Example #1
0
        public IActionResult Index()
        {
            ProfileMenuRightsViewModel objProfileMenuRightsViewModel = HttpContext.Session.GetObjectFromJson <ProfileMenuRightsViewModel>("MenuDetail");


            //DashboardAdminViewModel objDashboardAdminViewModel = new DashboardAdminViewModel();

            DashboardAdminViewModel objDashboardAdminViewModel = null;
            string        endpoint        = assetsApiBaseUrl + "Dashboard?MasterSubCategoryId=0&MasterBranchId=0";
            Task <string> HttpGetResponse = CommonFunction.GetWebAPI(endpoint);

            if (HttpGetResponse != null)
            {
                objDashboardAdminViewModel = JsonConvert.DeserializeObject <DashboardAdminViewModel>(HttpGetResponse.Result);
            }
            else
            {
                objDashboardAdminViewModel = new DashboardAdminViewModel();;

                ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
            }

            //OtherDetail

            objDashboardAdminViewModel.CurrentDateTime      = DateTime.Now;
            objDashboardAdminViewModel.LastSuccessfullLogin = objProfileMenuRightsViewModel.LastSuccessfullLogin;
            objDashboardAdminViewModel.CompanyMasterName    = objProfileMenuRightsViewModel.MasterCompanyName;
            objDashboardAdminViewModel.LoginIP   = objProfileMenuRightsViewModel.LoginIP;
            objDashboardAdminViewModel.SessionId = objProfileMenuRightsViewModel.SessionId;

            return(View(objDashboardAdminViewModel));
        }
        public static long?UserAuthentication(HttpContext context)
        {
            long EnterById = 0;

            System.Security.Claims.ClaimsPrincipal IUser = new ClaimsPrincipal();


            ProfileMenuRightsViewModel objProfileMenuRightsViewModel = context.Session.GetObjectFromJson <ProfileMenuRightsViewModel>("MenuDetail");

            if (objProfileMenuRightsViewModel != null && objProfileMenuRightsViewModel.ValidateAccountViewModelList != null && objProfileMenuRightsViewModel.ValidateAccountViewModelList.Count > 0)
            {
                EnterById = objProfileMenuRightsViewModel.ValidateAccountViewModelList.Select(a => a.MasterLoginId).FirstOrDefault();
            }

            return(EnterById);
        }
        public static ValidateAccountViewModel ActionResultAuthentication(HttpContext context, string strControlerURL)
        {
            ProfileMenuRightsViewModel objProfileMenuRightsViewModel = context.Session.GetObjectFromJson <ProfileMenuRightsViewModel>("MenuDetail");

            ValidateAccountViewModel objValidateAccountViewModel = new ValidateAccountViewModel();

            if (objProfileMenuRightsViewModel != null && objProfileMenuRightsViewModel.ValidateAccountViewModelList.Count > 0)
            {
                long ProfileMasterId = objProfileMenuRightsViewModel.ValidateAccountViewModelList.Select(a => a.MasterProfileId).FirstOrDefault();

                long iMenuMasterId = objProfileMenuRightsViewModel.ValidateAccountViewModelList.Where(a => a.FunctionLink == strControlerURL).Select(a => a.MasterFunctionId).FirstOrDefault();

                objValidateAccountViewModel = objProfileMenuRightsViewModel.ValidateAccountViewModelList.Where(a => a.MasterFunctionId == iMenuMasterId).FirstOrDefault();
            }
            return(objValidateAccountViewModel);
        }
Example #4
0
        public async Task <IActionResult> Login(LoginViewModel model, string returnUrl = null)
        {
            try
            {
                ViewData["ReturnUrl"] = returnUrl;

                if (!ModelState.IsValid)
                {
                    return(View(model));
                }

                //Get IP Address for Client Computer:
                //first the IP Address is determined for the Client machine’s which are behind Routers or Proxy Servers and hence the HTTP_X_FORWARDED_FOR server variable is checked.
                //If the IP Address is not found in the HTTP_X_FORWARDED_FOR server variable, it means that it is not using any Proxy Server and hence the IP Address is now checked in the REMOTE_ADDR server variable.

                string ipAddress = ""; Request.HttpContext.Connection.RemoteIpAddress.ToString();
                if (string.IsNullOrEmpty(ipAddress))
                {
                    ipAddress = Request.HttpContext.Connection.RemoteIpAddress.ToString();
                }

                string strSessionId = HttpContext.Session.Id;

                // Verify if a user exists with the provided identity information
                IEnumerable <ValidateAccountViewModel> objValidateAccountViewModelList = null;

                //Authentication & Authorisation
                ClaimsIdentity identity        = null;
                bool           isAuthenticated = false;

                string endpoint = apiBaseUrl + "ValidateAccount?UserName="******"&Password="******"&VerificationCode='0'&MacId=" + ipAddress + "&SessionId=" + strSessionId;

                if (CommonFunction.GetWebAPI(endpoint) != null)
                {
                    objValidateAccountViewModelList = JsonConvert.DeserializeObject <IEnumerable <ValidateAccountViewModel> >(CommonFunction.GetWebAPI(endpoint).Result);
                }
                else
                {
                    objValidateAccountViewModelList = Enumerable.Empty <ValidateAccountViewModel>();

                    ModelState.AddModelError(string.Empty, "Server error. Please contact administrator.");
                }

                if (objValidateAccountViewModelList != null && objValidateAccountViewModelList.Count() > 0 && objValidateAccountViewModelList.Where(a => a.ValidationCount == 1).Count() > 0 && objValidateAccountViewModelList.Where(a => a.IsFirstLogin == true).Count() == 0)
                {
                    ProfileMenuRightsViewModel objProfileMenuRightsViewModel = new ProfileMenuRightsViewModel();
                    objProfileMenuRightsViewModel.ValidateAccountViewModelList = objValidateAccountViewModelList.ToList();

                    objProfileMenuRightsViewModel.PayCalPeriod         = DateTime.Now.ToString("MMyyyy");
                    objProfileMenuRightsViewModel.PayPeriod            = DateTime.Now.AddMonths(-1).ToString("MMyyyy");
                    objProfileMenuRightsViewModel.MasterLoginId        = objValidateAccountViewModelList.Select(a => a.MasterLoginId).FirstOrDefault();
                    objProfileMenuRightsViewModel.MasterFinancialId    = 3;
                    objProfileMenuRightsViewModel.MasterCompanyId      = objValidateAccountViewModelList.Select(a => a.MasterCompanyId).FirstOrDefault() ?? 0;
                    objProfileMenuRightsViewModel.MasterCompanyName    = "Knowledge Ridge Private Limited";
                    objProfileMenuRightsViewModel.SessionId            = strSessionId;
                    objProfileMenuRightsViewModel.LoginIP              = ipAddress;
                    objProfileMenuRightsViewModel.LastSuccessfullLogin = objValidateAccountViewModelList.Select(a => a.LastLoginDate).FirstOrDefault().ToString();

                    //Session is used to store object
                    HttpContext.Session.SetObjectAsJson("MenuDetail", objProfileMenuRightsViewModel);

                    identity        = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, model.Email) }, CookieAuthenticationDefaults.AuthenticationScheme);
                    isAuthenticated = true;
                }

                //Check for Authentication
                if (isAuthenticated)
                {
                    var principal = new ClaimsPrincipal(identity);

                    var login = HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);

                    //Notification Message
                    //Session is used to store object
                    HttpContext.Session.SetObjectAsJson("GlobalMessage", CommonFunction.GlobalMessage(1, 3, 4, "HI " + objValidateAccountViewModelList.Select(a => a.EmployeeName).FirstOrDefault(), "You have successfully login!", "Your last successfull login was on dated " + objValidateAccountViewModelList.Select(a => a.LastLoginDate).FirstOrDefault().ToString() + "!"));

                    _logger.LogInformation(1, "User " + objValidateAccountViewModelList.Select(a => a.EmployeeName).FirstOrDefault() + " successfully logged in.");

                    return(RedirectToAction("Index", "Dashboard"));
                }
                else
                {
                    _logger.LogWarning(2, "Invalid login attempt by" + objValidateAccountViewModelList.Select(a => a.EmployeeName).FirstOrDefault());

                    ModelState.AddModelError(string.Empty, "Invalid login attempt.");

                    // If we get to this point, something failed, redisplay form and trigger the error summary
                    return(View(model));
                }
            }
            catch (System.Exception ex)
            {
                string ActionName     = this.ControllerContext.RouteData.Values["action"].ToString();
                string ControllerName = this.ControllerContext.RouteData.Values["controller"].ToString();
                string ErrorMessage   = "Controler:" + ControllerName + " , Action:" + ActionName + " , Exception:" + ex.Message;

                _logger.LogError(ErrorMessage);
                return(View("~/Views/Shared/Error.cshtml", CommonFunction.HandleErrorInfo(ex, ActionName, ControllerName)));
            }
            return(new EmptyResult());
        }