Esempio n. 1
0
File: user.go Progetto: xtfly/goman
//----------------------------------------------------------
// 增加一条记录
func (m *Users) Add(t *Transaction) (int64, bool) {
	m.LastIp = m.RegIp

	//
	m.Password, m.Salt = gokits.GenPasswd(m.Password, 8)

	// 生成用户的URL
	m.UrlToken = gokits.NewRandWithPrefix(m.Email, 8)
	m.UrlTokenUpdated = time.Now()

	m.InvitationAvailable = syscfg.Ra.NewerInviteNum
	m.RepuGroup = 5 // TODO
	m.FirstLogin = true

	// 前面要求对邀请码验证
	if syscfg.Ra.RegisterValidType == RegValidNone ||
		(syscfg.Ra.RegisterValidType == RegValidEmail && syscfg.Ra.RegisterType == RegTypeInvite) {
		m.GroupId = GroupNormal
	}

	//
	id, ok := t.Insert(m)
	if !ok {
		return id, ok
	}

	// 增加关注关系表
	fuids := strings.Split(syscfg.Ra.DefFocusUids, ",")
	for _, fuid := range fuids {
		if !AddUserFollow(t, id, com.StrTo(fuid).MustInt64()) {
			return id, false
		}
	}

	// 初始化积分
	if !AddIntegralLog(t, id, IntegralRegister, syscfg.Ir.DefautlIntegral, "初始资本") {
		return id, false
	}

	// 默认的配置
	us := &UserSetting{
		Uid:                 id,
		EmailSetting:        syscfg.Ra.EmailSettings,
		NotificationSetting: syscfg.Ra.NotificationSettings,
	}
	if _, ok := t.Insert(us); !ok {
		return id, false
	}

	return id, ok
}
Esempio n. 2
0
func NewValidByEmail(t *Transaction, uid int64, email string) bool {
	if uid <= 0 {
		return false
	}

	m := &ActiveData{
		UId:            uid,
		ExpireTime:     time.Now().Unix() + 60*60*24,
		ActiveCode:     gokits.NewRandWithPrefix(email, 8),
		AcitveTypeCode: "VALID_EMAIL",
	}

	_, ok := t.Insert(m)
	// TODO 发送验证邮件
	return ok
}