Exemplo n.º 1
0
        public ActionResult Login(UserMasterDTO data)
        {
            List <EntitlementDTO> lstEntitleMent = new List <EntitlementDTO>();
            List <ActionDTO>      lstAction      = new List <ActionDTO>();
            string unencryptedPass = data.Password;
            string pass            = encrypt.encryption(data.Password);

            data.Password = pass;

            StatusDTO <UserMasterDTO> status = _userSvc.Login(data, out lstEntitleMent, out lstAction);

            if (status.IsSuccess)
            {
                if (data.RememberMe)
                {
                    HttpCookie cookie = new HttpCookie("userDetails");
                    cookie["uid"]  = data.UserName;
                    cookie["pwd"]  = unencryptedPass;
                    cookie.Expires = DateTime.Now + new TimeSpan(1, 0, 0, 0);

                    if (Request.Cookies["userDetails"] != null)
                    {
                        Response.Cookies.Set(cookie);
                    }
                    else
                    {
                        Response.Cookies.Add(cookie);
                    }
                }
                else
                {
                    Response.Cookies.Remove("userDetails");
                }

                SessionDTO session = new SessionDTO();
                session.UserMasterId    = status.ReturnObj.UserMasterId;
                session.UserName        = status.ReturnObj.UserName;
                session.FName           = status.ReturnObj.FName;
                session.MName           = status.ReturnObj.MName;
                session.LName           = status.ReturnObj.LName;
                session.ActionList      = lstAction;
                session.EntitleMentList = lstEntitleMent;


                _sessionSvc.SetUserSession(session);
                SessionDTO sessionRet = _sessionSvc.GetUserSession();
            }
            else
            {
                data.LoginFailedMsg = status.FailureReason;
                return(View(data));
            }

            return(RedirectToAction("Landing", "Login", new { area = "Login" }));;
        }
Exemplo n.º 2
0
 public IActionResult Login([FromBody] LoginRequest request)
 {
     try
     {
         var user = _userSvc.Login(request.Username, request.Password);
         if (user != null)
         {
             return(Ok(user));
         }
         else
         {
             return(Ok(null));
         }
     }
     catch (Exception ex)
     {
         Log.Error($"Failed while logging in user: {request.Username} : {ex.Message}");
     }
     return(BadRequest());
 }