Esempio n. 1
0
File: ctrl.go Progetto: xtfly/goman
//----------------------------------------------------------
// /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")
}
Esempio n. 2
0
func (s *AccountService) Signup(f SignupForm, clientip string) (*models.Users, string, bool) {
	if msg, ok := s.CheckSignup(f); !ok {
		return nil, msg, ok
	}

	var invitation *models.Invitation
	if f.ICode != "" {
		if invitation = models.CheckICodeAvailable(f.ICode); invitation == nil {
			return nil, "邀请码无效或与邀请邮箱不一致", false
		}
	}

	u := &models.Users{}
	u.UserName = f.Name
	u.Email = f.Email
	u.Password = f.Password
	u.Gender = f.Gender
	u.JobId = f.JobId
	u.Province = f.Province
	u.City = f.City
	u.Signature = f.Signature
	u.RegIp = clientip
	u.GroupId = models.GroupNotValidated // 未验证会员
	if invitation != nil && f.Email == invitation.Email {
		u.ValidEmail = true
		u.GroupId = models.GroupNormal //  验证会员
	}

	t := models.NewTr().Begin()
	defer t.End()
	uid, ok := u.Add(t)
	if !ok {
		return nil, "内部系统错误", false

	}
	u.Id = uid

	// 把邀请者加为好友
	if invitation != nil {
		if !models.AddUserFollow(t, uid, invitation.Uid) {
			return nil, "内部系统错误", false
		}

		if !invitation.Active(t, clientip, uid) {
			return nil, "内部系统错误", false
		}
	}

	return u, "", true
}