Exemple #1
0
        public IHttpActionResult ResetAccountSMS(DTO.AccountInput account)
        {
            try
            {
                base.SetRequestInfo();

                accountApp.ResetAccount(account, base.AccountCode);
                return(Ok());
            }
            catch (LockedUpMemberException)
            {
                return(BadRequest("locked_member"));
            }
            catch (PasswordException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #2
0
        public DTO.ResetSMSToken GetTokenSMS(DTO.AccountInput accountInput, Guid clientId)
        {
            Account       account = null;
            ResetSMSToken token   = null;

            var applicationStore = applicationStoreRepository.GetByClientId(clientId);

            if (accountInput.Document.IsValidCNPJ() || accountInput.Document.IsValidCPF())
            {
                account = accountService.Get(accountInput.Document, applicationStore);
            }

            else if (accountInput.Email.IsValidEmail())
            {
                account = accountService.Get(accountInput.Email, applicationStore);
            }

            if (account.IsNull())
            {
                throw new ArgumentException("Cliente não encontrado");
            }
            else
            {
                if (!account.IsNull() && !account.Customer.IsNull())
                {
                    account.Customer.HandlerToGet();
                }
                else
                {
                    throw new ArgumentException("Não foram encontrados os dados de consumidor do cliente");
                }

                using (var transaction = Connection.BeginTransaction())
                {
                    try
                    {
                        token = smsTokenService.Generate(account.Customer, applicationStore, accountInput.UrlBack);
                        transaction.Commit();
                    }
                    catch (Exception)
                    {
                        transaction.Rollback();
                        throw;
                    }
                }
            }

            return(new DTO.ResetSMSToken(token));
        }
Exemple #3
0
 public IHttpActionResult IsMemberExistsByType(DTO.AccountInput param)
 {
     try
     {
         return(Ok((object)accountApp.IsMemberExists(param)));
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(ex));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Exemple #4
0
        public IHttpActionResult SendPasswordEmail(DTO.AccountInput input)
        {
            try
            {
                DTO.ApplicationStore appStore = null;
                Guid?confId = null;
                if (base.IsMainAdmin)
                {
                    appStore = appStoreApp.GetApplicationStoreByStoreTypeMain("Hagrid-UI-Login");
                    if (!appStore.IsNull())
                    {
                        confId = appStore.ConfidentialClient;
                    }
                }
                else
                {
                    confId = base.ClientId;
                }

                if (!confId.HasValue)
                {
                    throw new ArgumentException("Aplicação não encontrada");
                }

                resetPasswordTokenApp.GenerateResetPasswordToken(input.Email, confId.Value);

                return(Ok());
            }
            catch (LockedUpMemberException ex)
            {
                return(BadRequest(new ArgumentException(ex.Message)));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #5
0
        public void ResetAccount(DTO.AccountInput input, Guid currentAccount)
        {
            var registeredAccount = accountService.GetIfHasPermissionToUpdate(currentAccount, currentAccount);

            if (registeredAccount.IsNull())
            {
                throw new ArgumentException("A conta informada não foi encontrada");
            }

            if (!input.EmailNew.IsValidEmail())
            {
                throw new ArgumentException("O e-mail informado não é válido");
            }

            if (input.EmailNew.IsNullorEmpty())
            {
                throw new ArgumentException("O e-mail não foi informado");
            }

            if (input.PasswordNew.IsNullorEmpty())
            {
                throw new ArgumentException("A senha não foi informada");
            }

            using (var transaction = Connection.BeginTransaction())
            {
                try
                {
                    registeredAccount.SetPassword(input.PasswordNew, passwordPolicy);
                    accountService.UpdateAccountInfo(registeredAccount, email: input.EmailNew);
                }
                catch
                {
                    transaction.Rollback();

                    throw;
                }
            }
        }
Exemple #6
0
        public void ChangeAccountInfo(DTO.AccountInput input, Guid currentAccount)
        {
            var registeredAccount = accountService.GetIfHasPermissionToUpdate(currentAccount, input.Code);

            if (registeredAccount.IsNull())
            {
                throw new ArgumentException("A conta informada não foi encontrada");
            }

            if (!input.Email.IsNullOrWhiteSpace() && registeredAccount.Email != input.Email)
            {
                throw new ArgumentException("O e-mail informado é diferente do e-mail registrado");
            }

            if (!input.DocumentNew.IsNullOrWhiteSpace() && registeredAccount.Document == input.DocumentNew)
            {
                throw new ArgumentException("O documento informado é igual o documento registrado");
            }

            if (input.BirthdateNew.HasValue && input.BirthdateNew.Value < System.Data.SqlTypes.SqlDateTime.MinValue.AsDateTime())
            {
                throw new ArgumentException("Data de nascimento inválida");
            }

            using (var transaction = Connection.BeginTransaction())
            {
                try
                {
                    accountService.UpdateAccountInfo(registeredAccount, input.EmailNew, input.DocumentNew, input.BirthdateNew);
                }
                catch
                {
                    transaction.Rollback();

                    throw;
                }
            }
        }
Exemple #7
0
        public IHttpActionResult GetTokenSMS(AccountInput param)
        {
            try
            {
                var account = new DTO.AccountInput()
                {
                    Email    = param.email,
                    Document = param.document,
                    UrlBack  = param.url_back
                };

                var token = accountApp.GetTokenSMS(account, base.ClientId);
                return(Ok(token));
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #8
0
 public IHttpActionResult ValidatePassword(DTO.AccountInput param)
 {
     try
     {
         return(Ok(accountApp.ValidatePassword(base.AccountCode, param.Password)));
     }
     catch (LockedUpMemberException ex)
     {
         return(BadRequest(new ArgumentException(ex.Message)));
     }
     catch (PasswordException ex)
     {
         return(BadRequest(new ArgumentException(ex.Message)));
     }
     catch (ArgumentException ex)
     {
         return(BadRequest(ex));
     }
     catch (Exception ex)
     {
         return(InternalServerError(ex));
     }
 }
Exemple #9
0
        public IHttpActionResult ChangeAccountInfo(DTO.AccountInput input)
        {
            try
            {
                if (!base.IsMainAdmin)
                {
                    throw new ArgumentException("Não tem permissão para executar esse método");
                }

                base.SetRequestInfo();

                accountApp.ChangeAccountInfo(input, base.AccountCode);

                return(Ok());
            }
            catch (ArgumentException ex)
            {
                return(BadRequest(ex));
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }
Exemple #10
0
        public bool IsMemberExists(DTO.AccountInput account)
        {
            var _account = account.Convert();

            return(accountService.IsMemberExists(_account));
        }