22// Use of this source code is governed by a MIT-style
33// license that can be found in the LICENSE file.
44
5- package models
5+ package login
66
77import (
8+ "fmt"
9+
810 "code.gitea.io/gitea/models/db"
911 "code.gitea.io/gitea/modules/log"
1012 "code.gitea.io/gitea/modules/timeutil"
1113
1214 "github.com/tstranex/u2f"
1315)
1416
17+ // ____ ________________________________ .__ __ __ .__
18+ // | | \_____ \_ _____/\______ \ ____ ____ |__| _______/ |_____________ _/ |_|__| ____ ____
19+ // | | // ____/| __) | _// __ \ / ___\| |/ ___/\ __\_ __ \__ \\ __\ |/ _ \ / \
20+ // | | // \| \ | | \ ___// /_/ > |\___ \ | | | | \// __ \| | | ( <_> ) | \
21+ // |______/ \_______ \___ / |____|_ /\___ >___ /|__/____ > |__| |__| (____ /__| |__|\____/|___| /
22+ // \/ \/ \/ \/_____/ \/ \/ \/
23+
24+ // ErrU2FRegistrationNotExist represents a "ErrU2FRegistrationNotExist" kind of error.
25+ type ErrU2FRegistrationNotExist struct {
26+ ID int64
27+ }
28+
29+ func (err ErrU2FRegistrationNotExist ) Error () string {
30+ return fmt .Sprintf ("U2F registration does not exist [id: %d]" , err .ID )
31+ }
32+
33+ // IsErrU2FRegistrationNotExist checks if an error is a ErrU2FRegistrationNotExist.
34+ func IsErrU2FRegistrationNotExist (err error ) bool {
35+ _ , ok := err .(ErrU2FRegistrationNotExist )
36+ return ok
37+ }
38+
1539// U2FRegistration represents the registration data and counter of a security key
1640type U2FRegistration struct {
1741 ID int64 `xorm:"pk autoincr"`
@@ -91,13 +115,13 @@ func GetU2FRegistrationsByUID(uid int64) (U2FRegistrationList, error) {
91115 return getU2FRegistrationsByUID (db .GetEngine (db .DefaultContext ), uid )
92116}
93117
94- func createRegistration (e db.Engine , user * User , name string , reg * u2f.Registration ) (* U2FRegistration , error ) {
118+ func createRegistration (e db.Engine , userID int64 , name string , reg * u2f.Registration ) (* U2FRegistration , error ) {
95119 raw , err := reg .MarshalBinary ()
96120 if err != nil {
97121 return nil , err
98122 }
99123 r := & U2FRegistration {
100- UserID : user . ID ,
124+ UserID : userID ,
101125 Name : name ,
102126 Counter : 0 ,
103127 Raw : raw ,
@@ -110,8 +134,8 @@ func createRegistration(e db.Engine, user *User, name string, reg *u2f.Registrat
110134}
111135
112136// CreateRegistration will create a new U2FRegistration from the given Registration
113- func CreateRegistration (user * User , name string , reg * u2f.Registration ) (* U2FRegistration , error ) {
114- return createRegistration (db .GetEngine (db .DefaultContext ), user , name , reg )
137+ func CreateRegistration (userID int64 , name string , reg * u2f.Registration ) (* U2FRegistration , error ) {
138+ return createRegistration (db .GetEngine (db .DefaultContext ), userID , name , reg )
115139}
116140
117141// DeleteRegistration will delete U2FRegistration
0 commit comments