Skip to content

Commit

Permalink
Authenticate a user
Browse files Browse the repository at this point in the history
  • Loading branch information
mariojackson committed Jun 13, 2020
1 parent e0e4772 commit 56ef59d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cmd/web/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ func (app *application) signupUser(w http.ResponseWriter, r *http.Request) {
}

func (app *application) loginUserForm(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "display user login form")
app.render(w, r, "login.page.tmpl", &templateData{
Form: forms.New(nil),
})
}

func (app *application) loginUser(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/web/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func (app *application) routes() http.Handler {

mux.Get("/users/signup", dynamicMiddleware.ThenFunc(app.signupUserForm))
mux.Post("/users/signup", dynamicMiddleware.ThenFunc(app.signupUser))
mux.Get("/usesr/login", dynamicMiddleware.ThenFunc(app.loginUserForm))
mux.Get("/users/login", dynamicMiddleware.ThenFunc(app.loginUserForm))
mux.Post("/users/login", dynamicMiddleware.ThenFunc(app.loginUser))
mux.Post("/users/logout", dynamicMiddleware.ThenFunc(app.logoutUser))

Expand Down
25 changes: 25 additions & 0 deletions ui/html/login.page.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{{ template "base" . }}

{{ define "title" }}Login{{ end }}

{{ define "main" }}
<form action='/users/login' method='POST' novalidate>
{{ with .Form }}
{{ with .Errors.Get "generic" }}
<div class='error'>{{ . }}</div>
{{ end }}
<div>
<label>Email</label>
<input type='email' name='email' value='{{ .Get "email" }}'>
</div>
<div>
<label>Password</label>
<input type='password' name='password'>
</div>
<div>
<input type='submit' value='Login'>
</div>
{{ end }}
</form>
{{ end }}

2 changes: 1 addition & 1 deletion ui/html/signup.page.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
</div>
{{ end }}
</form>
{{ end }}
{{ end }}

0 comments on commit 56ef59d

Please sign in to comment.