Exemple #1
0
func logout(w http.ResponseWriter, r *http.Request) {
	log.Println("User requested logout.")
	user := configuration.GetUserCredentails()
	logged := configuration.GetUserLoggedDetails()
	logged.IsLoggedIn = "false"
	err := configuration.SaveUserLoggedDetails(logged)
	if err != nil {
		log.Fatal("Error saving user logged in details while signing out. ", err)
	}
	log.Println(user.Name + " has been successfully logged out.")
	http.Redirect(w, r, "/", 301)
}
Exemple #2
0
func home(w http.ResponseWriter, r *http.Request) {
	log.Println("User requested home view.")
	logged := configuration.GetUserLoggedDetails()
	user := configuration.GetUserCredentails()
	if logged.IsLoggedIn == "true" {
		log.Println(user.Name + " has already been logged in to the application.")
		t, _ := template.ParseFiles("templates/home.html", "templates/snippets/homeheader.html", "templates/snippets/home.html", "templates/snippets/welcomefooter.html")
		t.Execute(w, nil)
	} else {
		log.Println("User has not logged in to the application.")
		t, _ := template.ParseFiles("templates/home.html", "templates/snippets/welcomeheader.html", "templates/snippets/signin.html", "templates/snippets/welcomefooter.html")
		t.Execute(w, nil)
	}
}
Exemple #3
0
func signin(w http.ResponseWriter, r *http.Request) {
	log.Println("User requested signin.")
	logged := configuration.GetUserLoggedDetails()
	user := configuration.GetUserCredentails()
	r.ParseForm()
	user.Name = template.HTMLEscapeString(r.Form.Get("username"))
	user.Email = template.HTMLEscapeString(r.Form.Get("email"))
	password := md5.New()
	io.WriteString(password, template.HTMLEscapeString(r.Form.Get("password")))
	user.Password = string(password.Sum(nil))
	err := configuration.SaveUserCredentials(user)
	if err != nil {
		log.Fatal("Error saving user credentials while signing in. ", err)
	}
	logged.IsLoggedIn = "true"
	err = configuration.SaveUserLoggedDetails(logged)
	if err != nil {
		log.Fatal("Error saving user logged in details while signing in. ", err)
	}
	log.Println(user.Name + " has been successfully logged in.")
	http.Redirect(w, r, "/", 301)
}