public async Task <string> Handle(CreatePasswordResetCommand request, CancellationToken cancellationToken) { var user = await _userRepository.GetAsync(x => x.Email.ToLowerInvariant() == request.Email.ToLowerInvariant()); var passwordResetEntity = new PasswordResetEntity { CreatedDate = DateTime.UtcNow, ExpirationDate = DateTime.UtcNow.AddMinutes(30), Id = Guid.NewGuid().ToString(), UserId = user.Id }; await _passwordResetRepository.CreatePasswordResetAsync(passwordResetEntity, cancellationToken); // Send E-Mail But Don't Directly, Send a PasswordResetEntityCreated Event return(passwordResetEntity.Id); }
public async Task CreateOrUpdateIdentifierAsync(string customerId, string identifier, TimeSpan identifierTimeSpan) { var entity = PasswordResetEntity.Create(customerId, identifier, identifierTimeSpan); using (var context = _contextFactory.CreateDataContext()) { await context.AddAsync(entity); try { await context.SaveChangesAsync(); } catch (DbUpdateException e) { if (e.InnerException is SqlException sqlException && sqlException.Number == PrimaryKeyViolationErrorCode) { context.PasswordReset.Update(entity); await context.SaveChangesAsync(); }
public IHttpActionResult ResetPassword(string id, [FromBody] PasswordResetEntity content) { if (!string.IsNullOrWhiteSpace(content.Secret)) { if (!uint.TryParse(id, out var userId)) { return(this.BadRequest("Invalid id argument, it must be a integer.")); } if (!this.UserProvider.ResetPassword(userId, content.Secret, content.Password)) { return(this.NotFound()); } } else if (content.PasswordAnswers != null && content.PasswordAnswers.Length > 0) { var userId = Utility.ResolvePattern(id, out var identity, out var @namespace, out var suffix); //注意:该方法会将传入的纯数字的标识当做手机号处理 if (userId > 0) { identity = userId.ToString(); } if (!this.UserProvider.ResetPassword(identity, @namespace, content.PasswordAnswers, content.Password)) { return(this.NotFound()); } } else { return(this.BadRequest()); } return(this.Ok()); }
public Task CreatePasswordResetAsync(PasswordResetEntity passwordResetEntity, CancellationToken cancellationToken = default) { return(_mongoCollection.InsertOneAsync(passwordResetEntity, cancellationToken: cancellationToken)); }