diff --git a/models/user.go b/models/user.go index df1eb985c..661eff2fd 100644 --- a/models/user.go +++ b/models/user.go @@ -410,21 +410,27 @@ func GetUserByEmail(email string) (*User, error) { } // LoginUserPlain validates user by raw user name and password. -func LoginUserPlain(name, passwd string) (*User, error) { - user := User{LowerName: strings.ToLower(name)} - has, err := orm.Get(&user) +func LoginUserPlain(uname, passwd string) (*User, error) { + var u *User + if strings.Contains(uname, "@") { + u = &User{Email: uname} + } else { + u = &User{LowerName: strings.ToLower(uname)} + } + + has, err := orm.Get(u) if err != nil { return nil, err } else if !has { return nil, ErrUserNotExist } - newUser := &User{Passwd: passwd, Salt: user.Salt} + newUser := &User{Passwd: passwd, Salt: u.Salt} newUser.EncodePasswd() - if user.Passwd != newUser.Passwd { + if u.Passwd != newUser.Passwd { return nil, ErrUserNotExist } - return &user, nil + return u, nil } // Follow is connection request for receiving user notifycation. diff --git a/modules/auth/auth.go b/modules/auth/auth.go index 350ef4fcb..e493faefe 100644 --- a/modules/auth/auth.go +++ b/modules/auth/auth.go @@ -57,7 +57,7 @@ func (f *RegisterForm) Validate(errors *base.BindingErrors, req *http.Request, c } type LogInForm struct { - UserName string `form:"username" binding:"Required;AlphaDash;MaxSize(30)"` + UserName string `form:"username" binding:"Required;MaxSize(35)"` Password string `form:"passwd" binding:"Required;MinSize(6);MaxSize(30)"` Remember string `form:"remember"` } diff --git a/routers/user/user.go b/routers/user/user.go index fe53896e4..9cce4e719 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -144,27 +144,6 @@ func SignInPost(ctx *middleware.Context, form auth.LogInForm) { ctx.Redirect("/") } -func oauthSignInPost(ctx *middleware.Context, sid int64) { - ctx.Data["Title"] = "OAuth Sign Up" - ctx.Data["PageIsSignUp"] = true - - if _, err := models.GetOauth2ById(sid); err != nil { - if err == models.ErrOauth2RecordNotExist { - ctx.Handle(404, "user.oauthSignUp(GetOauth2ById)", err) - } else { - ctx.Handle(500, "user.oauthSignUp(GetOauth2ById)", err) - } - return - } - - ctx.Data["IsSocialLogin"] = true - ctx.Data["username"] = ctx.Session.Get("socialName") - ctx.Data["email"] = ctx.Session.Get("socialEmail") - log.Trace("user.oauthSignUp(social ID): %v", ctx.Session.Get("socialId")) - - ctx.HTML(200, "user/signup") -} - func SignOut(ctx *middleware.Context) { ctx.Session.Delete("userId") ctx.Session.Delete("userName") diff --git a/templates/user/signin.tmpl b/templates/user/signin.tmpl index 955c82f43..09ce249f7 100644 --- a/templates/user/signin.tmpl +++ b/templates/user/signin.tmpl @@ -10,7 +10,7 @@ {{end}} {{template "base/alert" .}}