/// <summary> /// 自动校验 /// </summary> public PasswordPostValidator(IMemberInfosRepository memberInfoRepository) { this._IMemberInfoRepository = memberInfoRepository; RuleFor(x => x.LoginName).MustAsync(async(loginName, collback) => { return(await _IMemberInfoRepository.IsExistAsync(a => a.Uid == loginName || a.Phone == loginName)); }).WithMessage("用户不存在!"); RuleFor(x => new { x.Old, x.LoginName }).MustAsync(async(obj, collback) => { return(await _IMemberInfoRepository.IsExistAsync(a => (a.Uid == obj.LoginName || a.Phone == obj.LoginName) && a.Password == Tools.Md5(obj.Old))); }).WithMessage("原始密码有误!"); RuleFor(x => x.New).NotEmpty().WithMessage("新密码不能为空!").Matches(@"^(?!(?:[^a-zA-Z]+|\D+|[a-zA-Z0-9]+)$).{6,50}$").WithMessage("新密码必须包含字母、数字和特殊字符"); RuleFor(x => x.Affirm).NotEmpty().WithMessage("确认密码不能为空!").Must(ReEqualsNew).WithMessage("确认密码必须跟新密码一样!"); }
public async Task <IActionResult> PostMemberInfoAsync([FromHeader] String source, [FromRoute] RouteIdInt route, [FromBody] MemberInfoPost item) { var response = new Response <Object>(); try { if (await _IMemberInfoRepository.IsExistAsync(a => a.MemberId == route.id && a.IsEnable == 1)) { var entity = await _IMemberInfoRepository.FirstOrDefaultAsync(a => a.MemberId == route.id); if (!string.IsNullOrEmpty(item.NickName)) { entity.NickName = item.NickName; } if (item.Sex.HasValue) { entity.Sex = item.Sex; } if (!string.IsNullOrEmpty(item.Phone)) { entity.Phone = item.Phone; } if (!string.IsNullOrEmpty(item.Name)) { entity.Name = item.Name; } if (!string.IsNullOrEmpty(item.Alipay)) { entity.Alipay = item.Alipay; await _ITaskInfoApp.AddTasks("T0004", new TaskItem() { MemberId = entity.MemberId, InvitedId = 0, FromMark = 0 }); } //注销账号 entity.IsEnable = item.IsEnable;//注销 _IMemberInfoRepository.Update(entity); response.Code = await _IMemberInfoRepository.SaveChangesAsync() > 0; response.Message = "修改成功"; } else { return(NotFound()); } } catch (Exception ex) { response.SetError(ex, this._ILogger); } return(response.ToHttpResponse()); }
/// <summary> /// 自动验证 /// </summary> public RegisterPostValidator(IMemberInfosRepository memberInfoRepository) { this._IMemberInfoRepository = memberInfoRepository; When(x => x.type == (int)RegisterType.wechat, () => { RuleFor(a => a.uid).NotEmpty().WithMessage("请传递uid!"); RuleFor(a => a.openid).NotEmpty().WithMessage("请传递openid!"); }).Otherwise(() => { RuleFor(a => a.phone).NotEmpty().WithMessage("请传递手机号!").MustAsync(async(phone, callback) => { return(!await _IMemberInfoRepository.IsExistAsync(x => x.Phone == phone)); }).WithMessage("该手机号已经被绑定!"). Matches(@"0?(13|14|15|17|18|19)[0-9]{9}").WithMessage("手机号格式不正确!"); }); }
private async Task <bool> AlipayRepeatValidator(string alipay, CancellationToken cancellation) { return(!await _IMemberInfosRepository.IsExistAsync(b => b.Alipay == alipay)); }