Ejemplo n.º 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)
}
Ejemplo n.º 2
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)
}