public async Task <IActionResult> OnPostAsync([FromBody] UserRegDto dto) { if (!ModelState.IsValid) { return(await Task.FromResult(new JsonResult(new { Status = false, ErrorMessage = ModelState.Where(e => e.Value.Errors.Count > 0).Select(e => e.Value.Errors.First().ErrorMessage).First() }))); } var userId = _accountContext.UserId; var command = new RegCommand(dto.Email, dto.Password); await _bus.SendCommand(command); if (_notifications.HasNotifications()) { var errorMessage = string.Join(";", _notifications.GetNotifications().Select(x => x.Content)); return(await Task.FromResult(new JsonResult(new { status = false, errorMessage }))); } return(await Task.FromResult(new JsonResult(new { status = true }))); }
public async Task <IActionResult> OnPostAsync([FromBody] UserRegDto dto) { var userId = _accountContext.UserId; var command = new RegCommand(dto.Email, dto.Password, dto.Code); await _bus.SendCommand(command); if (_notifications.HasNotifications()) { var errorMessage = string.Join(";", _notifications.GetNotifications().Select(x => x.Content)); return(await Task.FromResult(new JsonResult(new { status = false, errorMessage }))); } return(await Task.FromResult(new JsonResult(new { status = true }))); }
public async Task <Unit> Handle(RegCommand command, CancellationToken cancellationToken) { var email = command.Email.Trim().ToLower(); var password = command.Password; var code = command.Code; var user = await _userDomainService.Get(p => p.Email == email && p.HasVerifiedEmail); if (user != null) { await _bus.RaiseEvent(new DomainNotification("邮箱已被注册,请更改!")); return(Unit.Value); } string key = string.Format(RedisKey.RegEmail, email);// $"regemail_{email}"; long ttl = await _redisDb.KeyTimeToLive(key); if (ttl < 0) { await _bus.RaiseEvent(new DomainNotification($"注册验证码已超时,请重试")); return(Unit.Value); } string emailCode = await _redisDb.StringGet <string>(key); if (string.Compare(emailCode, code, true) != 0) { await _bus.RaiseEvent(new DomainNotification($"注册验证码已失效,请重试")); return(Unit.Value); } string ip = _httpAccessor.HttpContext.GetUserIp(); user = new UserEntity { Email = email, LastDate = DateTime.Now, Password = password.ToMd5(), Status = UserStatusEnum.正常, RegDate = DateTime.Now, UserName = "", RegIp = ip, LastIp = ip, HasVerifiedEmail = true }; await _userDomainService.Add(user); var jwtAccount = new JwtAccount { UserId = user.Id, Email = user.Email }; await _httpAccessor.HttpContext.SignIn("user", jwtAccount); await _redisDb.KeyDelete(key); if (await Commit()) { await _bus.RaiseEvent(new SignUpEvent(user)).ConfigureAwait(false); } return(Unit.Value); }
public AdminServerModule(RegCommand reg, UnRegCommand unRegCommand) { _regCmd = reg; _unRegCommand = unRegCommand; }
public void RegisterCommand(char symbol, Action <IVirtualMachine> execute) { RegCommand.Add(symbol, execute); }