Exemplo n.º 1
0
        //[EnableCors("AllowOrigin")]
        public IActionResult Authenticate([FromBody] User userParam)
        {
            if (userParam.Username == null || userParam.Password == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            var user = _loginManager.Authenticate(userParam.Username, userParam.Password);

            if (user != null)
            {
                return(Ok(_mapper.Map <LoginDTO>(user)));
            }
            return(Unauthorized(user));
        }
Exemplo n.º 2
0
        private void loginBtn_Click(object sender, EventArgs e)
        {
            _authenticatedUser = _loginManager.Authenticate(usernameTxt.Text, passwordTxt.Text);

            if (_authenticatedUser.IsExisting)
            {
                Program.LoggedInUser = _authenticatedUser;
                errorMsg.Visible     = false;

                displayMainMenu();
            }
            else
            {
                errorMsg.Visible = true;
            }
        }
 public virtual IActionResult Authenticate([FromBody] Login body)
 {
     try
     {
         var user = loginManager.Authenticate(body.Username, body.Password);
         if (user != null)
         {
             return(Ok(user));
         }
         else
         {
             throw new Exception();
         }
     }
     catch (Exception ex)
     {
         return(BadRequest("Invalid username or password "));
     }
 }
Exemplo n.º 4
0
        public ActionResult Authentication(LoginModel model)
        {
            LoginManager manager = new LoginManager();

            model = manager.Authenticate(model.Username, model.Password);

            if (model == null)
            {
                return(View("Index", new LoginModel {
                    ResultMessage = "Username/Passoword invalid"
                }));
            }

            // Set session
            Helper.Username = model.Username;
            Helper.UserId   = model.UserId.ToString();
            Helper.UserRole = model.Role.ToString();

            return(RedirectToAction("Index", "Home"));
        }
Exemplo n.º 5
0
        public async Task <ActionResult> LogOn(LogOnViewModel user)
        {
            if (ModelState.IsValid)
            {
                UserLoginProfile profile = await LoginManager.Authenticate(user, HttpContext.IsDebuggingEnabled);

                if (profile != null)
                {
                    bool confirm = false;
                    if (!string.IsNullOrEmpty(profile.error))
                    {
                        if (profile.error.IndexOf("패스워드가 만료 되었습니다", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                            profile.error.IndexOf("密碼已經過期", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                            profile.error.IndexOf("password has been expired", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                            profile.error.IndexOf("密码已经过期", StringComparison.InvariantCultureIgnoreCase) >= 0)
                        {
                            return(View("ChangePassword", (object)user.Username));
                        }

                        if (profile.error.IndexOf("密碼將於", StringComparison.InvariantCultureIgnoreCase) >= 0 &&
                            profile.error.IndexOf("天後到期", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                            profile.error.IndexOf("days left to be password expiration",
                                                  StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                            profile.error.IndexOf("패스워드 만료가", StringComparison.InvariantCultureIgnoreCase) >= 0 &&
                            profile.error.IndexOf("일 남았습니다", StringComparison.InvariantCultureIgnoreCase) >= 0)
                        {
                            confirm = true;
                        }

                        if (!confirm)
                        {
                            ModelState.AddModelError("", profile.error);
                            return(View(user));
                        }
                    }
                    await UpdateUsername(user.Username, profile.UserName);

                    RequestResult <string[]> result = GetAccessableBrands(user.Username);
                    if (!string.IsNullOrEmpty(result.ErrorMessage))
                    {
                        ModelState.AddModelError("", result.ErrorMessage);
                        return(View(user));
                    }
                    string lang = Codehelper.GetLang(profile.Language);
                    if (HttpContext.IsDebuggingEnabled)
                    {
                        FormsAuthenticationHelper.SetAuthCookie(user.Username, false, string.Join(",", result.ReturnValue));
                        return(RedirectToAction("Index", "Home", new { lang }));
                    }
                    FormsAuthenticationHelper.SetAuthCookie(user.Username, false, string.Join(",", result.ReturnValue));
                    if (confirm)
                    {
                        ViewBag.Msg      = profile.error;
                        ViewBag.Country  = profile.Country;
                        ViewBag.Language = lang;
                        return(View("ConfirmChangePassword"));
                    }
                    if (!Codehelper.DefaultCountry.EqualsIgnoreCaseAndBlank(profile.Country))
                    {
                        return(RedirectToAction("SwitchSite", new { country = profile.Country, language = lang }));
                    }
                    return(RedirectToAction("Index", "Home", new { lang }));
                }
            }
            ModelState.AddModelError("", StringResource.INVALID_USERNAME_OR_PASSWORD);
            return(View(user));
        }