public void OnActionExecuting(ActionExecutingContext context)
        {
            string controllername = ((Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)context.ActionDescriptor).ControllerName;
            string actionname     = ((Microsoft.AspNetCore.Mvc.Controllers.ControllerActionDescriptor)context.ActionDescriptor).ActionName;

            if (string.IsNullOrEmpty(Convert.ToString(context.HttpContext.Session.GetString(Constant.SessionUserName))))
            {
                context.Result = new RedirectToRouteResult(new Microsoft.AspNetCore.Routing.RouteValueDictionary
                {
                    { "Controller", "Account" },
                    { "Action", "SignOut" }
                });
            }
            else if (Convert.ToString(context.HttpContext.Session.GetString(Constant.SessionUserName)) != null)
            {
                MenuviewModel menuModel = JsonConvert.DeserializeObject <MenuviewModel>(context.HttpContext.Session.GetString(Constant.Menu));
                int           count     = menuModel.MenuModels.Where(x => x.Controller.ToUpper() == controllername.ToUpper() && x.Action.ToUpper() == actionname.ToUpper()).Count();
                if (count == 0)
                {
                    context.Result = new RedirectToRouteResult(new Microsoft.AspNetCore.Routing.RouteValueDictionary
                    {
                        { "Controller", "Home" },
                        { "Action", "Accessdenied" }
                    });
                }
            }
        }
 public IActionResult ApproverLogin(ApproverLogin loginViewModel)
 {
     if (!ModelState.IsValid)
     {
         return(View());
     }
     try
     {
         var empid = "";
         loginViewModel.Password = AESEncrytDecry.DecryptStringAES(loginViewModel.Password);
         var result = AdLogin(loginViewModel.UserId, loginViewModel.Password, loginViewModel.MailID, loginViewModel.Mobileno, out empid, out string userName, out string firstname);
         if (!result)
         {
             ViewBag.Messages = new[] { new AlertModel("danger", "Warning!", "Entered Credentials Did Not Match") };
             return(View());
         }
         else
         {
             var EmpID      = loginViewModel.UserId;
             var employeeid = empid;
             if (employeeid.Length != 8)
             {
                 employeeid = employeeid.ToString().PadLeft(8, '0');
             }
             Tuple <string, int> Result = _Ileaveapprovalservice.InsertEmpId(employeeid);
             if (Result.Item2 == 0)
             {
                 TempData["loginendtime"] = Result.Item1;
                 return(RedirectToAction("LoginTimeout", "Home"));
             }
             HttpContext.Session.SetString(Constant.ApproverID, employeeid);
             HttpContext.Session.SetString(Constant.AdminID, employeeid);
             HttpContext.Session.SetString(Constant.SessionUserName, userName);
             HttpContext.Session.SetString(Constant.SessionModulName, "Approver");
             HttpContext.Session.SetString("FirstName", firstname);
             ViewBag.UserName = HttpContext.Session.GetString(Constant.SessionUserName);
             LeaveApprovalModelViewModel approverLogin = new LeaveApprovalModelViewModel();
             string        ModuleName = HttpContext.Session.GetString(Constant.SessionModulName);
             var           MenuItem   = _imenuservice.GetMenu(ModuleName, employeeid);
             MenuviewModel model      = new MenuviewModel();
             model.MenuModels = Mapper.Map <List <MenuModel> >(MenuItem);
             HttpContext.Session.SetObjectAsJson <MenuviewModel>(Constant.Menu, model);
             return(RedirectToAction("ApproverDashboard", "LeaveApprover"));
         }
     }
     catch (Exception ex)
     {
         _logger.LogError(ex, ex.Message);
         ViewBag.Messages = new[] { new AlertModel("danger", "Warning!", "Entered Credentials Did Not Match") };
         return(View());
     }
 }
예제 #3
0
 public IActionResult Login(LoginViewModel loginViewModel, string btnLoginSubmit)
 {
     ModelState.Remove("ConfirmPassword");
     ModelState.Remove("EnterOTP");
     ModelState.Remove("NewPassword");
     if (!ModelState.IsValid)
     {
         if (btnLoginSubmit == "KIOSK")
         {
             return(View("LoginKIOSKHome"));
         }
         else
         {
             return(View());
         }
     }
     else
     {
         int flag = Convert.ToInt32(TempData["Flagforpwd"]);
         if (flag == 1)
         {
             ViewBag.Messages = new[] { new AlertModel("success", "Success!", "Password changed successfully") };
         }
         try
         {
             loginViewModel.Password = AESEncrytDecry.DecryptStringAES(loginViewModel.Password);
             if (loginViewModel.UserId.Trim().Length != 8)
             {
                 loginViewModel.UserId = loginViewModel.UserId.Trim().ToString().PadLeft(8, '0');
             }
             var result = Mapper.Map <LoginViewModel>(_ILoginViewService.Authentication(Mapper.Map <LoginViewServiceModel>(loginViewModel)));
             if (result.ReturnsaveValue == 1)
             {
                 ViewBag.Messages = new[] { new AlertModel("danger", "Warning!", "Incorrect UserID/Password. Your account will get locked out after 5 failure login attempts. If you've forgot password, please click on Forgot/Reset Password.") };
                 if (btnLoginSubmit == "KIOSK")
                 {
                     return(View("LoginKIOSKHome"));
                 }
                 else
                 {
                     return(View());
                 }
             }
             else if (result.ReturnsaveValue == 2)
             {
                 TempData["flag"]       = 1;
                 TempData["EmployeeID"] = loginViewModel.UserId;
                 return(RedirectToAction("GenerateOTP", "Account"));
             }
             else if (result.ReturnsaveValue == 3)
             {
                 TempData["loginstatus"]  = "concurrentlogin";
                 TempData["loginendtime"] = result.ReturnValMessg;
                 return(RedirectToAction("LoginTimeout", "Home"));
             }
             else if (result.ReturnsaveValue == 4)
             {
                 TempData["loginstatus"]  = "loginattempfailed";
                 TempData["loginendtime"] = result.ReturnValMessg;
                 return(RedirectToAction("LoginTimeout", "Home"));
             }
             else
             {
                 string userName   = result.EmployeeName;
                 string EmailID    = result.EmployeeMail;
                 string EmployeeId = Convert.ToString(result.EmployeeID.Trim());
                 if (EmployeeId.Length != 8)
                 {
                     EmployeeId = EmployeeId.ToString().PadLeft(8, '0');
                 }
                 string DOB      = result.EmployeeDOB;
                 string Grade    = result.Grade;
                 string Dept     = result.Dept;
                 string mobileno = (result.MobileNO);
                 HttpContext.Session.SetString(Constant.SessionUserName, userName);
                 HttpContext.Session.SetString(Constant.Category, result.Category.ToString());
                 HttpContext.Session.SetString(Constant.EmployeeID, EmployeeId.Trim().ToString());
                 HttpContext.Session.SetString("FirstName", userName);
                 HttpContext.Session.SetString(Constant.PersonalArea, result.PersonalArea);
                 HttpContext.Session.SetString(Constant.PersonalSubArea, result.PersonalSubArea);
                 HttpContext.Session.SetString(Constant.MobileNo, mobileno.ToString());
                 ViewBag.UserName = HttpContext.Session.GetString(Constant.SessionUserName);
                 HttpContext.Session.SetString(Constant.SessionModulName, "Employee");
                 string ModuleName = HttpContext.Session.GetString(Constant.SessionModulName);
                 var    EmployeeID = HttpContext.Session.GetString(Constant.EmployeeID);
                 GetdataSAP(EmployeeID);
                 var           MenuItem = _ImenuServices.GetMenu(ModuleName, EmployeeId);
                 MenuviewModel model    = new MenuviewModel();
                 model.MenuModels = Mapper.Map <List <MenuModel> >(MenuItem);
                 HttpContext.Session.SetObjectAsJson <MenuviewModel>(Constant.Menu, model);
             }
         }
         catch (Exception ex)
         {
             _logger.LogError(ex, ex.Message);
             ViewBag.Messages = new[] { new AlertModel("danger", "Warning!", "Please try after some time") };
             if (btnLoginSubmit == "KIOSK")
             {
                 return(View("LoginKIOSKHome"));
             }
             else
             {
                 return(View());
             }
         }
         return(RedirectToAction("LeaveDashboard", "LeaveDashboard"));
     }
 }