Exemple #1
0
func (this *SocialAuthController) ConnectPost() {
	token := this.Ctx.GetCookie("epic_user_token")
	ok, userId := tools.VerifyToken(token)
	if !ok || len(userId) == 0 {
		this.Redirect("/", 302)
		return
	}
	password := this.GetString("Password")
	userName := this.GetString("UserName")
	if len(userId) == 0 || len(password) == 0 || len(userName) == 0 {
		this.Data["userId"] = userId
		this.TplNames = "connect.html"
		this.Data["error"] = "[用户名]或者[密码]为空"
		this.Data["state"] = "注册失败"
		this.Data["msg"] = "[用户名]或者[邮箱]已被注册"
		return
	}
	isExist := auth.UserIsExists(userName, userName)
	if isExist {
		this.Data["userId"] = userId
		this.TplNames = "connect.html"
		this.Data["error"] = "[用户名]或者[邮箱]已被注册"
		this.Data["state"] = "注册失败"
		this.Data["msg"] = "[用户名]或者[邮箱]已被注册"
		return
	}
	user := models.User{}
	user.Password = password
	user.UserName = userName
	user.Id, _ = strconv.Atoi(userId)
	err := auth.ConnectUpdateUser(&user, password)
	if err != nil {
		this.Data["userId"] = userId
		this.TplNames = "connect.html"
		this.Data["error"] = err.Error()
		this.Data["state"] = "注册失败"
		beego.Error("注册失败-插入数据库出错", err)
		this.Data["msg"] = err.Error()
		return
	}

	subSitesConf := config.GetSubSites()
	this.Data["srcs"] = strings.Split(subSitesConf, ",")
	this.Data["token"] = token
	this.Data["state"] = "注册成功"
	this.Data["msg"] = "3秒后自动跳转!!"
	this.Data["succ"] = true
	this.Data["redirectURL"] = config.GetRedirectURL()
	this.TplNames = "succeed.html"
}
Exemple #2
0
func (this *RegisterController) Register() {
	redirectURL := this.GetString("redirectURL")
	if "" == redirectURL {
		redirectURL = config.GetRedirectURL()
	}

	this.Data["redirectURL"] = redirectURL

	user := models.User{}
	err := this.ParseForm(&user)
	this.TplNames = "succeed.html"
	this.Data["succ"] = true
	if err != nil {
		beego.Error("注册失败-表单解析出错", err)
		this.Data["state"] = "注册失败"
		this.Data["msg"] = err.Error()
		this.Data["succ"] = false
		return
	}
	ok := setting.Captcha.VerifyReq(this.Ctx.Request)
	if !ok {
		this.Data["state"] = "注册失败"
		this.Data["msg"] = "验证码错误"
		this.Data["succ"] = false
		return
	}

	isExist := auth.UserIsExists(user.UserName, user.Email)
	if isExist {
		this.Data["state"] = "注册失败"
		this.Data["msg"] = "[用户名]或者[邮箱]已被注册"
		this.Data["succ"] = false
		return
	}
	err = auth.RegisterUser(&user, user.UserName, user.Email, user.Password)
	if err != nil {
		this.Data["state"] = "注册失败"
		beego.Error("注册失败-插入数据库出错", err)
		this.Data["msg"] = err.Error()
		this.Data["succ"] = false
		return
	}
	this.Data["state"] = "注册成功"
	this.Data["msg"] = "恭喜!!将进行自动跳转,请稍等..."

}