Add sign in handler

This commit is contained in:
2024-08-08 12:22:56 -04:00
parent c4b5dcedf9
commit 951c081680
5 changed files with 31 additions and 1 deletions

View File

@@ -45,6 +45,21 @@ func (u Users) GetSignin(w http.ResponseWriter, r *http.Request) {
data.Email = r.FormValue("email")
u.Templates.Signin.Execute(w, data)
}
func (u Users) PostSignin(w http.ResponseWriter, r *http.Request) {
var data struct {
Email string
Password string
}
data.Email = r.FormValue("email")
data.Password = r.FormValue("password")
user, err := u.UserService.Authenticate(data.Email, data.Password)
if err != nil {
fmt.Println(err)
http.Error(w, "Something went wrong.", http.StatusInternalServerError)
return
}
fmt.Fprintf(w, "User authenticated: %+v", user)
}
func WithTemplates(user_service *models.UserService, signup Template, signin Template) Users {
u := Users{}