1
0
mirror of https://github.com/go-gitea/gitea synced 2024-12-24 03:35:55 +01:00

Add login by email

This commit is contained in:
Unknown 2014-04-27 01:54:08 -06:00
parent ce05a8d7b6
commit 62240b6bc1
4 changed files with 14 additions and 29 deletions

@ -410,21 +410,27 @@ func GetUserByEmail(email string) (*User, error) {
} }
// LoginUserPlain validates user by raw user name and password. // LoginUserPlain validates user by raw user name and password.
func LoginUserPlain(name, passwd string) (*User, error) { func LoginUserPlain(uname, passwd string) (*User, error) {
user := User{LowerName: strings.ToLower(name)} var u *User
has, err := orm.Get(&user) if strings.Contains(uname, "@") {
u = &User{Email: uname}
} else {
u = &User{LowerName: strings.ToLower(uname)}
}
has, err := orm.Get(u)
if err != nil { if err != nil {
return nil, err return nil, err
} else if !has { } else if !has {
return nil, ErrUserNotExist return nil, ErrUserNotExist
} }
newUser := &User{Passwd: passwd, Salt: user.Salt} newUser := &User{Passwd: passwd, Salt: u.Salt}
newUser.EncodePasswd() newUser.EncodePasswd()
if user.Passwd != newUser.Passwd { if u.Passwd != newUser.Passwd {
return nil, ErrUserNotExist return nil, ErrUserNotExist
} }
return &user, nil return u, nil
} }
// Follow is connection request for receiving user notifycation. // Follow is connection request for receiving user notifycation.

@ -57,7 +57,7 @@ func (f *RegisterForm) Validate(errors *base.BindingErrors, req *http.Request, c
} }
type LogInForm struct { 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)"` Password string `form:"passwd" binding:"Required;MinSize(6);MaxSize(30)"`
Remember string `form:"remember"` Remember string `form:"remember"`
} }

@ -144,27 +144,6 @@ func SignInPost(ctx *middleware.Context, form auth.LogInForm) {
ctx.Redirect("/") 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) { func SignOut(ctx *middleware.Context) {
ctx.Session.Delete("userId") ctx.Session.Delete("userId")
ctx.Session.Delete("userName") ctx.Session.Delete("userName")

@ -10,7 +10,7 @@
{{end}} {{end}}
{{template "base/alert" .}} {{template "base/alert" .}}
<div class="form-group {{if .Err_UserName}}has-error has-feedback{{end}}"> <div class="form-group {{if .Err_UserName}}has-error has-feedback{{end}}">
<label class="col-md-4 control-label">Username: </label> <label class="col-md-4 control-label">Username or e-mail: </label>
<div class="col-md-6"> <div class="col-md-6">
<input name="username" class="form-control" placeholder="Type your username" value="{{.username}}" required="required"> <input name="username" class="form-control" placeholder="Type your username" value="{{.username}}" required="required">
</div> </div>