add comments
This commit is contained in:
@@ -15,12 +15,14 @@ import (
|
||||
"github.com/mayswind/lab/pkg/services"
|
||||
)
|
||||
|
||||
// TwoFactorAuthorizationsApi represents 2fa api
|
||||
type TwoFactorAuthorizationsApi struct {
|
||||
twoFactorAuthorizations *services.TwoFactorAuthorizationService
|
||||
users *services.UserService
|
||||
tokens *services.TokenService
|
||||
}
|
||||
|
||||
// Initialize a 2fa api singleton instance
|
||||
var (
|
||||
TwoFactorAuthorizations = &TwoFactorAuthorizationsApi{
|
||||
twoFactorAuthorizations: services.TwoFactorAuthorizations,
|
||||
@@ -29,6 +31,7 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
// TwoFactorStatusHandler returns 2fa status of current user
|
||||
func (a *TwoFactorAuthorizationsApi) TwoFactorStatusHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
uid := c.GetCurrentUid()
|
||||
twoFactorSetting, err := a.twoFactorAuthorizations.GetUserTwoFactorSettingByUid(uid)
|
||||
@@ -54,6 +57,7 @@ func (a *TwoFactorAuthorizationsApi) TwoFactorStatusHandler(c *core.Context) (in
|
||||
return statusResp, nil
|
||||
}
|
||||
|
||||
// TwoFactorEnableRequestHandler returns a new 2fa secret and qr code for current user to set 2fa and verify passcode next
|
||||
func (a *TwoFactorAuthorizationsApi) TwoFactorEnableRequestHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
uid := c.GetCurrentUid()
|
||||
enabled, err := a.twoFactorAuthorizations.ExistsTwoFactorSetting(uid)
|
||||
@@ -105,6 +109,7 @@ func (a *TwoFactorAuthorizationsApi) TwoFactorEnableRequestHandler(c *core.Conte
|
||||
return enableResp, nil
|
||||
}
|
||||
|
||||
// TwoFactorEnableConfirmHandler enables 2fa for current user
|
||||
func (a *TwoFactorAuthorizationsApi) TwoFactorEnableConfirmHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var confirmReq models.TwoFactorEnableConfirmRequest
|
||||
err := c.ShouldBindJSON(&confirmReq)
|
||||
@@ -202,6 +207,7 @@ func (a *TwoFactorAuthorizationsApi) TwoFactorEnableConfirmHandler(c *core.Conte
|
||||
return confirmResp, nil
|
||||
}
|
||||
|
||||
// TwoFactorDisableHandler disables 2fa for current user
|
||||
func (a *TwoFactorAuthorizationsApi) TwoFactorDisableHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var disableReq models.TwoFactorDisableRequest
|
||||
err := c.ShouldBindJSON(&disableReq)
|
||||
@@ -256,6 +262,7 @@ func (a *TwoFactorAuthorizationsApi) TwoFactorDisableHandler(c *core.Context) (i
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// TwoFactorRecoveryCodeRegenerateHandler returns new 2fa recovery codes and revokes old recovery codes for current user
|
||||
func (a *TwoFactorAuthorizationsApi) TwoFactorRecoveryCodeRegenerateHandler(c *core.Context) (interface{}, *errs.Error) {
|
||||
var regenerateReq models.TwoFactorRegenerateRecoveryCodeRequest
|
||||
err := c.ShouldBindJSON(®enerateReq)
|
||||
|
||||
Reference in New Issue
Block a user