@@ -67,11 +67,7 @@ func (cred WebAuthnCredential) TableName() string {
6767}
6868
6969// UpdateSignCount will update the database value of SignCount
70- func (cred * WebAuthnCredential ) UpdateSignCount () error {
71- return cred .updateSignCount (db .DefaultContext )
72- }
73-
74- func (cred * WebAuthnCredential ) updateSignCount (ctx context.Context ) error {
70+ func (cred * WebAuthnCredential ) UpdateSignCount (ctx context.Context ) error {
7571 _ , err := db .GetEngine (ctx ).ID (cred .ID ).Cols ("sign_count" ).Update (cred )
7672 return err
7773}
@@ -113,30 +109,18 @@ func (list WebAuthnCredentialList) ToCredentials() []webauthn.Credential {
113109}
114110
115111// GetWebAuthnCredentialsByUID returns all WebAuthn credentials of the given user
116- func GetWebAuthnCredentialsByUID (uid int64 ) (WebAuthnCredentialList , error ) {
117- return getWebAuthnCredentialsByUID (db .DefaultContext , uid )
118- }
119-
120- func getWebAuthnCredentialsByUID (ctx context.Context , uid int64 ) (WebAuthnCredentialList , error ) {
112+ func GetWebAuthnCredentialsByUID (ctx context.Context , uid int64 ) (WebAuthnCredentialList , error ) {
121113 creds := make (WebAuthnCredentialList , 0 )
122114 return creds , db .GetEngine (ctx ).Where ("user_id = ?" , uid ).Find (& creds )
123115}
124116
125117// ExistsWebAuthnCredentialsForUID returns if the given user has credentials
126- func ExistsWebAuthnCredentialsForUID (uid int64 ) (bool , error ) {
127- return existsWebAuthnCredentialsByUID (db .DefaultContext , uid )
128- }
129-
130- func existsWebAuthnCredentialsByUID (ctx context.Context , uid int64 ) (bool , error ) {
118+ func ExistsWebAuthnCredentialsForUID (ctx context.Context , uid int64 ) (bool , error ) {
131119 return db .GetEngine (ctx ).Where ("user_id = ?" , uid ).Exist (& WebAuthnCredential {})
132120}
133121
134122// GetWebAuthnCredentialByName returns WebAuthn credential by id
135- func GetWebAuthnCredentialByName (uid int64 , name string ) (* WebAuthnCredential , error ) {
136- return getWebAuthnCredentialByName (db .DefaultContext , uid , name )
137- }
138-
139- func getWebAuthnCredentialByName (ctx context.Context , uid int64 , name string ) (* WebAuthnCredential , error ) {
123+ func GetWebAuthnCredentialByName (ctx context.Context , uid int64 , name string ) (* WebAuthnCredential , error ) {
140124 cred := new (WebAuthnCredential )
141125 if found , err := db .GetEngine (ctx ).Where ("user_id = ? AND lower_name = ?" , uid , strings .ToLower (name )).Get (cred ); err != nil {
142126 return nil , err
@@ -147,11 +131,7 @@ func getWebAuthnCredentialByName(ctx context.Context, uid int64, name string) (*
147131}
148132
149133// GetWebAuthnCredentialByID returns WebAuthn credential by id
150- func GetWebAuthnCredentialByID (id int64 ) (* WebAuthnCredential , error ) {
151- return getWebAuthnCredentialByID (db .DefaultContext , id )
152- }
153-
154- func getWebAuthnCredentialByID (ctx context.Context , id int64 ) (* WebAuthnCredential , error ) {
134+ func GetWebAuthnCredentialByID (ctx context.Context , id int64 ) (* WebAuthnCredential , error ) {
155135 cred := new (WebAuthnCredential )
156136 if found , err := db .GetEngine (ctx ).ID (id ).Get (cred ); err != nil {
157137 return nil , err
@@ -162,16 +142,12 @@ func getWebAuthnCredentialByID(ctx context.Context, id int64) (*WebAuthnCredenti
162142}
163143
164144// HasWebAuthnRegistrationsByUID returns whether a given user has WebAuthn registrations
165- func HasWebAuthnRegistrationsByUID (uid int64 ) (bool , error ) {
166- return db .GetEngine (db . DefaultContext ).Where ("user_id = ?" , uid ).Exist (& WebAuthnCredential {})
145+ func HasWebAuthnRegistrationsByUID (ctx context. Context , uid int64 ) (bool , error ) {
146+ return db .GetEngine (ctx ).Where ("user_id = ?" , uid ).Exist (& WebAuthnCredential {})
167147}
168148
169149// GetWebAuthnCredentialByCredID returns WebAuthn credential by credential ID
170- func GetWebAuthnCredentialByCredID (userID int64 , credID []byte ) (* WebAuthnCredential , error ) {
171- return getWebAuthnCredentialByCredID (db .DefaultContext , userID , credID )
172- }
173-
174- func getWebAuthnCredentialByCredID (ctx context.Context , userID int64 , credID []byte ) (* WebAuthnCredential , error ) {
150+ func GetWebAuthnCredentialByCredID (ctx context.Context , userID int64 , credID []byte ) (* WebAuthnCredential , error ) {
175151 cred := new (WebAuthnCredential )
176152 if found , err := db .GetEngine (ctx ).Where ("user_id = ? AND credential_id = ?" , userID , credID ).Get (cred ); err != nil {
177153 return nil , err
@@ -182,11 +158,7 @@ func getWebAuthnCredentialByCredID(ctx context.Context, userID int64, credID []b
182158}
183159
184160// CreateCredential will create a new WebAuthnCredential from the given Credential
185- func CreateCredential (userID int64 , name string , cred * webauthn.Credential ) (* WebAuthnCredential , error ) {
186- return createCredential (db .DefaultContext , userID , name , cred )
187- }
188-
189- func createCredential (ctx context.Context , userID int64 , name string , cred * webauthn.Credential ) (* WebAuthnCredential , error ) {
161+ func CreateCredential (ctx context.Context , userID int64 , name string , cred * webauthn.Credential ) (* WebAuthnCredential , error ) {
190162 c := & WebAuthnCredential {
191163 UserID : userID ,
192164 Name : name ,
@@ -205,18 +177,14 @@ func createCredential(ctx context.Context, userID int64, name string, cred *weba
205177}
206178
207179// DeleteCredential will delete WebAuthnCredential
208- func DeleteCredential (id , userID int64 ) (bool , error ) {
209- return deleteCredential (db .DefaultContext , id , userID )
210- }
211-
212- func deleteCredential (ctx context.Context , id , userID int64 ) (bool , error ) {
180+ func DeleteCredential (ctx context.Context , id , userID int64 ) (bool , error ) {
213181 had , err := db .GetEngine (ctx ).ID (id ).Where ("user_id = ?" , userID ).Delete (& WebAuthnCredential {})
214182 return had > 0 , err
215183}
216184
217185// WebAuthnCredentials implementns the webauthn.User interface
218- func WebAuthnCredentials (userID int64 ) ([]webauthn.Credential , error ) {
219- dbCreds , err := GetWebAuthnCredentialsByUID (userID )
186+ func WebAuthnCredentials (ctx context. Context , userID int64 ) ([]webauthn.Credential , error ) {
187+ dbCreds , err := GetWebAuthnCredentialsByUID (ctx , userID )
220188 if err != nil {
221189 return nil , err
222190 }
0 commit comments