Esempio n. 1
0
        public bool Authenticate(string clientId, string clientSecret, string reqOrigin, out string message, out ApplicationStore applicationStore)
        {
            message          = string.Empty;
            applicationStore = null;

            if (string.IsNullOrWhiteSpace(clientId))
            {
                message = "ClientId should be sent.";
            }
            else
            {
                Guid clientCode;
                if (Guid.TryParse(clientId, out clientCode))
                {
                    if (!clientSecret.IsNullOrWhiteSpace())
                    {
                        applicationStore = applicationStoreRepository.Get(ClientAuthType.Confidential, clientCode);
                    }
                    else
                    {
                        applicationStore = applicationStoreRepository.Get(ClientAuthType.JavaScript, clientCode);
                    }


                    if (applicationStore == null)
                    {
                        message = string.Format("Client '{0}' not found.", clientId);
                    }
                    else
                    {
                        if (!applicationStore.Status)
                        {
                            message = string.Format("Client '{0}' is inactive.", clientId);
                        }
                        else
                        {
                            return(applicationStore.IsValidCall(clientSecret, reqOrigin));
                        }
                    }
                }
                else
                {
                    message = string.Format("Client '{0}' not found.", clientId);
                }
            }

            return(false);
        }
Esempio n. 2
0
        public IEnumerable <DTO.ApplicationStore> ConnectApplications(DTO.Store store)
        {
            var applicationStoreCollection = new List <DTO.ApplicationStore>();

            var _store = storeRepository.Get(store.Code);

            if (_store.IsNull())
            {
                throw new ArgumentException("Ops! Esta loja não possui cadastro. :(");
            }

            using (var transaction = Connection.BeginTransaction())
            {
                try
                {
                    store.Applications.ForEach(application =>
                    {
                        var _application = applicationRepository.Get(application.ApplicationName);

                        if (_application.IsNull())
                        {
                            throw new ArgumentException("Ops! A aplicação '{0}' não existe. :(".ToFormat(application.ApplicationName));
                        }

                        var applicationStore = applicationStoreRepository.Get(_application.Code.Value, _store.Code);

                        if (applicationStore.IsNull())
                        {
                            applicationStoreCollection.Add(new DTO.ApplicationStore(applicationStoreService.Save(_application, _store, application.AllowedOrigins)));
                        }
                        else
                        {
                            if (!applicationStore.Status)
                            {
                                applicationStore.Status = true;
                                applicationStoreRepository.Update(applicationStore);
                            }

                            applicationStoreCollection.Add(new DTO.ApplicationStore(applicationStore));
                        }
                    });

                    transaction.Commit();
                }
                catch
                {
                    if (!transaction.IsNull())
                    {
                        transaction.Rollback();
                    }

                    throw;
                }
            }

            return(applicationStoreCollection);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public void ChangeMemberPassword(Guid memberCode, string password, string newPassword, Guid?appStoreCode = null)
        {
            using (var transaction = Connection.BeginTransaction())
            {
                try
                {
                    accountService.lockedUpMemberPolicy = lockedUpMemberPolicy;
                    accountService.lockMemberPolicy     = lockMemberPolicy;
                    accountService.passwordPolicy       = passwordPolicy;

                    var account = accountRepository.Get(memberCode);
                    accountService.Authenticate(account, null, password);

                    account.SetPassword(newPassword, passwordPolicy);

                    accountService.Update(account);

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

            if (appStoreCode.HasValue && !appStoreCode.Value.IsEmpty())
            {
                using (var transaction = Connection.BeginTransaction())
                {
                    try
                    {
                        var appStore = applicationStoreRepository.Get(appStoreCode.Value);

                        passwordLogRepository.Save(new PasswordLog(memberCode, PasswordEventLog.Change, appStore.Store.Code));
                        transaction.Commit();
                    }
                    catch
                    {
                        transaction.Rollback();
                    }
                }
            }
        }
Esempio n. 5
0
        private Account CreateConnect(IEnumerable <Account> accounts, ApplicationStore applicationStore, string password = "", bool isSave = false)
        {
            Account account = null;

            if (!accounts.IsNull() && accounts.Count() > 0)
            {
                for (int i = 0; i < accounts.Count(); i++)
                {
                    account = accounts.ElementAt(i);

                    if ((!password.IsNullOrWhiteSpace() && account.Password.Equals(password.Encrypt())) ||
                        (password.IsNullOrWhiteSpace() && applicationStore.Application.MemberType == Domain.Enums.MemberType.Consumer &&
                         (!account.Document.IsNullOrWhiteSpace() || !account.Customer.IsNull())))
                    {
                        //connect account to store
                        var role = roleRepository.GetByApplication(applicationStore.ApplicationCode, applicationStore.StoreCode);
                        if (!role.IsNull())
                        {
                            account.ConnectRole(role);
                        }

                        //connect account to store
                        var app = applicationStoreRepository.Get(applicationStore.Code);
                        account.ConnectApp(app);

                        break;
                    }
                    else if (account.AccountApplicationStoreCollection.Any(appSto => appSto.ApplicationStore.Application != null && appSto.ApplicationStore.Application.MemberType == MemberType.Merchant) && isSave)
                    {
                        throw new ArgumentException("E-mail já cadastrado");
                    }
                    else
                    {
                        account = null;
                    }
                }
            }

            return(account);
        }
Esempio n. 6
0
 public ApplicationStore Get(Guid code)
 {
     return(applicationStoreRepository.Get(code));
 }
Esempio n. 7
0
        public bool SaveAccount(Requisition requisition, Object account, ApplicationStore applicationStore, IConnection conn)
        {
            var acc = (DTO.Account)account;

            // Set Connection
            accountService.GetRepositories().ForEach(r => r.Connection        = conn);
            customerImportService.GetRepositories().ForEach(r => r.Connection = conn);

            var messageError = string.Empty;
            var isValid      = true;

            try
            {
                var accountDO = accountService.Get(acc.Email, acc.Document, applicationStore, true);

                if (accountDO.IsNull())
                {
                    var _account = acc.Transfer();

                    _account.AccountApplicationStoreCollection = new List <AccountApplicationStore>()
                    {
                        new AccountApplicationStore(_account.Code, applicationStoreRepository.Get(applicationStore.Code).Code)
                    };

                    var role = roleRepository.GetByApplication(applicationStore.ApplicationCode, applicationStore.StoreCode);
                    if (!role.IsNull())
                    {
                        _account.ConnectRole(role);
                    }

                    accountService.Add(_account, applicationStore, requisition.Store.Code);

                    if (!_account.Customer.IsNull() && !_account.Customer.Email.IsNullOrWhiteSpace())
                    {
                        customerImportService.RemoveMember(_account.Email, _account.Document);
                    }
                }
                else
                {
                    isValid      = false;
                    messageError = "Usuário já cadastrado";
                }
            }
            catch (Exception ex)
            {
                isValid = false;

                if (!ex.InnerException.IsNull() && !ex.InnerException.Message.IsNullorEmpty())
                {
                    messageError = ex.InnerException.Message;
                }
                else
                {
                    messageError = ex.Message;
                }
            }

            if (!isValid)
            {
                requisition.RequisitionErrors.Add(new RequisitionError()
                {
                    Email         = acc.Login,
                    Name          = acc.Customer.Name,
                    Line          = 0,
                    ErrorMessages = new List <string>()
                    {
                        messageError
                    }
                });
            }

            return(isValid);
        }