예제 #1
0
        public void Add(Account account, ApplicationStore applicationStore, Guid originStore, bool simplifiedCustomer = false)
        {
            if (applicationStore.IsNull())
            {
                throw new ArgumentException("Applicação inválida");
            }

            account.IsValid(simplifiedCustomer);

            account.SetPassword(account.Password, passwordPolicy);

            if (simplifiedCustomer || !account.Customer.IsNull())
            {
                var customer = account.Customer;
                customer.Password = account.Password;
                customer.Account  = account;

                if (!simplifiedCustomer && !account.Document.IsNullorEmpty())
                {
                    customerService.PrepareToAdd(customer, originStore);
                }
                else
                {
                    customerService.PrepareToAddSimplified(customer);
                }
            }

            account.SaveDate   = DateTime.Now;
            account.UpdateDate = DateTime.Now;

            var _account = accountRepository.Save(account);

            if (!account.CodeEmailTemplate.IsNull())
            {
                var resetPasswordTokenService = resetPasswordTokenFactory.GetResetPasswordTokenService(_account);
                SetConnection(resetPasswordTokenService);

                resetPasswordTokenService.lockedUpMemberPolicy = lockedUpMemberPolicy;

                var token = resetPasswordTokenService.GenerateResetPasswordToken(_account, applicationStore, "");

                var _tokenCode = token.Code.EncodeURIComponent();

                svcEmail.SendEmailUserCreatedByAccountAdminAsync(_account, _tokenCode, "");
            }
        }
예제 #2
0
        public override string GenerateResetPasswordToken(string email, Guid clientId, string urlBack = "", int emailTemplateCode = 0)
        {
            if (email.IsNullOrWhiteSpace())
            {
                throw new ArgumentException("E-mail não informado");
            }

            ApplicationStore appSto;
            Account          account;
            CustomerImport   customerImport = null;
            string           _tokenCode     = string.Empty;

            using (var transaction = Connection.BeginTransaction())
            {
                try
                {
                    appSto = applicationStoreRepository.GetByClientId(clientId);
                    var accounts = accountRepository.Get(email, appSto, true);

                    accountService.lockedUpMemberPolicy = lockedUpMemberPolicy;
                    accountService.lockMemberPolicy     = lockMemberPolicy;
                    accountService.passwordPolicy       = passwordPolicy;

                    account = accountService.Authenticate(accounts, appSto, false);

                    if (account != null)
                    {
                        var resetPasswordTokenService = resetPasswordTokenFactory.GetResetPasswordTokenService(account);

                        resetPasswordTokenService.lockedUpMemberPolicy = lockedUpMemberPolicy;

                        var token = resetPasswordTokenService.GenerateResetPasswordToken(account, appSto, urlBack);

                        _tokenCode = token.Code.EncodeURIComponent();

                        svcEmail.SendPasswordRecoveryEmailAsync(account, appSto.Store, _tokenCode, token.UrlBack, emailTemplateCode);
                    }
                    else
                    {
                        customerImport = customerImportService.Get(email, appSto.Store.Code);

                        if (customerImport != null)
                        {
                            var resetPasswordTokenService = resetPasswordTokenFactory.GetResetPasswordTokenService(customerImport);

                            var token = resetPasswordTokenService.GenerateResetPasswordToken(customerImport, appSto, urlBack);

                            _tokenCode = token.Code.EncodeURIComponent();

                            customerImport.HandleCustomer();
                            svcEmail.SendPasswordRecoveryEmailAsync(customerImport, appSto.Store, _tokenCode, urlBack, emailTemplateCode);
                        }
                    }

                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }

            if (!appSto.IsNull() && (!account.IsNull() || !customerImport.IsNull()))
            {
                using (var transaction = Connection.BeginTransaction())
                {
                    try
                    {
                        var code = !account.IsNull() ? account.Code : customerImport.AccountCode;

                        passwordLogRepository.Save(new PasswordLog(code, PasswordEventLog.RequestRecovery, appSto.Store.Code));

                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                    }
                }
            }

            return(_tokenCode);
        }