public override string GenerateResetPasswordToken(string email, Guid storeCode, string urlBack = "", int emailTemplateCode = 0) { ApplicationStore appSto; CustomerImport customerImport; string _tokenCode = string.Empty; using (var transaction = Connection.BeginTransaction()) { try { var application = applicationRepository.Get("EC-Loja", true); appSto = applicationStoreRepository.Get(application.Code.Value, storeCode, true); customerImport = customerImportService.Get(email, storeCode); if (customerImport != null) { var token = resetPasswordTokenService.GenerateResetPasswordToken(customerImport, appSto, urlBack); _tokenCode = token.Code.EncodeURIComponent(); customerImport.HandleCustomer(); svcEmail.SendPasswordRecoveryEmailAsync(customerImport, appSto.Store, _tokenCode, token.UrlBack, emailTemplateCode); } transaction.Commit(); } catch { transaction.Rollback(); throw; } } if (!appSto.IsNull() && !customerImport.IsNull()) { using (var transaction = Connection.BeginTransaction()) { try { passwordLogRepository.Save(new PasswordLog(customerImport.AccountCode, PasswordEventLog.ResquetRecoryCustomerImport, appSto.Store.Code)); transaction.Commit(); } catch { transaction.Rollback(); } } } return(_tokenCode); }
public Account Authenticate(string login, string password, ApplicationStore applicationStore, out bool requirePasswordChange, string urlBack = "") { requirePasswordChange = false; Account account = null; using (var transaction = Connection.BeginTransaction()) { var accounts = accountRepository.Get(login, applicationStore, true); if (accounts.Count() > 0) { var matchedAccounts = accountService.MatchPassword(accounts.ToList(), password); if (matchedAccounts.IsNull() || matchedAccounts.Count() == 0) { if (applicationStore.Application.MemberType == MemberType.Consumer) { if (accounts.Any(a => !a.Customer.IsNull() && a.Customer.Code.IsEmpty())) { accounts.ForEach(a => a.WrongLoginAttempt(lockedUpMemberPolicy, lockMemberPolicy)); } } else { var _accounts = accounts.Where(a => a.AccountRoles.Any(ar => ar.Role.Status == true && ar.Role.Store.Status == true && ar.Role.StoreCode == applicationStore.StoreCode && ar.Role.Permissions.Any(p => p.Status == true && p.Resource.Application.Status == true && p.Resource.ApplicationCode == applicationStore.ApplicationCode))); if (!_accounts.IsNull() && _accounts.Count() > 0) { _accounts.ForEach(a => a.WrongLoginAttempt(lockedUpMemberPolicy, lockMemberPolicy)); } else { accounts.ForEach(a => a.WrongLoginAttempt(lockedUpMemberPolicy, lockMemberPolicy)); } } transaction.Commit(); throw new ArgumentException("User and password not found"); } else { accountService.lockedUpMemberPolicy = lockedUpMemberPolicy; accountService.lockMemberPolicy = lockMemberPolicy; accountService.passwordPolicy = passwordPolicy; account = accountService.Authenticate(accounts, applicationStore); if (passwordPolicy != null) { requirePasswordChange = !passwordPolicy.Validate(account.Email, password, false); } transaction.Commit(); return(account); } } else { if (applicationStore.Application.MemberType == MemberType.Consumer) { var customerImport = customerImportService.Get(login, applicationStore.Store.Code); if (customerImport != null) { var token = resetPasswordTokenService.GenerateResetPasswordToken(customerImport, applicationStore, urlBack); var _tokenCode = token.Code.EncodeURIComponent(); customerImport.HandleCustomer(); svcEmail.SendPasswordRecoveryEmailAsync(customerImport, applicationStore.Store, _tokenCode, urlBack); transaction.Commit(); using (var transactionLog = Connection.BeginTransaction()) { try { passwordLogRepository.Save(new PasswordLog(customerImport.AccountCode, PasswordEventLog.ResquetRecoryCustomerImport, applicationStore.Store.Code)); transactionLog.Commit(); } catch { transactionLog.Rollback(); } } throw new ArgumentException("create_password_is_needed"); } } } } return(account); }