Esempio n. 1
0
// GetLogin shows the login form for the backend.
func GetLogin(w http.ResponseWriter, req *http.Request, app *App) {
	if models.UserCount(app.Db) > 0 {
		render(w, "admin/login", map[string]interface{}{"hideNav": true}, app)
	} else {
		http.Redirect(w, req, app.Config.General.Prefix+"/register", http.StatusSeeOther)
	}

}
Esempio n. 2
0
// PostUser will create a new user when no other users are in the database.
// If users are present, it will redirect to the login.
func PostUser(w http.ResponseWriter, req *http.Request, app *App) {
	if models.UserCount(app.Db) == 0 {
		email, password := req.FormValue("email"), req.FormValue("password")
		user := models.NewUser(email, password)
		err := user.Save(app.Db)
		if err != nil {
			http.Redirect(w, req, app.Config.General.Prefix+"/register", http.StatusFound)
		} else {
			http.Redirect(w, req, app.Config.General.Prefix+"/login", http.StatusFound)
		}
	}
}