Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
67 additions
and 2 deletions.
- +33 −0 handlers.go
- +15 −1 main.go
- +4 −1 templates/index.html
- +15 −0 templates/register.html
@@ -42,13 +42,27 @@ func main() { | ||
} | ||
database = session.DB("").Name | ||
|
||
//create an index for the username field on the users collection | ||
if err := session.DB("").C("users").EnsureIndex(mgo.Index{ | ||
Key: []string{"username"}, | ||
Unique: true, | ||
}); err != nil { | ||
panic(err) | ||
} | ||
|
||
This comment has been minimized.
zeebo
Author
Owner
|
||
store = sessions.NewCookieStore([]byte(os.Getenv("KEY"))) | ||
|
||
router = pat.New() | ||
router.Add("GET", "/login", handler(loginForm)).Name("login") | ||
router.Add("GET", "/logout", handler(logout)).Name("logout") | ||
router.Add("POST", "/login", handler(login)) | ||
|
||
router.Add("GET", "/register", handler(registerForm)).Name("register") | ||
router.Add("POST", "/register", handler(register)) | ||
|
||
router.Add("GET", "/logout", handler(logout)).Name("logout") | ||
|
||
router.Add("GET", "/", handler(hello)).Name("index") | ||
|
||
router.Add("POST", "/sign", handler(sign)).Name("sign") | ||
|
||
if err = http.ListenAndServe(":"+os.Getenv("PORT"), router); err != nil { | ||
@@ -0,0 +1,15 @@ | ||
{{ define "title" }}Guestbook - Register{{ end }} | ||
|
||
{{ define "content" }} | ||
<h1>Register</h1> | ||
|
||
{{ range .ctx.Session.Flashes }} | ||
<h2>{{ . }}</h2> | ||
{{ end }} | ||
|
||
<form action="{{ reverse "register" }}" method="POST"> | ||
<p>Username: <input type="text" name="username"></p> | ||
<p>Password: <input type="password" name="password"></p> | ||
<p><button>Login</button></p> | ||
</form> | ||
{{ end }} |
If we really wanted to be sure they got inserted correctly, we could use the experimental txn subpackage of mgo, but that's outside the scope right now.