Пример #1
0
func (s *AccountService) CheckSignup(f SignupForm) (string, bool) {
	ra := boot.SysSetting.Ra
	switch ra.RegisterType {
	case models.RegTypeClose:
		return "本站目前关闭注册", false
	case models.RegTypeInvite:
		if f.ICode == "" {
			return "本站只能通过邀请注册", false
		}
	default:
		break
	}

	if err, ok := s.CheckUsernameChar(f.Name); !ok {
		return err, ok
	}

	if s.CheckUsernameSensitiveWords(f.Name) || models.UserExistedByName(f.Name) {
		return "用户名已被注册或包含敏感词或系统保留字", false
	}

	if !gokits.IsEmail(f.Email) || models.UserExistedByEmail(f.Email) {
		return "EMail 已经被使用, 或格式不正确", false
	}

	if len(f.Password) < 6 {
		return "密码长度不符合规则", false
	}

	if !f.Agree {
		return "你必需同意用户协议才能继续", false
	}

	if f.Gender < models.GenderUnknown || f.Gender > models.GenderFemale {
		return "非法的性别输入", false
	}

	return "", true
}
Пример #2
0
//----------------------------------------------------------
// POST /api/account/setting/profile
func ApiSettingProfile(c *macaron.Context, f UserSettingForm, ss session.Store) {
	r := core.NewRender(c)

	if msg, ok := r.CheckUser(); !ok {
		c.JSON(200, comps.NewRestErrResp(-1, msg))
		return
	}

	s := NewService()
	u := r.UserInfo
	nu := &models.Users{Id: u.Id}
	t := models.NewTr().Begin()
	defer t.End()

	// 如果原来是采用Email注册,默认使用Email做为username
	nu.UserName = u.UserName
	if f.UserName != "" {
		if msg, ok := s.CheckUsernameChar(f.UserName); !ok {
			c.JSON(200, comps.NewRestErrResp(-1, msg))
			return
		}
		if u.UserName != f.UserName && models.UserExistedByName(f.UserName) {
			c.JSON(200, comps.NewRestErrResp(-1, "已经存在相同的姓名, 请重新填写"))
			return
		}
		nu.UserName = f.UserName
	}

	//
	nu.UrlToken = u.UrlToken
	if f.UrlToken != "" && f.UrlToken != u.UrlToken {
		if msg, ok := s.CheckUrlToken(&u.Users, f.UrlToken); !ok {
			c.JSON(200, comps.NewRestErrResp(-1, msg))
			return
		}
		nu.UrlToken = f.UrlToken
	}

	nu.Email = u.Email
	if f.Email != "" {
		if !gokits.IsEmail(f.Email) {
			c.JSON(200, comps.NewRestErrResp(-1, "请输入正确的 E-Mail 地址"))
			return
		}
		if !models.UserExistedByEmail(f.Email) {
			c.JSON(200, comps.NewRestErrResp(-1, "邮箱已经存在, 请使用新的邮箱"))
			return
		}
		nu.Email = f.Email
		models.NewValidByEmail(t, u.Id, nu.Email)
	}

	nu.CommonEmail = u.CommonEmail
	if f.CommonEmail != "" {
		if !gokits.IsEmail(f.CommonEmail) {
			c.JSON(200, comps.NewRestErrResp(-1, "请输入正确的常用邮箱地址"))
			return
		}
		nu.CommonEmail = f.CommonEmail
	}

	nu.Gender = f.Gender
	nu.Province = gokits.IfEmpty(f.Province, u.Province)
	nu.City = gokits.IfEmpty(f.City, u.City)

	nu.Birthday = u.Birthday
	if f.Birthday != "" {
		nu.Birthday, _ = time.Parse("19801010", f.Birthday)
	}

	nu.Signature = u.Signature
	if f.Signature != "" {
		nu.Signature = f.Signature
		if !models.IntegralLogExistByUidAction(u.Id, models.IntegralUpdateUserSignature) {
			models.AddIntegralLog(t, u.Id, models.IntegralUpdateUserSignature, int64(float64(boot.SysSetting.Ir.FinishProfile)*0.1), "完善一句话介绍")
		}
	}

	nu.JobId = u.JobId
	if f.JobId != 0 {
		nu.JobId = f.JobId
	}
	nu.Mobile = gokits.IfEmpty(f.Mobile, u.Mobile)

	if boot.SysSetting.Cs.AutoCreateSocialTopic {
		if f.Province != "" {
			models.AddTopic(t, f.Province)
		}
		if f.City != "" {
			models.AddTopic(t, f.City)
		}
	}

	if _, ok := t.Update(nu, "UserName", "Gender", "Province", "Province", "JobId",
		"Signature", "Email", "Signature", "UrlToken", "CommonEmail",
		"Birthday", "Mobile"); !ok {
		c.JSON(200, comps.NewRestErrResp(-1, "个人资料保存成功失败"))
	} else {
		c.JSON(200, comps.NewRestErrResp(1, "个人资料保存成功"))
	}
}