Implemented Logout function

pull/24/head
Jordan 2014-02-02 16:55:26 -06:00
parent 43417d160f
commit ca884fd384
1 changed files with 14 additions and 0 deletions

View File

@ -19,6 +19,7 @@ func CreateRouter() *mux.Router {
router := mux.NewRouter() router := mux.NewRouter()
// Base Front-end routes // Base Front-end routes
router.HandleFunc("/login", Login) router.HandleFunc("/login", Login)
router.HandleFunc("/logout", Use(Logout, mid.RequireLogin))
router.HandleFunc("/register", Register) router.HandleFunc("/register", Register)
router.HandleFunc("/", Use(Base, mid.RequireLogin)) router.HandleFunc("/", Use(Base, mid.RequireLogin))
router.HandleFunc("/campaigns/{id:[0-9]+}", Use(Campaigns_Id, mid.RequireLogin)) router.HandleFunc("/campaigns/{id:[0-9]+}", Use(Campaigns_Id, mid.RequireLogin))
@ -54,6 +55,19 @@ func Register(w http.ResponseWriter, r *http.Request) {
Login(w, r) Login(w, r)
} }
func Logout(w http.ResponseWriter, r *http.Request) {
// If it is a post request, attempt to register the account
// Now that we are all registered, we can log the user in
session := ctx.Get(r, "session").(*sessions.Session)
delete(session.Values, "id")
session.AddFlash(models.Flash{
Type: "success",
Message: "You have successfully logged out.",
})
session.Save(r, w)
http.Redirect(w, r, "login", 302)
}
func Base(w http.ResponseWriter, r *http.Request) { func Base(w http.ResponseWriter, r *http.Request) {
// Example of using session - will be removed. // Example of using session - will be removed.
params := struct { params := struct {