aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/user
diff options
context:
space:
mode:
Diffstat (limited to 'routers/web/user')
-rw-r--r--routers/web/user/auth.go124
-rw-r--r--routers/web/user/auth_openid.go17
-rw-r--r--routers/web/user/avatar.go8
-rw-r--r--routers/web/user/home.go17
-rw-r--r--routers/web/user/oauth.go9
-rw-r--r--routers/web/user/oauth_test.go4
-rw-r--r--routers/web/user/profile.go36
-rw-r--r--routers/web/user/setting/account.go12
-rw-r--r--routers/web/user/setting/adopt.go3
-rw-r--r--routers/web/user/setting/profile.go26
10 files changed, 129 insertions, 127 deletions
diff --git a/routers/web/user/auth.go b/routers/web/user/auth.go
index c5164c4956..02f5afd8ba 100644
--- a/routers/web/user/auth.go
+++ b/routers/web/user/auth.go
@@ -76,9 +76,9 @@ func AutoSignIn(ctx *context.Context) (bool, error) {
}
}()
- u, err := models.GetUserByName(uname)
+ u, err := user_model.GetUserByName(uname)
if err != nil {
- if !models.IsErrUserNotExist(err) {
+ if !user_model.IsErrUserNotExist(err) {
return false, fmt.Errorf("GetUserByName: %v", err)
}
return false, nil
@@ -180,17 +180,17 @@ func SignInPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.SignInForm)
u, source, err := auth.UserSignIn(form.UserName, form.Password)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplSignIn, &form)
log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
} else if user_model.IsErrEmailAlreadyUsed(err) {
ctx.RenderWithErr(ctx.Tr("form.email_been_used"), tplSignIn, &form)
log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
- } else if models.IsErrUserProhibitLogin(err) {
+ } else if user_model.IsErrUserProhibitLogin(err) {
log.Info("Failed authentication attempt for %s from %s: %v", form.UserName, ctx.RemoteAddr(), err)
ctx.Data["Title"] = ctx.Tr("auth.prohibit_login")
ctx.HTML(http.StatusOK, "user/auth/prohibit_login")
- } else if models.IsErrUserInactive(err) {
+ } else if user_model.IsErrUserInactive(err) {
if setting.Service.RegisterEmailConfirm {
ctx.Data["Title"] = ctx.Tr("auth.active_your_account")
ctx.HTML(http.StatusOK, TplActivate)
@@ -314,7 +314,7 @@ func TwoFactorPost(ctx *context.Context) {
if ok && twofa.LastUsedPasscode != form.Passcode {
remember := ctx.Session.Get("twofaRemember").(bool)
- u, err := models.GetUserByID(id)
+ u, err := user_model.GetUserByID(id)
if err != nil {
ctx.ServerError("UserSignIn", err)
return
@@ -398,7 +398,7 @@ func TwoFactorScratchPost(ctx *context.Context) {
}
remember := ctx.Session.Get("twofaRemember").(bool)
- u, err := models.GetUserByID(id)
+ u, err := user_model.GetUserByID(id)
if err != nil {
ctx.ServerError("UserSignIn", err)
return
@@ -495,7 +495,7 @@ func U2FSign(ctx *context.Context) {
newCounter, authErr := r.Authenticate(*signResp, *challenge, reg.Counter)
if authErr == nil {
reg.Counter = newCounter
- user, err := models.GetUserByID(id)
+ user, err := user_model.GetUserByID(id)
if err != nil {
ctx.ServerError("UserSignIn", err)
return
@@ -531,11 +531,11 @@ func U2FSign(ctx *context.Context) {
}
// This handles the final part of the sign-in process of the user.
-func handleSignIn(ctx *context.Context, u *models.User, remember bool) {
+func handleSignIn(ctx *context.Context, u *user_model.User, remember bool) {
handleSignInFull(ctx, u, remember, true)
}
-func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyRedirect bool) string {
+func handleSignInFull(ctx *context.Context, u *user_model.User, remember bool, obeyRedirect bool) string {
if remember {
days := 86400 * setting.LogInRememberDays
ctx.SetCookie(setting.CookieUserName, u.Name, days)
@@ -565,7 +565,7 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
// If the user does not have a locale set, we save the current one.
if len(u.Language) == 0 {
u.Language = ctx.Locale.Language()
- if err := models.UpdateUserCols(db.DefaultContext, u, "language"); err != nil {
+ if err := user_model.UpdateUserCols(db.DefaultContext, u, "language"); err != nil {
log.Error(fmt.Sprintf("Error updating user language [user: %d, locale: %s]", u.ID, u.Language))
return setting.AppSubURL + "/"
}
@@ -582,7 +582,7 @@ func handleSignInFull(ctx *context.Context, u *models.User, remember bool, obeyR
// Register last login
u.SetLastLogin()
- if err := models.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil {
+ if err := user_model.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil {
ctx.ServerError("UpdateUserCols", err)
return setting.AppSubURL + "/"
}
@@ -680,7 +680,7 @@ func SignInOAuthCallback(ctx *context.Context) {
ctx.ServerError("CreateUser", err)
return
}
- u = &models.User{
+ u = &user_model.User{
Name: getUserName(&gothUser),
FullName: gothUser.Name,
Email: gothUser.Email,
@@ -725,7 +725,7 @@ func showLinkingLogin(ctx *context.Context, gothUser goth.User) {
ctx.Redirect(setting.AppSubURL + "/user/link_account")
}
-func updateAvatarIfNeed(url string, u *models.User) {
+func updateAvatarIfNeed(url string, u *user_model.User) {
if setting.OAuth2Client.UpdateAvatar && len(url) > 0 {
resp, err := http.Get(url)
if err == nil {
@@ -743,7 +743,7 @@ func updateAvatarIfNeed(url string, u *models.User) {
}
}
-func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *models.User, gothUser goth.User) {
+func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *user_model.User, gothUser goth.User) {
updateAvatarIfNeed(gothUser.AvatarURL, u)
needs2FA := false
@@ -774,7 +774,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *models.Us
// Register last login
u.SetLastLogin()
- if err := models.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil {
+ if err := user_model.UpdateUserCols(db.DefaultContext, u, "last_login_unix"); err != nil {
ctx.ServerError("UpdateUserCols", err)
return
}
@@ -817,7 +817,7 @@ func handleOAuth2SignIn(ctx *context.Context, source *login.Source, u *models.Us
// OAuth2UserLoginCallback attempts to handle the callback from the OAuth2 provider and if successful
// login the user
-func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, response http.ResponseWriter) (*models.User, goth.User, error) {
+func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, response http.ResponseWriter) (*user_model.User, goth.User, error) {
gothUser, err := loginSource.Cfg.(*oauth2.Source).Callback(request, response)
if err != nil {
if err.Error() == "securecookie: the value is too long" || strings.Contains(err.Error(), "Data too long") {
@@ -827,13 +827,13 @@ func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, r
return nil, goth.User{}, err
}
- user := &models.User{
+ user := &user_model.User{
LoginName: gothUser.UserID,
LoginType: login.OAuth2,
LoginSource: loginSource.ID,
}
- hasUser, err := models.GetUser(user)
+ hasUser, err := user_model.GetUser(user)
if err != nil {
return nil, goth.User{}, err
}
@@ -852,7 +852,7 @@ func oAuth2UserLoginCallback(loginSource *login.Source, request *http.Request, r
return nil, goth.User{}, err
}
if hasUser {
- user, err = models.GetUserByID(externalLoginUser.UserID)
+ user, err = user_model.GetUserByID(externalLoginUser.UserID)
return user, gothUser, err
}
@@ -893,8 +893,8 @@ func LinkAccount(ctx *context.Context) {
ctx.Data["email"] = email
if len(email) != 0 {
- u, err := models.GetUserByEmail(email)
- if err != nil && !models.IsErrUserNotExist(err) {
+ u, err := user_model.GetUserByEmail(email)
+ if err != nil && !user_model.IsErrUserNotExist(err) {
ctx.ServerError("UserSignIn", err)
return
}
@@ -902,8 +902,8 @@ func LinkAccount(ctx *context.Context) {
ctx.Data["user_exists"] = true
}
} else if len(uname) != 0 {
- u, err := models.GetUserByName(uname)
- if err != nil && !models.IsErrUserNotExist(err) {
+ u, err := user_model.GetUserByName(uname)
+ if err != nil && !user_model.IsErrUserNotExist(err) {
ctx.ServerError("UserSignIn", err)
return
}
@@ -948,7 +948,7 @@ func LinkAccountPostSignIn(ctx *context.Context) {
u, _, err := auth.UserSignIn(signInForm.UserName, signInForm.Password)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Data["user_exists"] = true
ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplLinkAccount, &signInForm)
} else {
@@ -960,7 +960,7 @@ func LinkAccountPostSignIn(ctx *context.Context) {
linkAccount(ctx, u, gothUser.(goth.User), signInForm.Remember)
}
-func linkAccount(ctx *context.Context, u *models.User, gothUser goth.User, remember bool) {
+func linkAccount(ctx *context.Context, u *user_model.User, gothUser goth.User, remember bool) {
updateAvatarIfNeed(gothUser.AvatarURL, u)
// If this user is enrolled in 2FA, we can't sign the user in just yet.
@@ -1081,7 +1081,7 @@ func LinkAccountPostRegister(ctx *context.Context) {
}
if setting.Service.AllowOnlyExternalRegistration || !setting.Service.RequireExternalRegistrationPassword {
- // In models.User an empty password is classed as not set, so we set form.Password to empty.
+ // In user_model.User an empty password is classed as not set, so we set form.Password to empty.
// Eventually the database should be changed to indicate "Second Factor"-enabled accounts
// (accounts that do not introduce the security vulnerabilities of a password).
// If a user decides to circumvent second-factor security, and purposefully create a password,
@@ -1105,7 +1105,7 @@ func LinkAccountPostRegister(ctx *context.Context) {
ctx.ServerError("CreateUser", err)
}
- u := &models.User{
+ u := &user_model.User{
Name: form.UserName,
Email: form.Email,
Passwd: form.Password,
@@ -1249,7 +1249,7 @@ func SignUpPost(ctx *context.Context) {
return
}
- u := &models.User{
+ u := &user_model.User{
Name: form.UserName,
Email: form.Email,
Passwd: form.Password,
@@ -1268,7 +1268,7 @@ func SignUpPost(ctx *context.Context) {
// createAndHandleCreatedUser calls createUserInContext and
// then handleUserCreated.
-func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form interface{}, u *models.User, gothUser *goth.User, allowLink bool) bool {
+func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form interface{}, u *user_model.User, gothUser *goth.User, allowLink bool) bool {
if !createUserInContext(ctx, tpl, form, u, gothUser, allowLink) {
return false
}
@@ -1277,16 +1277,16 @@ func createAndHandleCreatedUser(ctx *context.Context, tpl base.TplName, form int
// createUserInContext creates a user and handles errors within a given context.
// Optionally a template can be specified.
-func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{}, u *models.User, gothUser *goth.User, allowLink bool) (ok bool) {
- if err := models.CreateUser(u); err != nil {
- if allowLink && (models.IsErrUserAlreadyExist(err) || user_model.IsErrEmailAlreadyUsed(err)) {
+func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{}, u *user_model.User, gothUser *goth.User, allowLink bool) (ok bool) {
+ if err := user_model.CreateUser(u); err != nil {
+ if allowLink && (user_model.IsErrUserAlreadyExist(err) || user_model.IsErrEmailAlreadyUsed(err)) {
if setting.OAuth2Client.AccountLinking == setting.OAuth2AccountLinkingAuto {
- var user *models.User
- user = &models.User{Name: u.Name}
- hasUser, err := models.GetUser(user)
+ var user *user_model.User
+ user = &user_model.User{Name: u.Name}
+ hasUser, err := user_model.GetUser(user)
if !hasUser || err != nil {
- user = &models.User{Email: u.Email}
- hasUser, err = models.GetUser(user)
+ user = &user_model.User{Email: u.Email}
+ hasUser, err = user_model.GetUser(user)
if !hasUser || err != nil {
ctx.ServerError("UserLinkAccount", err)
return
@@ -1310,7 +1310,7 @@ func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{
// handle error with template
switch {
- case models.IsErrUserAlreadyExist(err):
+ case user_model.IsErrUserAlreadyExist(err):
ctx.Data["Err_UserName"] = true
ctx.RenderWithErr(ctx.Tr("form.username_been_taken"), tpl, form)
case user_model.IsErrEmailAlreadyUsed(err):
@@ -1319,15 +1319,15 @@ func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{
case user_model.IsErrEmailInvalid(err):
ctx.Data["Err_Email"] = true
ctx.RenderWithErr(ctx.Tr("form.email_invalid"), tpl, form)
- case models.IsErrNameReserved(err):
+ case db.IsErrNameReserved(err):
ctx.Data["Err_UserName"] = true
- ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(models.ErrNameReserved).Name), tpl, form)
- case models.IsErrNamePatternNotAllowed(err):
+ ctx.RenderWithErr(ctx.Tr("user.form.name_reserved", err.(db.ErrNameReserved).Name), tpl, form)
+ case db.IsErrNamePatternNotAllowed(err):
ctx.Data["Err_UserName"] = true
- ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(models.ErrNamePatternNotAllowed).Pattern), tpl, form)
- case models.IsErrNameCharsNotAllowed(err):
+ ctx.RenderWithErr(ctx.Tr("user.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tpl, form)
+ case db.IsErrNameCharsNotAllowed(err):
ctx.Data["Err_UserName"] = true
- ctx.RenderWithErr(ctx.Tr("user.form.name_chars_not_allowed", err.(models.ErrNameCharsNotAllowed).Name), tpl, form)
+ ctx.RenderWithErr(ctx.Tr("user.form.name_chars_not_allowed", err.(db.ErrNameCharsNotAllowed).Name), tpl, form)
default:
ctx.ServerError("CreateUser", err)
}
@@ -1340,13 +1340,13 @@ func createUserInContext(ctx *context.Context, tpl base.TplName, form interface{
// handleUserCreated does additional steps after a new user is created.
// It auto-sets admin for the only user, updates the optional external user and
// sends a confirmation email if required.
-func handleUserCreated(ctx *context.Context, u *models.User, gothUser *goth.User) (ok bool) {
+func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth.User) (ok bool) {
// Auto-set admin for the only user.
- if models.CountUsers() == 1 {
+ if user_model.CountUsers() == 1 {
u.IsAdmin = true
u.IsActive = true
u.SetLastLogin()
- if err := models.UpdateUserCols(db.DefaultContext, u, "is_admin", "is_active", "last_login_unix"); err != nil {
+ if err := user_model.UpdateUserCols(db.DefaultContext, u, "is_admin", "is_active", "last_login_unix"); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
@@ -1406,7 +1406,7 @@ func Activate(ctx *context.Context) {
return
}
- user := models.VerifyUserActiveCode(code)
+ user := user_model.VerifyUserActiveCode(code)
// if code is wrong
if user == nil {
ctx.Data["IsActivateFailed"] = true
@@ -1433,7 +1433,7 @@ func ActivatePost(ctx *context.Context) {
return
}
- user := models.VerifyUserActiveCode(code)
+ user := user_model.VerifyUserActiveCode(code)
// if code is wrong
if user == nil {
ctx.Data["IsActivateFailed"] = true
@@ -1460,15 +1460,15 @@ func ActivatePost(ctx *context.Context) {
handleAccountActivation(ctx, user)
}
-func handleAccountActivation(ctx *context.Context, user *models.User) {
+func handleAccountActivation(ctx *context.Context, user *user_model.User) {
user.IsActive = true
var err error
- if user.Rands, err = models.GetUserSalt(); err != nil {
+ if user.Rands, err = user_model.GetUserSalt(); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
- if err := models.UpdateUserCols(db.DefaultContext, user, "is_active", "rands"); err != nil {
- if models.IsErrUserNotExist(err) {
+ if err := user_model.UpdateUserCols(db.DefaultContext, user, "is_active", "rands"); err != nil {
+ if user_model.IsErrUserNotExist(err) {
ctx.NotFound("UpdateUserCols", err)
} else {
ctx.ServerError("UpdateUser", err)
@@ -1512,7 +1512,7 @@ func ActivateEmail(ctx *context.Context) {
log.Trace("Email activated: %s", email.Email)
ctx.Flash.Success(ctx.Tr("settings.add_email_success"))
- if u, err := models.GetUserByID(email.UID); err != nil {
+ if u, err := user_model.GetUserByID(email.UID); err != nil {
log.Warn("GetUserByID: %d", email.UID)
} else {
// Allow user to validate more emails
@@ -1556,9 +1556,9 @@ func ForgotPasswdPost(ctx *context.Context) {
email := ctx.FormString("email")
ctx.Data["Email"] = email
- u, err := models.GetUserByEmail(email)
+ u, err := user_model.GetUserByEmail(email)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language())
ctx.Data["IsResetSent"] = true
ctx.HTML(http.StatusOK, tplForgotPassword)
@@ -1592,7 +1592,7 @@ func ForgotPasswdPost(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplForgotPassword)
}
-func commonResetPassword(ctx *context.Context) (*models.User, *login.TwoFactor) {
+func commonResetPassword(ctx *context.Context) (*user_model.User, *login.TwoFactor) {
code := ctx.FormString("code")
ctx.Data["Title"] = ctx.Tr("auth.reset_password")
@@ -1608,7 +1608,7 @@ func commonResetPassword(ctx *context.Context) (*models.User, *login.TwoFactor)
}
// Fail early, don't frustrate the user
- u := models.VerifyUserActiveCode(code)
+ u := user_model.VerifyUserActiveCode(code)
if u == nil {
ctx.Flash.Error(ctx.Tr("auth.invalid_code"))
return nil, nil
@@ -1718,7 +1718,7 @@ func ResetPasswdPost(ctx *context.Context) {
}
}
var err error
- if u.Rands, err = models.GetUserSalt(); err != nil {
+ if u.Rands, err = user_model.GetUserSalt(); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
@@ -1727,7 +1727,7 @@ func ResetPasswdPost(ctx *context.Context) {
return
}
u.MustChangePassword = false
- if err := models.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "rands", "salt"); err != nil {
+ if err := user_model.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "rands", "salt"); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
@@ -1803,7 +1803,7 @@ func MustChangePasswordPost(ctx *context.Context) {
u.MustChangePassword = false
- if err := models.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "salt"); err != nil {
+ if err := user_model.UpdateUserCols(db.DefaultContext, u, "must_change_password", "passwd", "passwd_hash_algo", "salt"); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
diff --git a/routers/web/user/auth_openid.go b/routers/web/user/auth_openid.go
index 4724a7b431..68e166d12c 100644
--- a/routers/web/user/auth_openid.go
+++ b/routers/web/user/auth_openid.go
@@ -9,7 +9,6 @@ import (
"net/http"
"net/url"
- "code.gitea.io/gitea/models"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/auth/openid"
"code.gitea.io/gitea/modules/base"
@@ -163,9 +162,9 @@ func signInOpenIDVerify(ctx *context.Context) {
/* Now we should seek for the user and log him in, or prompt
* to register if not found */
- u, err := models.GetUserByOpenID(id)
+ u, err := user_model.GetUserByOpenID(id)
if err != nil {
- if !models.IsErrUserNotExist(err) {
+ if !user_model.IsErrUserNotExist(err) {
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{
Openid: id,
})
@@ -203,9 +202,9 @@ func signInOpenIDVerify(ctx *context.Context) {
log.Trace("User has email=" + email + " and nickname=" + nickname)
if email != "" {
- u, err = models.GetUserByEmail(email)
+ u, err = user_model.GetUserByEmail(email)
if err != nil {
- if !models.IsErrUserNotExist(err) {
+ if !user_model.IsErrUserNotExist(err) {
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{
Openid: id,
})
@@ -219,9 +218,9 @@ func signInOpenIDVerify(ctx *context.Context) {
}
if u == nil && nickname != "" {
- u, _ = models.GetUserByName(nickname)
+ u, _ = user_model.GetUserByName(nickname)
if err != nil {
- if !models.IsErrUserNotExist(err) {
+ if !user_model.IsErrUserNotExist(err) {
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &forms.SignInOpenIDForm{
Openid: id,
})
@@ -294,7 +293,7 @@ func ConnectOpenIDPost(ctx *context.Context) {
u, _, err := auth.UserSignIn(form.UserName, form.Password)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.RenderWithErr(ctx.Tr("form.username_password_incorrect"), tplConnectOID, &form)
} else {
ctx.ServerError("ConnectOpenIDPost", err)
@@ -419,7 +418,7 @@ func RegisterOpenIDPost(ctx *context.Context) {
return
}
- u := &models.User{
+ u := &user_model.User{
Name: form.UserName,
Email: form.Email,
Passwd: password,
diff --git a/routers/web/user/avatar.go b/routers/web/user/avatar.go
index f39bcc36d3..c8bca9dc2c 100644
--- a/routers/web/user/avatar.go
+++ b/routers/web/user/avatar.go
@@ -8,8 +8,8 @@ import (
"strings"
"time"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/avatars"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/httpcache"
)
@@ -27,15 +27,15 @@ func AvatarByUserName(ctx *context.Context) {
userName := ctx.Params(":username")
size := int(ctx.ParamsInt64(":size"))
- var user *models.User
+ var user *user_model.User
if strings.ToLower(userName) != "ghost" {
var err error
- if user, err = models.GetUserByName(userName); err != nil {
+ if user, err = user_model.GetUserByName(userName); err != nil {
ctx.ServerError("Invalid user: "+userName, err)
return
}
} else {
- user = models.NewGhostUser()
+ user = user_model.NewGhostUser()
}
cacheableRedirect(ctx, user.AvatarLinkWithSize(size))
diff --git a/routers/web/user/home.go b/routers/web/user/home.go
index 9efbe755d9..ca2705a42f 100644
--- a/routers/web/user/home.go
+++ b/routers/web/user/home.go
@@ -17,6 +17,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/unit"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
@@ -43,7 +44,7 @@ const (
)
// getDashboardContextUser finds out which context user dashboard is being viewed as .
-func getDashboardContextUser(ctx *context.Context) *models.User {
+func getDashboardContextUser(ctx *context.Context) *user_model.User {
ctxUser := ctx.User
orgName := ctx.Params(":org")
if len(orgName) > 0 {
@@ -727,7 +728,7 @@ func getRepoIDs(reposQuery string) []int64 {
return repoIDs
}
-func getActiveUserRepoIDs(ctxUser *models.User, team *models.Team, unitType unit.Type) ([]int64, error) {
+func getActiveUserRepoIDs(ctxUser *user_model.User, team *models.Team, unitType unit.Type) ([]int64, error) {
var userRepoIDs []int64
var err error
@@ -737,7 +738,7 @@ func getActiveUserRepoIDs(ctxUser *models.User, team *models.Team, unitType unit
return nil, fmt.Errorf("orgRepoIds: %v", err)
}
} else {
- userRepoIDs, err = ctxUser.GetActiveAccessRepoIDs(unitType)
+ userRepoIDs, err = models.GetActiveAccessRepoIDs(ctxUser, unitType)
if err != nil {
return nil, fmt.Errorf("ctxUser.GetAccessRepoIDs: %v", err)
}
@@ -752,7 +753,7 @@ func getActiveUserRepoIDs(ctxUser *models.User, team *models.Team, unitType unit
// getActiveTeamOrOrgRepoIds gets RepoIDs for ctxUser as Organization.
// Should be called if and only if ctxUser.IsOrganization == true.
-func getActiveTeamOrOrgRepoIds(ctxUser *models.User, team *models.Team, unitType unit.Type) ([]int64, error) {
+func getActiveTeamOrOrgRepoIds(ctxUser *user_model.User, team *models.Team, unitType unit.Type) ([]int64, error) {
var orgRepoIDs []int64
var err error
var env models.AccessibleReposEnvironment
@@ -777,7 +778,7 @@ func getActiveTeamOrOrgRepoIds(ctxUser *models.User, team *models.Team, unitType
return orgRepoIDs, nil
}
-func issueIDsFromSearch(ctxUser *models.User, keyword string, opts *models.IssuesOptions) ([]int64, error) {
+func issueIDsFromSearch(ctxUser *user_model.User, keyword string, opts *models.IssuesOptions) ([]int64, error) {
if len(keyword) == 0 {
return []int64{}, nil
}
@@ -794,7 +795,7 @@ func issueIDsFromSearch(ctxUser *models.User, keyword string, opts *models.Issue
return issueIDsFromSearch, nil
}
-func repoIDMap(ctxUser *models.User, issueCountByRepo map[int64]int64, unitType unit.Type) (map[int64]*models.Repository, error) {
+func repoIDMap(ctxUser *user_model.User, issueCountByRepo map[int64]int64, unitType unit.Type) (map[int64]*models.Repository, error) {
repoByID := make(map[int64]*models.Repository, len(issueCountByRepo))
for id := range issueCountByRepo {
if id <= 0 {
@@ -880,9 +881,9 @@ func ShowGPGKeys(ctx *context.Context, uid int64) {
// Email2User show user page via email
func Email2User(ctx *context.Context) {
- u, err := models.GetUserByEmail(ctx.FormString("email"))
+ u, err := user_model.GetUserByEmail(ctx.FormString("email"))
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
ctx.NotFound("GetUserByEmail", err)
} else {
ctx.ServerError("GetUserByEmail", err)
diff --git a/routers/web/user/oauth.go b/routers/web/user/oauth.go
index 7b1854c521..d3baeaedc4 100644
--- a/routers/web/user/oauth.go
+++ b/routers/web/user/oauth.go
@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/login"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/base"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/json"
@@ -170,9 +171,9 @@ func newAccessTokenResponse(grant *login.OAuth2Grant, serverKey, clientKey oauth
ErrorDescription: "cannot find application",
}
}
- user, err := models.GetUserByID(grant.UserID)
+ user, err := user_model.GetUserByID(grant.UserID)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
return nil, &AccessTokenError{
ErrorCode: AccessTokenErrorCodeInvalidRequest,
ErrorDescription: "cannot find user",
@@ -274,7 +275,7 @@ func InfoOAuth(ctx *context.Context) {
// returns a list of "org" and "org:team" strings,
// that the given user is a part of.
-func getOAuthGroupsForUser(user *models.User) ([]string, error) {
+func getOAuthGroupsForUser(user *user_model.User) ([]string, error) {
orgs, err := models.GetUserOrgsList(user)
if err != nil {
return nil, fmt.Errorf("GetUserOrgList: %v", err)
@@ -359,7 +360,7 @@ func AuthorizeOAuth(ctx *context.Context) {
return
}
- user, err := models.GetUserByID(app.UID)
+ user, err := user_model.GetUserByID(app.UID)
if err != nil {
ctx.ServerError("GetUserByID", err)
return
diff --git a/routers/web/user/oauth_test.go b/routers/web/user/oauth_test.go
index dfdaa9a1ed..e26a42b2fc 100644
--- a/routers/web/user/oauth_test.go
+++ b/routers/web/user/oauth_test.go
@@ -7,9 +7,9 @@ package user
import (
"testing"
- "code.gitea.io/gitea/models"
"code.gitea.io/gitea/models/login"
"code.gitea.io/gitea/models/unittest"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/services/auth/source/oauth2"
"github.com/golang-jwt/jwt"
@@ -58,7 +58,7 @@ func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
assert.Empty(t, oidcToken.Email)
assert.False(t, oidcToken.EmailVerified)
- user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
+ user := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}).(*user_model.User)
grants, err = login.GetOAuth2GrantsByUserID(user.ID)
assert.NoError(t, err)
assert.Len(t, grants, 1)
diff --git a/routers/web/user/profile.go b/routers/web/user/profile.go
index 2594ba3013..32d2bdde83 100644
--- a/routers/web/user/profile.go
+++ b/routers/web/user/profile.go
@@ -24,10 +24,10 @@ import (
)
// GetUserByName get user by name
-func GetUserByName(ctx *context.Context, name string) *models.User {
- user, err := models.GetUserByName(name)
+func GetUserByName(ctx *context.Context, name string) *user_model.User {
+ user, err := user_model.GetUserByName(name)
if err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
if redirectUserID, err := user_model.LookupUserRedirect(name); err == nil {
context.RedirectToUser(ctx, name, redirectUserID)
} else {
@@ -42,7 +42,7 @@ func GetUserByName(ctx *context.Context, name string) *models.User {
}
// GetUserByParams returns user whose name is presented in URL paramenter.
-func GetUserByParams(ctx *context.Context) *models.User {
+func GetUserByParams(ctx *context.Context) *user_model.User {
return GetUserByName(ctx, ctx.Params(":username"))
}
@@ -199,41 +199,41 @@ func Profile(ctx *context.Context) {
repos []*models.Repository
count int64
total int
- orderBy models.SearchOrderBy
+ orderBy db.SearchOrderBy
)
ctx.Data["SortType"] = ctx.FormString("sort")
switch ctx.FormString("sort") {
case "newest":
- orderBy = models.SearchOrderByNewest
+ orderBy = db.SearchOrderByNewest
case "oldest":
- orderBy = models.SearchOrderByOldest
+ orderBy = db.SearchOrderByOldest
case "recentupdate":
- orderBy = models.SearchOrderByRecentUpdated
+ orderBy = db.SearchOrderByRecentUpdated
case "leastupdate":
- orderBy = models.SearchOrderByLeastUpdated
+ orderBy = db.SearchOrderByLeastUpdated
case "reversealphabetically":
- orderBy = models.SearchOrderByAlphabeticallyReverse
+ orderBy = db.SearchOrderByAlphabeticallyReverse
case "alphabetically":
- orderBy = models.SearchOrderByAlphabetically
+ orderBy = db.SearchOrderByAlphabetically
case "moststars":
- orderBy = models.SearchOrderByStarsReverse
+ orderBy = db.SearchOrderByStarsReverse
case "feweststars":
- orderBy = models.SearchOrderByStars
+ orderBy = db.SearchOrderByStars
case "mostforks":
- orderBy = models.SearchOrderByForksReverse
+ orderBy = db.SearchOrderByForksReverse
case "fewestforks":
- orderBy = models.SearchOrderByForks
+ orderBy = db.SearchOrderByForks
default:
ctx.Data["SortType"] = "recentupdate"
- orderBy = models.SearchOrderByRecentUpdated
+ orderBy = db.SearchOrderByRecentUpdated
}
keyword := ctx.FormTrim("q")
ctx.Data["Keyword"] = keyword
switch tab {
case "followers":
- items, err := models.GetUserFollowers(ctxUser, db.ListOptions{
+ items, err := user_model.GetUserFollowers(ctxUser, db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
Page: page,
})
@@ -245,7 +245,7 @@ func Profile(ctx *context.Context) {
total = ctxUser.NumFollowers
case "following":
- items, err := models.GetUserFollowing(ctxUser, db.ListOptions{
+ items, err := user_model.GetUserFollowing(ctxUser, db.ListOptions{
PageSize: setting.UI.User.RepoPagingNum,
Page: page,
})
diff --git a/routers/web/user/setting/account.go b/routers/web/user/setting/account.go
index 603786697a..3b51fdb777 100644
--- a/routers/web/user/setting/account.go
+++ b/routers/web/user/setting/account.go
@@ -75,7 +75,7 @@ func AccountPost(ctx *context.Context) {
ctx.ServerError("UpdateUser", err)
return
}
- if err := models.UpdateUserCols(db.DefaultContext, ctx.User, "salt", "passwd_hash_algo", "passwd"); err != nil {
+ if err := user_model.UpdateUserCols(db.DefaultContext, ctx.User, "salt", "passwd_hash_algo", "passwd"); err != nil {
ctx.ServerError("UpdateUser", err)
return
}
@@ -152,14 +152,14 @@ func EmailPost(ctx *context.Context) {
// Set Email Notification Preference
if ctx.FormString("_method") == "NOTIFICATION" {
preference := ctx.FormString("preference")
- if !(preference == models.EmailNotificationsEnabled ||
- preference == models.EmailNotificationsOnMention ||
- preference == models.EmailNotificationsDisabled) {
+ if !(preference == user_model.EmailNotificationsEnabled ||
+ preference == user_model.EmailNotificationsOnMention ||
+ preference == user_model.EmailNotificationsDisabled) {
log.Error("Email notifications preference change returned unrecognized option %s: %s", preference, ctx.User.Name)
ctx.ServerError("SetEmailPreference", errors.New("option unrecognized"))
return
}
- if err := models.SetEmailNotifications(ctx.User, preference); err != nil {
+ if err := user_model.SetEmailNotifications(ctx.User, preference); err != nil {
log.Error("Set Email Notifications failed: %v", err)
ctx.ServerError("SetEmailNotifications", err)
return
@@ -233,7 +233,7 @@ func DeleteAccount(ctx *context.Context) {
ctx.Data["PageIsSettingsAccount"] = true
if _, _, err := auth.UserSignIn(ctx.User.Name, ctx.FormString("password")); err != nil {
- if models.IsErrUserNotExist(err) {
+ if user_model.IsErrUserNotExist(err) {
loadAccountData(ctx)
ctx.RenderWithErr(ctx.Tr("form.enterred_invalid_password"), tplSettingsAccount, nil)
diff --git a/routers/web/user/setting/adopt.go b/routers/web/user/setting/adopt.go
index 948cc1e936..56ab6ec999 100644
--- a/routers/web/user/setting/adopt.go
+++ b/routers/web/user/setting/adopt.go
@@ -8,6 +8,7 @@ import (
"path/filepath"
"code.gitea.io/gitea/models"
+ user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
@@ -27,7 +28,7 @@ func AdoptOrDeleteRepository(ctx *context.Context) {
action := ctx.FormString("action")
ctxUser := ctx.User
- root := models.UserPath(ctxUser.LowerName)
+ root := user_model.UserPath(ctxUser.LowerName)
// check not a repo
has, err := models.IsRepositoryExist(ctxUser, dir)
diff --git a/routers/web/user/setting/profile.go b/routers/web/user/setting/profile.go
index 1e515f2fd3..0475398a9a 100644
--- a/routers/web/user/setting/profile.go
+++ b/routers/web/user/setting/profile.go
@@ -49,7 +49,7 @@ func Profile(ctx *context.Context) {
}
// HandleUsernameChange handle username changes from user settings and admin interface
-func HandleUsernameChange(ctx *context.Context, user *models.User, newName string) error {
+func HandleUsernameChange(ctx *context.Context, user *user_model.User, newName string) error {
// Non-local users are not allowed to change their username.
if !user.IsLocal() {
ctx.Flash.Error(ctx.Tr("form.username_change_not_local_user"))
@@ -58,17 +58,17 @@ func HandleUsernameChange(ctx *context.Context, user *models.User, newName strin
// Check if user name has been changed
if user.LowerName != strings.ToLower(newName) {
- if err := models.ChangeUserName(user, newName); err != nil {
+ if err := user_model.ChangeUserName(user, newName); err != nil {
switch {
- case models.IsErrUserAlreadyExist(err):
+ case user_model.IsErrUserAlreadyExist(err):
ctx.Flash.Error(ctx.Tr("form.username_been_taken"))
case user_model.IsErrEmailAlreadyUsed(err):
ctx.Flash.Error(ctx.Tr("form.email_been_used"))
- case models.IsErrNameReserved(err):
+ case db.IsErrNameReserved(err):
ctx.Flash.Error(ctx.Tr("user.form.name_reserved", newName))
- case models.IsErrNamePatternNotAllowed(err):
+ case db.IsErrNamePatternNotAllowed(err):
ctx.Flash.Error(ctx.Tr("user.form.name_pattern_not_allowed", newName))
- case models.IsErrNameCharsNotAllowed(err):
+ case db.IsErrNameCharsNotAllowed(err):
ctx.Flash.Error(ctx.Tr("user.form.name_chars_not_allowed", newName))
default:
ctx.ServerError("ChangeUserName", err)
@@ -121,7 +121,7 @@ func ProfilePost(ctx *context.Context) {
ctx.User.Description = form.Description
ctx.User.KeepActivityPrivate = form.KeepActivityPrivate
ctx.User.Visibility = form.Visibility
- if err := models.UpdateUserSetting(ctx.User); err != nil {
+ if err := user_model.UpdateUserSetting(ctx.User); err != nil {
if _, ok := err.(user_model.ErrEmailAlreadyUsed); ok {
ctx.Flash.Error(ctx.Tr("form.email_been_used"))
ctx.Redirect(setting.AppSubURL + "/user/settings")
@@ -141,7 +141,7 @@ func ProfilePost(ctx *context.Context) {
// UpdateAvatarSetting update user's avatar
// FIXME: limit size.
-func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *models.User) error {
+func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *user_model.User) error {
ctxUser.UseCustomAvatar = form.Source == forms.AvatarLocal
if len(form.Gravatar) > 0 {
if form.Avatar != nil {
@@ -178,12 +178,12 @@ func UpdateAvatarSetting(ctx *context.Context, form *forms.AvatarForm, ctxUser *
} else if ctxUser.UseCustomAvatar && ctxUser.Avatar == "" {
// No avatar is uploaded but setting has been changed to enable,
// generate a random one when needed.
- if err := models.GenerateRandomAvatar(ctxUser); err != nil {
+ if err := user_model.GenerateRandomAvatar(ctxUser); err != nil {
log.Error("GenerateRandomAvatar[%d]: %v", ctxUser.ID, err)
}
}
- if err := models.UpdateUserCols(db.DefaultContext, ctxUser, "avatar", "avatar_email", "use_custom_avatar"); err != nil {
+ if err := user_model.UpdateUserCols(db.DefaultContext, ctxUser, "avatar", "avatar_email", "use_custom_avatar"); err != nil {
return fmt.Errorf("UpdateUser: %v", err)
}
@@ -273,7 +273,7 @@ func Repos(ctx *context.Context) {
repoNames := make([]string, 0, setting.UI.Admin.UserPagingNum)
repos := map[string]*models.Repository{}
// We're going to iterate by pagesize.
- root := models.UserPath(ctxUser.Name)
+ root := user_model.UserPath(ctxUser.Name)
if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil {
if os.IsNotExist(err) {
@@ -377,7 +377,7 @@ func UpdateUIThemePost(ctx *context.Context) {
return
}
- if err := models.UpdateUserTheme(ctx.User, form.Theme); err != nil {
+ if err := user_model.UpdateUserTheme(ctx.User, form.Theme); err != nil {
ctx.Flash.Error(ctx.Tr("settings.theme_update_error"))
ctx.Redirect(setting.AppSubURL + "/user/settings/appearance")
return
@@ -403,7 +403,7 @@ func UpdateUserLang(ctx *context.Context) {
ctx.User.Language = form.Language
}
- if err := models.UpdateUserSetting(ctx.User); err != nil {
+ if err := user_model.UpdateUserSetting(ctx.User); err != nil {
ctx.ServerError("UpdateUserSetting", err)
return
}