mirror of
https://github.com/semaphoreui/semaphore.git
synced 2025-01-20 07:19:20 +01:00
feat(auth): api for adding totp
This commit is contained in:
parent
21263baf17
commit
a5ad050d3e
@ -276,7 +276,7 @@ type Store interface {
|
||||
UpdateUser(user UserWithPwd) error
|
||||
SetUserPassword(userID int, password string) error
|
||||
AddUserTotpVerification(userID int, secret string) (UserTotp, error)
|
||||
DeleteTotpVerification(userID int) error
|
||||
DeleteTotpVerification(userID int, totpID int) error
|
||||
|
||||
GetUser(userID int) (User, error)
|
||||
GetUserByLoginOrEmail(login string, email string) (User, error)
|
||||
@ -534,6 +534,12 @@ var TemplateVaultProps = ObjectProps{
|
||||
ReferringColumnSuffix: "template_id",
|
||||
}
|
||||
|
||||
var UserTotpProps = ObjectProps{
|
||||
TableName: "user__totp",
|
||||
Type: reflect.TypeOf(UserTotp{}),
|
||||
PrimaryColumnName: "id",
|
||||
}
|
||||
|
||||
func (p ObjectProps) GetReferringFieldsFrom(t reflect.Type) (fields []string, err error) {
|
||||
n := t.NumField()
|
||||
for i := 0; i < n; i++ {
|
||||
|
@ -216,3 +216,31 @@ func (d *BoltDb) GetAllAdmins() (users []db.User, err error) {
|
||||
}, &users)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *BoltDb) AddUserTotpVerification(userID int, secret string) (totp db.UserTotp, err error) {
|
||||
|
||||
current := make([]db.UserTotp, 0)
|
||||
err = d.getObjects(userID, db.UserTotpProps, db.RetrieveQueryParams{}, nil, current)
|
||||
|
||||
if len(current) > 0 {
|
||||
err = fmt.Errorf("already exists")
|
||||
return
|
||||
}
|
||||
|
||||
totp.UserID = userID
|
||||
totp.Secret = secret
|
||||
totp.Created = db.GetParsedTime(time.Now().UTC())
|
||||
|
||||
newTotp, err := d.createObject(userID, db.UserTotpProps, totp)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
totp = newTotp.(db.UserTotp)
|
||||
return
|
||||
}
|
||||
|
||||
func (d *BoltDb) DeleteTotpVerification(userID int, totpID int) error {
|
||||
return d.deleteObject(userID, db.UserTotpProps, intObjectID(totpID), nil)
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ func (d *SqlDb) AddUserTotpVerification(userID int, secret string) (totp db.User
|
||||
return
|
||||
}
|
||||
|
||||
func (d *SqlDb) DeleteTotpVerification(userID int) error {
|
||||
_, err := d.exec("delete from user__totp where user_id=?", userID)
|
||||
func (d *SqlDb) DeleteTotpVerification(userID int, totpID int) error {
|
||||
_, err := d.exec("delete from user__totp where user_id=? and id = ?", userID, totpID)
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user