mirror of
https://github.com/1f349/lavender.git
synced 2025-04-14 06:55:55 +01:00
Fixes to password provider
This commit is contained in:
parent
4300165ae3
commit
ba76dc5371
@ -25,14 +25,13 @@ type PasswordLogin struct {
|
||||
DB passwordLoginDB
|
||||
}
|
||||
|
||||
func (b *PasswordLogin) AccessState() process.State { return process.StateBase }
|
||||
func (p *PasswordLogin) AccessState() process.State { return process.StateBase }
|
||||
|
||||
func (b *PasswordLogin) Name() string { return "password" }
|
||||
func (p *PasswordLogin) Name() string { return "password" }
|
||||
|
||||
func (b *PasswordLogin) RenderTemplate(ctx authContext.TemplateContext) error {
|
||||
func (p *PasswordLogin) RenderTemplate(ctx authContext.TemplateContext) error {
|
||||
// TODO(melon): rewrite this
|
||||
req := ctx.Request()
|
||||
un := req.FormValue("login")
|
||||
redirect := req.FormValue("redirect")
|
||||
if redirect == "" {
|
||||
redirect = "/"
|
||||
@ -41,24 +40,24 @@ func (b *PasswordLogin) RenderTemplate(ctx authContext.TemplateContext) error {
|
||||
UserEmail string
|
||||
Redirect string
|
||||
}{
|
||||
UserEmail: un,
|
||||
UserEmail: ctx.LoginProcessData().Email,
|
||||
Redirect: redirect,
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (b *PasswordLogin) AttemptLogin(ctx authContext.FormContext) error {
|
||||
func (p *PasswordLogin) AttemptLogin(ctx authContext.FormContext) error {
|
||||
req := ctx.Request()
|
||||
un := req.FormValue("username")
|
||||
un := req.FormValue("email")
|
||||
pw := req.FormValue("password")
|
||||
if len(pw) < 8 {
|
||||
return auth.BasicUserSafeError(http.StatusBadRequest, "Password too short")
|
||||
}
|
||||
|
||||
login, err := b.DB.CheckLogin(ctx.Context(), un, pw)
|
||||
login, err := p.DB.CheckLogin(ctx.Context(), un, pw)
|
||||
switch {
|
||||
case err == nil:
|
||||
user, err := b.DB.GetUser(ctx.Context(), login.Subject)
|
||||
user, err := p.DB.GetUser(ctx.Context(), login.Subject)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
|
||||
-- name: checkLogin :one
|
||||
SELECT subject, password, need_factor, email, email_verified
|
||||
FROM users
|
||||
WHERE users.subject = ?
|
||||
WHERE users.email = ?
|
||||
LIMIT 1;
|
||||
|
||||
-- name: GetUser :one
|
||||
|
@ -219,7 +219,7 @@ func (q *Queries) changeUserPassword(ctx context.Context, arg changeUserPassword
|
||||
const checkLogin = `-- name: checkLogin :one
|
||||
SELECT subject, password, need_factor, email, email_verified
|
||||
FROM users
|
||||
WHERE users.subject = ?
|
||||
WHERE users.email = ?
|
||||
LIMIT 1
|
||||
`
|
||||
|
||||
@ -231,8 +231,8 @@ type checkLoginRow struct {
|
||||
EmailVerified bool `json:"email_verified"`
|
||||
}
|
||||
|
||||
func (q *Queries) checkLogin(ctx context.Context, subject string) (checkLoginRow, error) {
|
||||
row := q.db.QueryRowContext(ctx, checkLogin, subject)
|
||||
func (q *Queries) checkLogin(ctx context.Context, email string) (checkLoginRow, error) {
|
||||
row := q.db.QueryRowContext(ctx, checkLogin, email)
|
||||
var i checkLoginRow
|
||||
err := row.Scan(
|
||||
&i.Subject,
|
||||
|
Loading…
x
Reference in New Issue
Block a user