예제 #1
0
        public ActionResult Login()
        {
            //if (IsAuthorised("154211"))
            //{
            //    return Redirect("~/" + SessionHelper.DefaultPage);
            //}

            //SessionHelper.UserName = "******";
            //SessionHelper.UserId = 3;
            //SessionHelper.UnitId = 1;
            //SessionHelper.DateFormat = "dd MMM, yyyy";
            //return Redirect("~/Main");


            var encriptData = string.Empty;

            if (Request.QueryString[SsoUtility.SsoToken] != null)
            {
                encriptData = HttpUtility.HtmlDecode(Request.QueryString[SsoUtility.SsoToken]);


                //Process for normal authentication
                var objSsoManager = new SSOManager();
                var objSso        = objSsoManager.GetSSO(encriptData);

                //SMSC.Models.SMSCContext _contex = new Models.SMSCContext();
                if (objSso.authenticated == true)
                {
                    userLoginLogService.Add(new UserLoginLog
                    {
                        PIN         = objSso.name
                        , Name      = objSso.fullname
                        , LoginTime = DateTime.Now
                    });

                    unitOfWork.Commit();
                    SessionHelper.IsGuest = false;

                    if (IsAuthorised(objSso.name))
                    {
                        return(Redirect("~/" + SessionHelper.DefaultPage));
                    }
                    else
                    {
                        SessionHelper.UserName = objSso.fullname;
                        SessionHelper.UserId   = 0;
                        SessionHelper.UnitId   = 1;
                        //SessionHelper.DateFormat = "dd MMM, yyyy";
                        return(Redirect("~/Main"));
                    }
                }
                else if (objSso.name != null)
                {
                    ModelState.AddModelError("", "");
                }
            }

            return(View("Index"));
        }
예제 #2
0
        bool IsAuthorised(string pin, string password)
        {
            var login = userProfileService.GetByPin(pin);

            if (login == null)
            {
                return(false);
            }

            else if (login.Password != password.ToMD5())
            {
                return(false);
            }

            Role role = roleService.GetDataById(login.RoleId);

            if (role.IsActive && login.IsActive)
            {
                userLoginLogService.Add(new UserLoginLog
                {
                    PIN = login.Pin
                    ,
                    Name = login.UserName
                    ,
                    LoginTime = DateTime.Now
                });

                unitOfWork.Commit();

                FormsAuthentication.SetAuthCookie(pin, true);
                var identity = new GenericIdentity(pin);

                //var unit = unitOfUserService.GetAllUnitsOfUserByUserProfileId(login.Id).FirstOrDefault();
                //SessionHelper.DateFormat = "dd MMM, yyyy";
                SessionHelper.UserName = login.UserName;
                SessionHelper.UserId   = login.Id;
                SessionHelper.IsGuest  = true;

                //var tmp = userAccessListService.GetUserAccessListByUserProfileID(login.Id);
                //SessionHelper.Role = roleFeatureService.GetFeaturesByRoleID(login.RoleId);
                //SessionHelper.CanAccessAllDept = role.CanAccessAllDepartment;
                IEnumerable <QryRoleFeature> features = roleFeatureService.GetFeaturesByRoleID(role.Id);
                List <string> ftr = new List <string>();

                if (features != null)
                {
                    ftr = features.Select(c => c.Name).ToList();
                }

                SessionHelper.Role = ftr;

                GenericPrincipal gp = new GenericPrincipal(identity, ftr.ToArray());
                HttpContext.User = gp;

                SessionHelper.DefaultPage = role.RoleDefaultPage.PageUrl;

                return(true);
            }

            return(false);
        }