login on register
This commit is contained in:
parent
ca4823e80b
commit
8a07105316
13
server.go
13
server.go
@ -95,6 +95,19 @@ func (s *Server) Register(w http.ResponseWriter, r *http.Request) {
|
|||||||
http.Error(w, "something went wrong, maybe someone already has that username, idk", http.StatusInternalServerError)
|
http.Error(w, "something went wrong, maybe someone already has that username, idk", http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
p, err := player.Login(ctx, s.creds, user, pass)
|
||||||
|
if err != nil {
|
||||||
|
slog.ErrorContext(ctx, "login failed", "err", err.Error())
|
||||||
|
http.Error(w, "no", http.StatusUnauthorized)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
id, err := player.StartSession(ctx, s.sessions, p, time.Now())
|
||||||
|
if err != nil {
|
||||||
|
slog.ErrorContext(ctx, "failed to create session", "player", p, "err", err.Error())
|
||||||
|
http.Error(w, "something went wrong", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
serve.SetSession(w, id)
|
||||||
http.Redirect(w, r, "/", http.StatusSeeOther)
|
http.Redirect(w, r, "/", http.StatusSeeOther)
|
||||||
slog.InfoContext(ctx, "registered", "user", user)
|
slog.InfoContext(ctx, "registered", "user", user)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user