用户注册 @param email string 邮箱 @param username string 用户名 @param password string 密码 @param repassword string 确认密码 @param intro string 签名 @return
(email, username, password, repassword, intro string)
| 121 | //@return error 错误 |
| 122 | //@return int 注册成功时返回注册id |
| 123 | func (u *User) Reg(email, username, password, repassword, intro string) (error, int) { |
| 124 | var ( |
| 125 | user User |
| 126 | o = orm.NewOrm() |
| 127 | now = time.Now().Unix() |
| 128 | ) |
| 129 | |
| 130 | l := strings.Count(username, "") - 1 |
| 131 | if l < 2 || l > 16 { |
| 132 | return errors.New("用户名长度限制在2-16个字符"), 0 |
| 133 | } |
| 134 | if o.QueryTable(GetTableUser()).Filter("Username", username).One(&user); user.Id > 0 { |
| 135 | return errors.New("用户名已被注册,请更换新的用户名"), 0 |
| 136 | } |
| 137 | if o.QueryTable(GetTableUser()).Filter("Email", email).One(&user); user.Id > 0 { |
| 138 | return errors.New("邮箱已被注册,请更换新注册邮箱"), 0 |
| 139 | } |
| 140 | pwd := helper.MD5Crypt(password) |
| 141 | if pwd != helper.MD5Crypt(repassword) { |
| 142 | return errors.New("密码和确认密码不一致"), 0 |
| 143 | } |
| 144 | user = User{Email: email, Username: username, Password: pwd, Intro: intro} |
| 145 | _, err := o.Insert(&user) |
| 146 | if user.Id > 0 { |
| 147 | //coin := beego.AppConfig.DefaultInt("coinreg", 10) |
| 148 | coin := NewSys().GetByField("CoinReg").CoinReg |
| 149 | var userinfo = UserInfo{Id: user.Id, Status: true, Coin: coin, TimeCreate: int(now)} |
| 150 | _, err = o.Insert(&userinfo) |
| 151 | } |
| 152 | return err, user.Id |
| 153 | } |
| 154 | |
| 155 | //获取除了用户密码之外的用户全部信息 |
| 156 | //@param id 用户id |
nothing calls this directly
no test coverage detected