Ejemplo n.º 1
0
Archivo: account.go Proyecto: jsli/cms
func (c Account) PostLogin(loginUser *models.LoginUser) revel.Result {
	//workflow is the same as PostRegister
	//step 0: check user is exist or not
	loginUser.Validate(c.Validation, c.MongoSession)

	//step 1: validation
	if c.Validation.HasErrors() {
		c.Validation.Keep()
		c.FlashParams()
		return c.Redirect(Account.GetLogin)
	}

	//update login status
	dal := models.NewDalMgo(c.MongoSession)
	user, err := dal.GetUserByName(loginUser.UserName)
	if user != nil && err == nil {
		user.IsLogined = true
		dal.UpdateUserById(user, user)
	}

	//step 3: save cookie, flash or session
	c.Session["user"] = loginUser.UserName
	c.Flash.Success("Welcome, login " + loginUser.UserName)
	fmt.Println("Welcome, login ", loginUser.UserName)

	//step 4: rediret
	return c.Redirect(Account.Index)
}
Ejemplo n.º 2
0
Archivo: account.go Proyecto: jsli/cms
func (c Account) Logout() revel.Result {
	//logout status
	dal := models.NewDalMgo(c.MongoSession)
	user, err := dal.GetUserByName(c.Session["user"])
	if user != nil && err == nil {
		user.IsLogined = false
		dal.UpdateUserById(user, user)
	}
	for k := range c.Session {
		delete(c.Session, k)
	}
	c.Flash.Success(fmt.Sprintf("Welcome, logout %s", user.UserName))
	return c.Redirect(App.Index)
}