Exemple #1
0
func (a Auth) DoLogin(email, pwd, validationCode, captchaId string) revel.Result {
	log.Println("email:", email, "validationCode:", validationCode, "captchaId:", captchaId)
	ok := app.NewOk()
	ok.Ok = a.Validation.Required(captcha.VerifyString(captchaId, validationCode)).Ok
	if !ok.Ok {
		ok.Msg = "captcha"
		return a.RenderJson(ok)
	}
	ok.Ok = a.Validation.Required(email).Ok
	if !ok.Ok {
		ok.Msg = "email"
		return a.RenderJson(ok)
	}
	ok.Ok = a.Validation.Email(email).Ok
	if !ok.Ok {
		ok.Msg = "email"
		return a.RenderJson(ok)
	}

	if !a.checkAuth() {
		ok.Msg = "login"
		ok.Ok = false
	} else {
		ok.Next = app.NextJson{"href", "/index"}
		a.Session["user"] = email
		if email == "*****@*****.**" {
			ok.Msg = "admin"
		}
	}

	log.Println("set register session:", a.Session, "with resp:", ok)
	return a.RenderJson(ok)
}
Exemple #2
0
func (a Auth) DoRegister(email, pwd, captcha, captchaId string) revel.Result {
	ok := app.NewOk()

	a.Validation.Required(!a.userService().ExistsUserByEmail(email)).Message(
		"userHasBeenRegistered", email)
	if ret := a.checkAuth(); !ret {
		ok.Ok = false
		ok.Msg = "exists"
		log.Println(email, "has already been registed")
		return a.RenderJson(ok)
	}

	user, err := a.userService().RegistUserByEmail(email, pwd)
	if err != nil {
		a.Flash.Error(err.Error())
		ok.Ok = false
		ok.Msg = "error"
		log.Println(email, "registed with error:", err)
		return a.RenderJson(ok)
	}

	// send activation mail to user
	SendMail(a.Message("activationMail"), fmt.Sprintf(
		`<a href="http://*****:*****@qq.com" {
		ok.Msg = "admin"
	}
	log.Println("set register session:", a.Session)
	return a.RenderJson(ok)
	// return a.Redirect("/items")
}