public ActionResult Login(string userName, string userPassword)
        {
            IUserFacade userFacade = FacadeRepository.GetUserFacade();

            SecurityUser securityUser = null;

            try
            {
                securityUser = userFacade.Authenticate(userName, userPassword);
            }
            catch (System.Threading.ThreadAbortException se)
            {
                ViewBag.Message = se.Message;
            }
            catch (SecurityException se)
            {
                ViewBag.Message = se.Message;
            }
            catch (Exception ex)
            {
                ViewBag.Message = ex.Message;
            }

            if (securityUser != null)
            {
                SecurityManager.CurrentUser = securityUser;

                Session[Constants.UserID]           = securityUser.UserId;
                Session[Constants.RoleID]           = securityUser.RoleId;
                Session[Constants.PermissionString] = securityUser.UserPermission;
                Session[Constants.Name]             = securityUser.Name;

                UserName = securityUser.Name;

                if (Request.QueryString["ReturnUrl"] != null)
                {
                    FormsAuthentication.RedirectFromLoginPage(userName, false);
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(userName, false);
                }

                if (!securityUser.MustChangePassword)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    Response.Redirect("User/ChangePassword.aspx?Id=" + securityUser.UserId + "&Pass="******"&Delete=True", false);
                }
            }
            else
            {
                ViewBag.WrongCredentials = "Username or password is incorrect.";
            }

            return(View());
        }
Exemple #2
0
        public void LoginUser(string userName, string userPassword)
        {
            IUserFacade userFacade = FacadeRepository.GetUserFacade();

            lblMessage.Text = string.Empty;
            SecurityUser securityUser = null;

            try
            {
                securityUser = userFacade.Authenticate(userName, userPassword);
            }
            catch (System.Threading.ThreadAbortException se)
            {
                lblMessage.Text = se.Message;
            }
            catch (SecurityException se)
            {
                lblMessage.Text = se.Message;
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }

            if (securityUser != null)
            {
                SecurityManager.CurrentUser = securityUser;

                Session[Constants.UserID]           = securityUser.UserId;
                Session[Constants.RoleID]           = securityUser.RoleId;
                Session[Constants.PermissionString] = securityUser.UserPermission;
                Session[Constants.Name]             = securityUser.Name;



                if (Request.QueryString["ReturnUrl"] != null)
                {
                    FormsAuthentication.RedirectFromLoginPage(userName, false);
                }
                else
                {
                    FormsAuthentication.SetAuthCookie(userName, false);
                }

                if (!securityUser.MustChangePassword)
                {
                    Response.Redirect("~/Welcome.aspx", false);
                    Response.Redirect("~/WebForms/Admin/User/Search.aspx", false);
                }
                else
                {
                    Response.Redirect("User/ChangePassword.aspx?Id=" + securityUser.UserId + "&Pass="******"&Delete=True", false);
                }
            }
        }
        public IActionResult Authenticate([FromBody] UserCredential userParam)
        {
            var user = _facade.Authenticate(userParam.UserName, userParam.Password);

            if (user.Result == null)
            {
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            return(Ok(user));
        }