aboutsummaryrefslogtreecommitdiff
path: root/internal/route/user
diff options
context:
space:
mode:
authorᴜɴᴋɴᴡᴏɴ <u@gogs.io>2020-04-14 09:41:54 +0800
committerGitHub <noreply@github.com>2020-04-14 09:41:54 +0800
commitcb439a126aa6a2728e423bcfd0d5e948337b8ddb (patch)
treef7d09181fe5b96ea444f7544091673b3c668b9fe /internal/route/user
parent659acd48b1a131476fd98a54604fa6416b1cef9d (diff)
db: add tests for two factors (#6099)
* Rename to TwoFactors.Create * Use GORM to execute queries * TwoFactor.GetByUserID * Add tests * Fix failing tests * Add MD5 tests * Add tests for RandomChars
Diffstat (limited to 'internal/route/user')
-rw-r--r--internal/route/user/auth.go2
-rw-r--r--internal/route/user/setting.go9
2 files changed, 6 insertions, 5 deletions
diff --git a/internal/route/user/auth.go b/internal/route/user/auth.go
index be23b78d..852c9679 100644
--- a/internal/route/user/auth.go
+++ b/internal/route/user/auth.go
@@ -209,7 +209,7 @@ func LoginTwoFactorPost(c *context.Context) {
return
}
- t, err := db.GetTwoFactorByUserID(userID)
+ t, err := db.TwoFactors.GetByUserID(userID)
if err != nil {
c.Error(err, "get two factor by user ID")
return
diff --git a/internal/route/user/setting.go b/internal/route/user/setting.go
index 7e49505d..15848ef5 100644
--- a/internal/route/user/setting.go
+++ b/internal/route/user/setting.go
@@ -20,6 +20,7 @@ import (
"gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/context"
+ "gogs.io/gogs/internal/cryptoutil"
"gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/db/errors"
"gogs.io/gogs/internal/email"
@@ -118,7 +119,7 @@ func SettingsPost(c *context.Context, f form.UpdateProfile) {
func UpdateAvatarSetting(c *context.Context, f form.Avatar, ctxUser *db.User) error {
ctxUser.UseCustomAvatar = f.Source == form.AVATAR_LOCAL
if len(f.Gravatar) > 0 {
- ctxUser.Avatar = tool.MD5(f.Gravatar)
+ ctxUser.Avatar = cryptoutil.MD5(f.Gravatar)
ctxUser.AvatarEmail = f.Gravatar
}
@@ -381,8 +382,8 @@ func SettingsSecurity(c *context.Context) {
c.Title("settings.security")
c.PageIs("SettingsSecurity")
- t, err := db.GetTwoFactorByUserID(c.UserID())
- if err != nil && !errors.IsTwoFactorNotFound(err) {
+ t, err := db.TwoFactors.GetByUserID(c.UserID())
+ if err != nil && !db.IsErrTwoFactorNotFound(err) {
c.Errorf(err, "get two factor by user ID")
return
}
@@ -449,7 +450,7 @@ func SettingsTwoFactorEnablePost(c *context.Context) {
return
}
- if err := db.NewTwoFactor(c.UserID(), secret); err != nil {
+ if err := db.TwoFactors.Create(c.UserID(), conf.Security.SecretKey, secret); err != nil {
c.Flash.Error(c.Tr("settings.two_factor_enable_error", err))
c.RedirectSubpath("/user/settings/security/two_factor_enable")
return