Add totp check when logging in
continuous-integration/drone/pr Build is failing
Details
continuous-integration/drone/pr Build is failing
Details
This commit is contained in:
parent
97d78b032e
commit
42beec531e
|
@ -53,6 +53,21 @@ func Login(c echo.Context) error {
|
|||
return handler.HandleHTTPError(err, c)
|
||||
}
|
||||
|
||||
totpEnabled, err := user2.TOTPEnabledForUser(user)
|
||||
if err != nil {
|
||||
return handler.HandleHTTPError(err, c)
|
||||
}
|
||||
|
||||
if totpEnabled {
|
||||
_, err = user2.ValidateTOTPPasscode(&user2.TOTPPasscode{
|
||||
User: user,
|
||||
Passcode: u.TOTPPasscode,
|
||||
})
|
||||
if err != nil {
|
||||
return handler.HandleHTTPError(err, c)
|
||||
}
|
||||
}
|
||||
|
||||
// Create token
|
||||
t, err := NewUserJWTAuthtoken(user)
|
||||
if err != nil {
|
||||
|
|
|
@ -44,6 +44,11 @@ type TOTPPasscode struct {
|
|||
Passcode string `json:"passcode"`
|
||||
}
|
||||
|
||||
// TOTPEnabledForUser checks if totp is enabled for a user - not if it is activated, use getTOTPForUser to check that.
|
||||
func TOTPEnabledForUser(user *User) (bool, error) {
|
||||
return x.Where("user_id = ?", user.ID).Exist(&TOTP{})
|
||||
}
|
||||
|
||||
func getTOTPForUser(user *User) (t *TOTP, err error) {
|
||||
t = &TOTP{}
|
||||
exists, err := x.Where("user_id = ?", user.ID).Get(t)
|
||||
|
|
|
@ -37,6 +37,8 @@ type Login struct {
|
|||
Username string `json:"username"`
|
||||
// The password for the user.
|
||||
Password string `json:"password"`
|
||||
// The totp passcode of a user. Only needs to be provided when enabled.
|
||||
TOTPPasscode string `json:"totp_passcode"`
|
||||
}
|
||||
|
||||
// User holds information about an user
|
||||
|
|
Loading…
Reference in New Issue