Пример #1
0
func (c PublicApplication) UserNameExists() revel.Result {
	var name string
	c.Params.Bind(&name, "user_name")
	return c.RenderJson(map[string]interface{}{
		"status": "success",
		"result": models.UserNameExists(name),
	})
}
Пример #2
0
func (c PublicApplication) CreateUser() revel.Result {
	var user models.User

	c.Params.Bind(&user, "user")

	if !validEmail(user.Email) {
		c.Flash.Error("Invalid email ... please use the university provided email account")
		return c.Redirect(routes.PublicApplication.CreateUser())
	}
	if models.UserNameExists(user.UserName) {
		c.Flash.Error("Username Already taken")
		return c.Redirect(routes.PublicApplication.CreateUser())
	}

	user.Validate(c.Validation)

	if c.Validation.HasErrors() {
		c.Flash.Error("Cannot signup!")
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(routes.PublicApplication.CreateUser())
	}

	user.Hashed = false

	if err := models.CreateUser(user); err != nil {
		stats.TRACE.Println("Failed to create user ", err)
		return c.Redirect(routes.PublicApplication.CreateUser())
	}

	c.Session["user"] = user.UserName

	c.Flash.Success("Welcome, " + user.UserName)

	stats.Incr("App", "Users")

	return c.Redirect(routes.PublicApplication.Index())
}