Example #1
0
        private static bool RetriveSessionFromCookie()
        {
            var        cookies = WebGlobalVariable.Request.Cookies;
            HttpCookie cookie  = cookies[RightConst.USER_INFO_COOKIE_NAME];

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

            CookieUserInfo userInfo = CookieUserInfo.FromEncodeString(cookie.Value);

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

            EmptyDbDataSource source = new EmptyDbDataSource();

            using (source)
                using (UserResolver resolver = new UserResolver(source))
                {
                    try
                    {
                        IUserInfo info = resolver.CheckUserLogOnById(userInfo.UserId, userInfo.Password);
                        WebGlobalVariable.SessionGbl.AppRight.Initialize(info);
                        return(true);
                    }
                    catch
                    {
                        return(false);
                    }
                }
        }
Example #2
0
        public OutputData Insert(IInputData input, object instance)
        {
            LogOnData data = instance.Convert <LogOnData>();

            using (UserResolver resolver = new UserResolver(this))
            {
                IUserInfo userInfo = resolver.CheckUserLogOn(data.LogOnName, data.Password, 0);
                if (userInfo == null)
                {
                }
                WebGlobalVariable.SessionGbl.AppRight.Initialize(userInfo);

                var        response = WebGlobalVariable.Response;
                HttpCookie cookie   = new HttpCookie(COOKIE_NAME, data.LogOnName)
                {
                    Expires = DateTime.Now.AddDays(30)
                };
                response.Cookies.Set(cookie);
                CookieUserInfo cookieInfo = new CookieUserInfo(data, userInfo);
                cookie = new HttpCookie(RightConst.USER_INFO_COOKIE_NAME, cookieInfo.Encode())
                {
                    Expires = GetExpireDate()
                };
                response.Cookies.Set(cookie);

                WebSuccessResult result;
                var    request = WebGlobalVariable.Request;
                string retUrl  = request.QueryString["RetURL"];
                if (!string.IsNullOrEmpty(retUrl))
                {
                    result = new WebSuccessResult(retUrl);
                }
                else
                {
                    WebAppSetting appSetting = WebAppSetting.WebCurrent;
                    if (string.IsNullOrEmpty(appSetting.MainPath))
                    {
                        result = new WebSuccessResult(appSetting.HomePath);
                    }
                    else
                    {
                        string url     = HttpUtility.UrlEncode(appSetting.HomePath);
                        string mainUrl = UriUtil.AppendQueryString(appSetting.MainPath, "StartUrl=" + url);
                        result = new WebSuccessResult(mainUrl);
                    }
                }

                return(OutputData.CreateToolkitObject(result));
            }
        }
Example #3
0
        public ActionResult SecretCode(SecretCodeModel secretCode)
        {
            try
            {
                HttpCookie     cookie   = HttpContext.Request.Cookies.Get(".SECURECODE");
                CookieUserInfo userInfo = (CookieUserInfo)HttpRuntime.Cache.Get(HttpContext.Request.UserHostAddress + HttpContext.Request.UserAgent);

                if ((cookie == null) || (userInfo == null) || (cookie.Value != userInfo.Cookie.Value))
                {
                    return(RedirectToAction("Index"));
                }

                Customer customer  = _repo.Customers.GetAll(c => (c.Login == userInfo.LoginModel.Name) && (c.Passoword == userInfo.LoginModel.Password)).ToList().First();
                var      card      = customer.AccessCards.First();
                var      codes     = _repo.AccessCodes.GetAll(c => c.AccessCardID == card.AccessCardID).ToList();
                var      code      = codes.Where(c => c.Number == secretCode.CodeIndex).First();
                var      codeCount = _repo.AccessCodes.GetAll(c => c.AccessCardID == card.AccessCardID).Count();


                if (code.Code == secretCode.EnteredCode)
                {
                    WebSecurity.Login(userInfo.LoginModel.Name, userInfo.LoginModel.Password);
                    RedirectToAction("Index", "Home");
                }
                else
                {
                    CodeEnterFail(card);
                    if (card.IsBlocked == true)
                    {
                        return(View("AccountBlocked"));
                    }
                    ModelState.Remove("CodeIndex");
                    var secretCodeModel = new SecretCodeModel()
                    {
                        CodeIndex = (new Random()).Next(1, codeCount),
                        Remaining = GetEnterCodeRemaining(card)
                    };

                    ResetCookie(userInfo.LoginModel);
                    ModelState.AddModelError("", "Неправильный код. Попробуйте еще раз");
                    return(View(secretCodeModel));
                }

                return(RedirectToAction("Index", "Home"));
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
        public OutputData Insert(IInputData input, object instance)
        {
            LogOnData data = instance.Convert<LogOnData>();
            using (UserResolver resolver = new UserResolver(this))
            {
                IUserInfo userInfo = resolver.CheckUserLogOn(data.LogOnName, data.Password, 0);
                if (userInfo == null)
                {
                }
                WebGlobalVariable.SessionGbl.AppRight.Initialize(userInfo);

                var response = WebGlobalVariable.Response;
                HttpCookie cookie = new HttpCookie(COOKIE_NAME, data.LogOnName)
                {
                    Expires = DateTime.Now.AddDays(30)
                };
                response.Cookies.Set(cookie);
                CookieUserInfo cookieInfo = new CookieUserInfo(data, userInfo);
                cookie = new HttpCookie(RightConst.USER_INFO_COOKIE_NAME, cookieInfo.Encode())
                {
                    Expires = GetExpireDate()
                };
                response.Cookies.Set(cookie);

                WebSuccessResult result;
                var request = WebGlobalVariable.Request;
                string retUrl = request.QueryString["RetURL"];
                if (!string.IsNullOrEmpty(retUrl))
                    result = new WebSuccessResult(retUrl);
                else
                {
                    WebAppSetting appSetting = WebAppSetting.WebCurrent;
                    if (string.IsNullOrEmpty(appSetting.MainPath))
                        result = new WebSuccessResult(appSetting.HomePath);
                    else
                    {
                        string url = HttpUtility.UrlEncode(appSetting.HomePath);
                        string mainUrl = UriUtil.AppendQueryString(appSetting.MainPath, "StartUrl=" + url);
                        result = new WebSuccessResult(mainUrl);
                    }
                }

                return OutputData.CreateToolkitObject(result);
            }
        }
Example #5
0
        private void ResetCookie(LoginModel loginModel)
        {
            HttpRuntime.Cache.Remove(HttpContext.Request.UserHostAddress + HttpContext.Request.UserAgent);

            var cookie = new HttpCookie(".SECURECODE")
            {
                Expires = DateTime.Now.AddSeconds(_expiration_time_sec),
                Value   = Tools.GetCookieValue(_expiration_time_sec)
            };

            var userInfo = new CookieUserInfo()
            {
                Cookie     = cookie,
                LoginModel = loginModel
            };

            HttpRuntime.Cache.Add(HttpContext.Request.UserHostAddress + HttpContext.Request.UserAgent, userInfo, null, DateTime.Now.AddSeconds(_expiration_time_sec),
                                  Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);
            HttpContext.Response.AppendCookie(cookie);
        }
Example #6
0
        public ActionResult SecretCode()
        {
            HttpCookie     cookie   = HttpContext.Request.Cookies.Get(".SECURECODE");
            CookieUserInfo userInfo = (CookieUserInfo)HttpRuntime.Cache.Get(HttpContext.Request.UserHostAddress + HttpContext.Request.UserAgent);

            if ((cookie == null) || (userInfo == null) || (cookie.Value != userInfo.Cookie.Value))
            {
                return(RedirectToAction("Index"));
            }

            Customer customer  = _repo.Customers.GetAll(c => (c.Login == userInfo.LoginModel.Name) && (c.Passoword == userInfo.LoginModel.Password)).ToList().First();
            var      card      = customer.AccessCards.First();
            var      codeCount = _repo.AccessCodes.GetAll(c => c.AccessCardID == card.AccessCardID).Count();

            ModelState.Remove("CodeIndex");
            var secretCodeModel = new SecretCodeModel()
            {
                CodeIndex = (new Random()).Next(1, codeCount),
                Remaining = GetEnterCodeRemaining(card)
            };

            ResetCookie(userInfo.LoginModel);
            return(View(secretCodeModel));
        }