public async Task <IHttpActionResult> ValidateRegister(UserInfoRegistDto dto, string validateCode) { dto.PhoneNo = dto.UserName; var result = await UserContract.ValidateRegister(dto, validateCode); return(Json(result.ToApiResult())); }
/// <summary> /// 验证用户注册 /// </summary> /// <param name="dto">用户注册信息</param> /// <param name="validateCode">验证码</param> /// <returns>业务操作结果</returns> public async Task <OperationResult> ValidateRegister(UserInfoRegistDto dto, string validateCode) { dto.CheckNotNull("dto"); validateCode.CheckNotNullOrEmpty("validateCode"); //验证码 var severCode = GetValidateCode(dto.UserName, CodeType.用户注册); if (severCode == null || severCode.Code != validateCode) { return(new OperationResult(OperationResultType.ValidError, "验证码错误", 0)); } if (SysUserRepo.CheckExists(p => p.UserName == dto.UserName)) { return(new OperationResult(OperationResultType.ValidError, "账号已被使用", 0)); } try { UserInfoRepo.UnitOfWork.TransactionEnabled = true; //验证密码格式 IdentityResult result = await UserManager.PasswordValidator.ValidateAsync(dto.Password); if (!result.Succeeded) { return(result.ToOperationResult()); } SysUser sUser = new SysUser() { UserName = dto.UserName, NickName = dto.NickName, PasswordHash = UserManager.PasswordHasher.HashPassword(dto.Password),//密码加密 UserType = UserType.App用户 }; if (severCode.ValidateType == ValidateType.手机) { sUser.PhoneNumber = dto.UserName; sUser.PhoneNumberConfirmed = true; } else { sUser.Email = dto.UserName; sUser.EmailConfirmed = true; } await UserManager.CreateAsync(sUser); var userInfo = Mapper.Map <UserInfo>(dto); userInfo.SysUser = sUser; await UserInfoRepo.InsertAsync(userInfo); await UserInfoRepo.UnitOfWork.SaveChangesAsync(); return(new OperationResult(OperationResultType.Success, "注册成功", userInfo.Id)); } catch { return(new OperationResult(OperationResultType.NoChanged, "注册失败", 0)); } }
public async Task <IHttpActionResult> ValidateRegister(string phoneNo, string password, string validateCode, LoginDevice loginDevice, string clientVersion, string email, string registKey = "") { var dto = new UserInfoRegistDto() { UserName = phoneNo, Password = password, NickName = "xbxd" + phoneNo, Email = email, }; var result = await UserContract.ValidateRegister(dto, validateCode); if (result.Successed) { return(Json((await UserContract.Login(phoneNo, password, registKey, loginDevice, clientVersion, 1)).ToApiResult())); } return(Json(result.ToApiResult())); }
public async Task <ActionResult> ValidateRegister(FormCollection values) { if (ModelState.IsValid) { var dto = new UserInfoRegistDto { UserName = values["phoneNo"], Password = values["password"], NickName = values["phoneNo"] }; var result = await UserContract.ValidateRegister(dto, values["validateCode"]); if (result.Successed) { FormsAuthentication.SetAuthCookie(result.Data.ToJsonString(), false); } return(Json(result.ToApiResult())); } return(Json(new { ReturnCode = 2, ReturnMsg = "图片验证码有误" })); }