Ejemplo n.º 1
0
        public ActionResult Login(LoginRequestViewModel model)
        {
            var loginResult = _userRegistrationService.ValidateUser(model.LoginName, model.Password);

            if (loginResult == Core.Domain.Users.UserLoginResults.Successful)
            {
                var user = this._userService.GetUserByLoginName(model.LoginName);
                _authenticationService.SignIn(user, model.RememberMe);

                var usermodel = new UserViewModel()
                {
                    FirstName    = user.FirstName,
                    LastName     = user.LastName,
                    Email        = user.Email,
                    IsAdmin      = user.IsAdmin,
                    Language     = user.Language,
                    LoginName    = user.LoginName,
                    Phone        = user.Phone,
                    OpenId       = user.OpenId,
                    QQ           = user.QQ,
                    Sex          = user.Sex,
                    Address      = user.Address,
                    Married      = user.Married == null ? false : user.Married.Value,
                    Education    = user.Education,
                    IdentityCard = user.IdentityCard
                };
                return(Json(ResponseMessageExt.Success("", usermodel)));
            }
            else
            {
                return(Json(ResponseMessageExt.Failed(loginResult.ToString())));
            }
        }
Ejemplo n.º 2
0
        public ActionResult Login(AccountLogin model)
        {
            User user = new User()
            {
                Username = model.UsernameOrEmail,
                Email    = model.UsernameOrEmail,
                Password = model.Password
            };

            var loginResult = _userRegistrationService.ValidateUser(model.UsernameOrEmail, model.Password);

            switch (loginResult)
            {
            case UserLoginResults.Successful:
            {
                // sign in user
                // TODO add remember me
                _authenticationService.SignIn(user, true);

                // TODO save login activity log

                // TODO redirect to return url

                return(RedirectToAction("Index", "Home"));
            }

                // TODO check other login results for login errors
            }

            return(View(model));
        }
Ejemplo n.º 3
0
        public virtual IActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                model.Email = model.Email.Trim();
                var loginResult = _userRegistrationService.ValidateUser(model.Email, model.Password);
                switch (loginResult)
                {
                case UserLoginResults.Successful:
                {
                    var customer = _userService.GetUserByUsername(model.Email);

                    //sign in new customer
                    _authenticationService.SignIn(customer, model.RememberMe);

                    if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
                    {
                        return(RedirectToAction("Index", "Home"));
                    }

                    return(Redirect(returnUrl));
                }

                case UserLoginResults.UserNotExist:
                    ModelState.AddModelError("", "No user account found");
                    break;

                case UserLoginResults.Deleted:
                    ModelState.AddModelError("", "User is deleted");
                    break;

                case UserLoginResults.NotActive:
                    ModelState.AddModelError("", "Account is not active");
                    break;

                case UserLoginResults.NotRegistered:
                    ModelState.AddModelError("", "Account is not registered");
                    break;

                case UserLoginResults.LockedOut:
                    ModelState.AddModelError("", "User is locked out");
                    break;

                case UserLoginResults.WrongPassword:
                default:
                    ModelState.AddModelError("", "The credentials provided are incorrect");
                    break;
                }
            }

            return(View(model));
        }
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var loginResult = _userRegistrationService.ValidateUser(model.LoginName, model.LoginPassword);
                switch (loginResult)
                {
                case UserLoginResults.Successful:
                {
                    var user = _userService.GetUserByLoginName(model.LoginName);

                    //sign in new customer
                    _authenticationService.SignIn(user, false);

                    //activity log
                    _userActivityService.InsertActivityLog("Login", "From IP: " + Request.UserHostAddress);

                    if (String.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect("/"));
                    }

                    return(Redirect(returnUrl));
                }

                case UserLoginResults.UserNotExist:
                    ModelState.AddModelError("", _localizationService.GetResource("User.Login.WrongCredentials.UserNotExist"));
                    break;

                case UserLoginResults.Deleted:
                    ModelState.AddModelError("", _localizationService.GetResource("User.Login.WrongCredentials.Deleted"));
                    break;

                case UserLoginResults.NotActive:
                    ModelState.AddModelError("", _localizationService.GetResource("User.Login.WrongCredentials.NotActive"));
                    break;

                case UserLoginResults.NotRegistered:
                    ModelState.AddModelError("", _localizationService.GetResource("User.Login.WrongCredentials.NotRegistered"));
                    break;

                case UserLoginResults.WrongPassword:
                default:
                    ModelState.AddModelError("", _localizationService.GetResource("User.Login.WrongCredentials"));
                    break;
                }
            }

            return(View(model));
        }
Ejemplo n.º 5
0
        public virtual IActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var loginResult =
                    _userRegistrationService.ValidateUser(
                        model.Email, model.Password);
                switch (loginResult)
                {
                case UserLoginResults.Successful:
                {
                    var user = _userService.GetUserByEmail(model.Email);

                    //sign in new user
                    _authenticationService.SignIn(user, model.RememberMe);

                    //raise event
                    _eventPublisher.Publish(new UserLoggedinEvent(user));

                    if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
                    {
                        return(RedirectToRoute("Homepage"));
                    }

                    return(Redirect(returnUrl));
                }

                case UserLoginResults.UserNotExist:
                    ModelState.AddModelError("",
                                             "No user account found");
                    break;

                case UserLoginResults.Deleted:
                    ModelState.AddModelError("",
                                             "User is deleted");
                    break;

                case UserLoginResults.WrongPassword:
                default:
                    ModelState.AddModelError("",
                                             "The credentials provided are incorrect");
                    break;
                }
            }

            //If we got this far, something failed, redisplay form
            model = _userModelFactory.PrepareLoginModel();
            return(View(model));
        }
Ejemplo n.º 6
0
        public IActionResult CreateToken(JwtRequest login)
        {
            IActionResult response = Unauthorized();

            var loginResult = _userRegistrationService.ValidateUser(_userSettings.UsernamesEnabled ? login.username : login.username, login.password);

            if (loginResult == UserLoginResults.Successful)
            {
                var user = _userService.GetUserByUsername(login.username);

                var tokenString = Jwt.GenerateToken(user);
                response = Ok(new { token = tokenString });
            }

            return(response);
        }
Ejemplo n.º 7
0
        public UserModel Login([FromBody] UserModel model)
        {
            if (!ModelState.IsValid)
            {
                throw this.ExceptionInvalidModelState();
            }

            var loginResult = _userRegistrationService.ValidateUser(model.LoginName, model.LoginPassword);

            switch (loginResult)
            {
            case UserLoginResults.Successful:
            {
                var primarySystemCurrency = _currencyRepository.GetById(_currencySettings.PrimarySystemCurrencyId);
                var user = _userRepository.GetAll().Where(u => u.LoginName == model.LoginName).FirstOrDefault();
                return(new UserModel
                    {
                        Id = user.Id,
                        Name = user.Name,
                        PublicKey = user.PublicKey,
                        SecretKey = user.SecretKey,
                        DefaultSiteId = user.DefaultSiteId,
                        CurrencySymbol = primarySystemCurrency.CurrencySymbol
                    });
            }

            case UserLoginResults.UserNotExist:
                throw this.ExceptionUnauthorized(_localizationService.GetResource("User.Login.WrongCredentials.UserNotExist"));

            case UserLoginResults.Deleted:
                throw this.ExceptionUnauthorized(_localizationService.GetResource("User.Login.WrongCredentials.Deleted"));

            case UserLoginResults.NotActive:
                throw this.ExceptionUnauthorized(_localizationService.GetResource("User.Login.WrongCredentials.NotActive"));

            case UserLoginResults.NotRegistered:
                throw this.ExceptionUnauthorized(_localizationService.GetResource("User.Login.WrongCredentials.NotRegistered"));

            case UserLoginResults.WrongPassword:
            default:
                throw this.ExceptionUnauthorized(_localizationService.GetResource("User.Login.WrongCredentials"));
            }
        }
Ejemplo n.º 8
0
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var loginResult = _userRegistrationService.ValidateUser(model.Email, model.Password);

                switch (loginResult)
                {
                case UserLoginResults.Successful:
                {
                    var user = _userService.GetUserByEmail(model.Email);

                    _authenticationService.SignIn(user, model.RememberMe);

                    return(RedirectToRoute("HomePage"));
                }

                case UserLoginResults.NotRegistered:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.NotRegistered"));
                    break;

                case UserLoginResults.UserNotExist:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.UserNotExist"));
                    break;

                case UserLoginResults.Deleted:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.Deleted"));
                    break;

                case UserLoginResults.NotActive:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.NotActive"));
                    break;

                case UserLoginResults.WrongPassword:
                default:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials"));
                    break;
                }
            }

            return(View(model));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> PostLogin(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                UserLoginResult loginResult = await _userRegistrationService.ValidateUser(model.UserName, model.Password);

                switch (loginResult)
                {
                case UserLoginResult.Successful:
                    User user = await _userRegistrationService.GetUserByUserName(model.UserName);

                    AuthenticationResult result = await _authenticationService.AuthenticateUser(user);

                    if (result.Success)
                    {
                        return(Ok(model.PrepareLoginSuccessModel(result)));
                    }
                    ModelState.AddModelError(string.Empty, "Login Failed");
                    break;

                case UserLoginResult.UserNotExist:
                    ModelState.AddModelError(string.Empty, "User not exist");
                    break;

                case UserLoginResult.WrongPassword:
                    ModelState.AddModelError(string.Empty, "Wrong Credential");
                    break;

                case UserLoginResult.NotActive:
                    ModelState.AddModelError(string.Empty, "User Inactive");
                    break;

                case UserLoginResult.LockedOut:
                    ModelState.AddModelError(string.Empty, "Profile Locked");
                    break;
                }
            }
            return(BadRequest(ModelState.Select(x => x.Value.Errors.First().ErrorMessage)));
        }
Ejemplo n.º 10
0
 public bool Validate(User user)
 {
     return(registrationService.ValidateUser(user));
 }
Ejemplo n.º 11
0
        public virtual IActionResult Login(LoginModel model, string returnUrl, bool captchaValid)
        {
            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnLoginPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (ModelState.IsValid)
            {
                if (_userSettings.UsernamesEnabled && model.Username != null)
                {
                    model.Username = model.Username.Trim();
                }
                var loginResult = _userRegistrationService.ValidateUser(_userSettings.UsernamesEnabled ? model.Username : model.Email, model.Password);
                switch (loginResult)
                {
                case UserLoginResults.Successful:
                {
                    var user = _userSettings.UsernamesEnabled
                                ? _userService.GetUserByUsername(model.Username)
                                : _userService.GetUserByEmail(model.Email);

                    //sign in new user
                    _authenticationService.SignIn(user, model.RememberMe);

                    //raise event
                    _eventPublisher.Publish(new UserLoggedinEvent(user));

                    //activity log
                    _userActivityService.InsertActivity(user, "PublicStore.Login",
                                                        _localizationService.GetResource("ActivityLog.PublicStore.Login"), user);

                    if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
                    {
                        return(RedirectToRoute("HomePage"));
                    }

                    return(Redirect(returnUrl));
                }

                case UserLoginResults.UserNotExist:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.UserNotExist"));
                    break;

                case UserLoginResults.Deleted:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.Deleted"));
                    break;

                case UserLoginResults.NotActive:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.NotActive"));
                    break;

                case UserLoginResults.NotRegistered:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.NotRegistered"));
                    break;

                case UserLoginResults.LockedOut:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials.LockedOut"));
                    break;

                case UserLoginResults.WrongPassword:
                default:
                    ModelState.AddModelError("", _localizationService.GetResource("Account.Login.WrongCredentials"));
                    break;
                }
            }

            //If we got this far, something failed, redisplay form
            model = _userModelFactory.PrepareLoginModel(model.CheckoutAsGuest);
            return(View(model));
        }
Ejemplo n.º 12
0
        //[ValidateCaptcha]
        //available even when navigation is not allowed
        //[CheckAccessPublicStore(true)]
        //[PublicAntiForgery]
        public virtual IActionResult Login(LoginModel model, string returnUrl, bool captchaValid)
        {
            if (ModelState.IsValid)
            {
                var loginResult = _userRegistrationService.ValidateUser(_userSettings.UsernamesEnabled ?
                                                                        model.UserName : model.Email, model.Password);
                switch (loginResult)
                {
                case UserLoginResults.Successful:
                {
                    var user = _userSettings.UsernamesEnabled
                                ? _userService.GetUserByUsername(model.UserName)
                                : _userService.GetUserByEmail(model.Email);

                    //sign in new user
                    _authenticationService.SignIn(user, model.RememberMe);

                    //raise event
                    _eventPublisher.Publish(new UserLoggedinEvent(user));

                    //activity log
                    //_userActivityService.InsertActivity(user, "PublicStore.Login","ActivityLog.PublicStore.Login", user);

                    if (string.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
                    {
                        //return RedirectToRoute("Project");
                        return(RedirectToAction("Dashboard2", "Dashboards"));
                    }

                    return(Redirect(returnUrl));
                }

                case UserLoginResults.UserNotExist:
                    ModelState.AddModelError("", "ไม่มีผู้ใช้นี้ในระบบ");
                    break;

                case UserLoginResults.Deleted:
                    ModelState.AddModelError("", "ผู้ใช้ถูกลบออกระบบไปแล้ว กรุณาลงทะเบียนใหม่");
                    break;

                case UserLoginResults.NotActive:
                    ModelState.AddModelError("", "ผู้ใช้ไม่ Active");
                    break;

                case UserLoginResults.NotRegistered:
                    ModelState.AddModelError("", "ผู้ใช้ยังไม่ได้ลงทะเบียน");
                    break;

                case UserLoginResults.LockedOut:
                    ModelState.AddModelError("", "ผู้ใช้ Locked Out");
                    break;

                case UserLoginResults.WrongPassword:
                default:
                    ModelState.AddModelError("", "รหัสผ่านไม่ถูกต้องการ");
                    break;
                }
            }

            //If we got this far, something failed, redisplay form
            model = _userModelFactory.PrepareLoginModel(model.CheckoutAsGuest);
            return(View(model));
        }