Beispiel #1
0
//----------------------------------------------------------
// /a/signup
func GetSignupCtrl(c *macaron.Context, cpt *captcha.Captcha, a token.TokenService) {
	r := core.NewRender(c)

	if boot.SysSetting.Ra.SiteClose {
		r.RedirectMsg("本站目前关闭注册", "/")
		return
	}

	icode := c.QueryEscape("icode")
	if boot.SysSetting.Ra.RegisterType == models.RegTypeInvite && icode == "" {
		r.RedirectMsg("本站只接受邀请注册", "/")
		return
	}

	if icode != "" {
		if i := models.CheckICodeAvailable(icode); i != nil {
			r.Data["icode"] = icode
		} else {
			r.RedirectMsg("邀请码无效或已经使用, 请使用新的邀请码", "/")
			return
		}
	}

	r.AddCss("signup.css").AddJs("comps/signup.js")
	r.SetCaptcha(cpt)

	c.Data["jobs"] = models.AllJobs()
	c.Data["csrf_token"], _ = a.GenSysToken(c.RemoteAddr(), 15)
	r.RHTML(200, "account/signup")
}
Beispiel #2
0
//----------------------------------------------------------
// POST /api/account/signup/
func ApiUserSignup(f SignupForm, c *macaron.Context, cpt *captcha.Captcha,
	a token.TokenService, ss session.Store) {
	if !a.ValidToken(c.RemoteAddr(), f.CsrfToken) {
		c.JSON(200, comps.NewRestErrResp(-1, "非法的跨站请求"))
		return
	}

	if !cpt.VerifyReq(c.Req) {
		c.JSON(200, comps.NewRestResp(comps.NewCaptcha(cpt), -1, "请填写正确的验证码"))
		return
	}

	s := NewService()
	u, msg, ok := s.Signup(f, c.RemoteAddr())
	if !ok {
		c.JSON(200, comps.NewRestResp(comps.NewCaptcha(cpt), -1, msg))
		return
	}

	// 如果不需要email验证
	if boot.SysSetting.Ra.RegisterValidType == models.RegValidNone ||
		u.GroupId != models.GroupNotValidated ||
		u.ValidEmail {
		SetSigninCookies(c, u, a, ss)
		c.JSON(200, comps.NewRestRedirectResp("/h/firstlogin"))
		return
	}

	ss.Set("validemail", u.Email)
	if !models.NewValidByEmail(models.NewTr(), u.Id, u.Email) {
		c.JSON(200, comps.NewRestErrResp(-1, "内部系统错误"))
		return
	}

	SetSigninCookies(c, u, a, ss)
	c.JSON(200, comps.NewRestRedirectResp("/a/validemail/"))
	return
}
Beispiel #3
0
//----------------------------------------------------------
// 设置Cookie信息
func SetSigninCookies(c *macaron.Context, u *models.Users, a token.TokenService, ss session.Store) {
	t, _ := a.GenUserToken(c.RemoteAddr(), u.Id, 24*60, token.TokenUser)
	c.SetCookie("utoken", t, 24*60*60) // Name, Value, MaxAge, Path, Domain, Secure, HttpOnly
	ss.Set("utoken", t)
}