Esempio n. 1
0
// GET /users/:uuid/activate
func GetUsersActivate(r render.Render, params martini.Params) {
	user := db.User{}
	if db.DB.Where("activation_token = ?", params["uuid"]).First(&user).RecordNotFound() {
		r.Error(404)
	} else {
		if err := user.Activate(); err != nil {
			r.Error(500)
		}
		r.Status(200)
	}
}
Esempio n. 2
0
// GET /users/user/:uuid/reset
func GetUsersReset(r render.Render, params martini.Params) {
	user := db.User{}
	if db.DB.Where("uuid = ?", params["uuid"]).First(&user).RecordNotFound() {
		r.Error(404)
	} else {
		password := utils.RandPassword(8)
		user.Password = utils.Hash([]byte(password), []byte(user.Salt))
		db.DB.Save(&user)
		go utils.SendResetPassword(user.Email, password)
		r.Redirect("/users")
	}
}
Esempio n. 3
0
// POST /users
func PostUsers(r render.Render, req *http.Request) {
	name := req.PostFormValue("name")
	email := req.PostFormValue("email")
	password := req.PostFormValue("password")
	uuid := req.PostFormValue("uuid")
	var user = db.User{}
	if uuid != "" {
		if db.DB.Where("uuid = ?", uuid).First(&user).RecordNotFound() {
			r.Error(404)
		}
		user.Name = name
		user.Email = email
	} else {
		user = db.User{Name: name, Email: email, Password: password}
	}
	if err := db.DB.Save(&user).Error; err != nil {
		r.Error(500)
	} else {
		r.Redirect("/users")
	}
}