添加用户.
()
| 163 | |
| 164 | // 添加用户. |
| 165 | func (this *ManagerController) CreateMember() { |
| 166 | |
| 167 | account := strings.TrimSpace(this.GetString("account")) |
| 168 | nickname := strings.TrimSpace(this.GetString("nickname")) |
| 169 | password1 := strings.TrimSpace(this.GetString("password1")) |
| 170 | password2 := strings.TrimSpace(this.GetString("password2")) |
| 171 | email := strings.TrimSpace(this.GetString("email")) |
| 172 | phone := strings.TrimSpace(this.GetString("phone")) |
| 173 | role, _ := this.GetInt("role", 1) |
| 174 | //status, _ := this.GetInt("status", 0) |
| 175 | |
| 176 | if ok, err := regexp.MatchString(conf.RegexpAccount, account); account == "" || !ok || err != nil { |
| 177 | this.JsonResult(6001, "账号只能由英文字母数字组成,且在3-50个字符") |
| 178 | } |
| 179 | if l := strings.Count(nickname, "") - 1; l < 2 || l > 20 { |
| 180 | this.JsonResult(6001, "昵称限制在2-20个字符") |
| 181 | } |
| 182 | if l := strings.Count(password1, ""); password1 == "" || l > 50 || l < 6 { |
| 183 | this.JsonResult(6002, "密码必须在6-50个字符之间") |
| 184 | } |
| 185 | if password1 != password2 { |
| 186 | this.JsonResult(6003, "确认密码不正确") |
| 187 | } |
| 188 | if ok, err := regexp.MatchString(conf.RegexpEmail, email); !ok || err != nil || email == "" { |
| 189 | this.JsonResult(6004, "邮箱格式不正确") |
| 190 | } |
| 191 | if role != 0 && role != 1 && role != 2 { |
| 192 | role = 1 |
| 193 | } |
| 194 | |
| 195 | member := models.NewMember() |
| 196 | |
| 197 | if _, err := member.FindByAccount(account); err == nil && member.MemberId > 0 { |
| 198 | this.JsonResult(6005, "账号已存在") |
| 199 | } |
| 200 | |
| 201 | member.Account = account |
| 202 | member.Password = password1 |
| 203 | member.Role = role |
| 204 | member.Avatar = conf.GetDefaultAvatar() |
| 205 | member.CreateAt = this.Member.MemberId |
| 206 | member.Email = email |
| 207 | member.Nickname = nickname |
| 208 | if phone != "" { |
| 209 | member.Phone = phone |
| 210 | } |
| 211 | |
| 212 | if err := member.Add(); err != nil { |
| 213 | beego.Error(err.Error()) |
| 214 | this.JsonResult(6006, "注册失败,可能昵称已存在") |
| 215 | } |
| 216 | |
| 217 | this.JsonResult(0, "ok", member) |
| 218 | } |
| 219 | |
| 220 | // 更新用户状态. |
| 221 | func (this *ManagerController) UpdateMemberStatus() { |
nothing calls this directly
no test coverage detected