public void DeactivateCodesByType(User user, ConfirmationCodeType type) { var codes = _confirmationCodeManager.GetConfirmationCodesByUserId(user.UserId); foreach (var code in codes) { if (code.Type == type) { code.IsActive = false; } } }
public void SendConfirmation(string emailValue, ConfirmationCodeType type) { var code = _codeGenerator.GenerateCode(type); var email = _emailManager.GetEmailByValue(emailValue); if (email == null) { throw new EmailNotFoundException(emailValue); } _codeManager.SaveCode(code, email); _notificationTransportService.SendNotification("", ""); }
public ConfirmationCode GenerateCode(ConfirmationCodeType type) { const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; var generator = new Generator(); var value = generator.GenerateString(chars); var experationDate = DateTime.Now.AddHours(12); var confirmationCode = new ConfirmationCode(); confirmationCode.ExpirationDate = experationDate; confirmationCode.Value = value; confirmationCode.IsActive = true; confirmationCode.Type = type; return(confirmationCode); }
public bool TryAcceptConfirmation(string codeValue, ConfirmationCodeType type) { try { _confirmationCodeService.ValidateCode(codeValue, type); } catch (Exception ex) when(ex is CodeIsNotActiveException || ex is CodeIsNotExistException || ex is CodeExpirationDateIsUpException) { return(false); } var user = _confirmationCodeService.GetRelatedUser(codeValue); var emailValue = _confirmationCodeService.GetCodeByValue(codeValue).Email.Value; user.Emails.Find(e => e.Value == emailValue).IsConfirmed = true; _confirmationCodeService.DeactivateCode(codeValue); return(true); }
public void ValidateCode(ConfirmationCode code, ConfirmationCodeType type) { if (code == null) { throw new CodeIsNotExistException("Code is not exist"); } if (!code.IsActive) { throw new CodeIsNotActiveException("Code is not active."); } if (DateTime.Now.Subtract(code.ExpirationDate.DateTime).Seconds > 0) { throw new CodeExpirationDateIsUpException("Code's Experation Date is up."); } if (type != code.Type) { throw new CodeHasWrongTypeException(code.Value); } }
public void SendConfirmation(string emailValue, ConfirmationCodeType type) { var code = _codeGenerator.GenerateCode(type); var email = _emailManager.GetEmailByValue(emailValue); if (email == null) { throw new EmailNotFoundException(emailValue); } string linkType; _codeManager.SaveCode(code, email); if (type == ConfirmationCodeType.EmailChange) { linkType = "/email-change/"; } else if (type == ConfirmationCodeType.EmailChangeConfirmation) { linkType = "/email-change-confirm/"; } else if (type == ConfirmationCodeType.EmailConfirmation) { linkType = "/email-confirm/"; } else { linkType = "/password-recover/"; } var linkWithCode = clientUrl + linkType + code.Value; _notificationTransportService.SendNotification(emailValue, linkWithCode); }
public void ValidateCode(string codeValue, ConfirmationCodeType type) { var code = _confirmationCodeManager.GetConfirmationCodeByValue(codeValue); _codeValidationRule.ValidateCode(code, type); }