示例#1
0
        public SellerView PersistLogin()
        {
            SellerView seller;

            string sessionValue = session.GetString(sellerSessionKeyWord);

            if (sessionValue != null)
            {
                seller = eCommerce.GetSellerBy(int.Parse(sessionValue));
                if (seller != null)
                {
                    if (seller.Status != SellerStatus.Locked)
                    {
                        return(seller);
                    }
                }
                session.Remove(sellerSessionKeyWord);
                return(null);
            }

            LoginCookies loginCookies = requestCookies.GetJson <LoginCookies>(sellerCookieKeyWord);

            if (loginCookies == null)
            {
                return(null);
            }

            seller = eCommerce.GetSellerBy(loginCookies.UserId);
            if (seller == null)
            {
                responseCookies.Delete(sellerCookieKeyWord);
                return(null);
            }

            if (seller.Status == SellerStatus.Locked)
            {
                responseCookies.Delete(sellerCookieKeyWord);
                return(null);
            }

            string loginValue = EncryptionService.Encrypt(seller.Email +
                                                          eCommerce.GetSellerEncryptedPassword(int.Parse(seller.Id)) +
                                                          connectionInfo.RemoteIpAddress.ToString());

            if (loginCookies.LoginValue != loginValue)
            {
                responseCookies.Delete(sellerCookieKeyWord);
                return(null);
            }

            session.SetString(sellerSessionKeyWord, seller.Id);
            return(seller);
        }
示例#2
0
        public IActionResult Login(LoginViewModel loginViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(loginViewModel));
            }
            IList <string> errors = new List <string>();
            SellerView     seller = loginPersistence.PersistLogin();

            if (seller == null)
            {
                if (EmailValidationService.IsValidEmail(loginViewModel.LoginInformation.Username))
                {
                    seller = eCommerce.GetSellerBy(loginViewModel.LoginInformation.Username);
                    if (seller != null)
                    {
                        if (seller.Status == SellerStatus.Active)
                        {
                            string encryptedPassword = eCommerce.GetSellerEncryptedPassword(int.Parse(seller.Id));
                            if (EncryptionService.Encrypt(loginViewModel.LoginInformation.Password) == encryptedPassword)
                            {
                                loginPersistence.LoginThrough(loginViewModel.LoginInformation.Username, loginViewModel.LoginInformation.Remember);
                            }
                            else
                            {
                                errors.Add("Wrong password");
                            }
                        }
                        else
                        {
                            switch (seller.Status)
                            {
                            case SellerStatus.Locked: errors.Add("Account was locked"); break;

                            case SellerStatus.Validating: errors.Add("Account are waiting for validating"); break;
                            }
                        }
                    }
                    else
                    {
                        errors.Add("Email not found");
                    }
                }
                else
                {
                    errors.Add("Invalid email address");
                }
            }
            else
            {
                return(Redirect(loginViewModel.ReturnUrl));
            }

            if (errors.Any())
            {
                ViewData[GlobalViewBagKeys.Errors] = errors;
                return(View(loginViewModel));
            }
            return(Redirect(loginViewModel.ReturnUrl));
        }