mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-25 21:13:01 +01:00
Add login by email
This commit is contained in:
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.
|
||||
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.
|
||||
|
|
|
@ -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"`
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
{{end}}
|
||||
{{template "base/alert" .}}
|
||||
<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">
|
||||
<input name="username" class="form-control" placeholder="Type your username" value="{{.username}}" required="required">
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue