示例#1
0
        private void ClearCookieUserSession()
        {
            CookieUser u = Cookies.User;

            u.ui         = null;
            u.s          = null;
            Cookies.User = u;
        }
示例#2
0
        public ActionResult Index()
        {
            var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (cookie != null)
            {
                var        ticket = FormsAuthentication.Decrypt(cookie.Value);
                CookieUser user   = JsonConvert.DeserializeObject <CookieUser>(ticket.UserData);
                ViewData["uname"] = user.LoginName;
            }
            return(View());
        }
示例#3
0
        public ActionResult Index()
        {
            ActionResult returnAction = View();

            // Verify user had admin rights
            CookieUser cUser = Newtonsoft.Json.JsonConvert.DeserializeObject <CookieUser>(Request.Cookies[Constants._COOKIE_NAME_].Value);

            if (!MyUserService.ValidateUserAdmin(cUser.UserToken))
            {
                returnAction = RedirectToAction("Logout", "Account");
            }

            return(returnAction);
        }
示例#4
0
        public ActionResult Login(InputUser user, string returnUrl)
        {
            LoginResponse response = UserApiProxy.ValidateUser(SSConfiguration.WebApiUrl, user.Email, user.Password);

            if (response.Success)
            {
                // Setup our cookies
                FormsAuthentication.SetAuthCookie(response.UserToken.ToString(), true);

                CookieUser cUser = new CookieUser();
                cUser.UserId    = response.User.Id;
                cUser.UserName  = response.User.Username;
                cUser.UserToken = response.UserToken.ToString();

                HttpCookie sacredCookie = new HttpCookie(Constants._COOKIE_NAME_);
                sacredCookie.Value   = Newtonsoft.Json.JsonConvert.SerializeObject(cUser);
                sacredCookie.Expires = DateTime.Now.AddDays(3.0);
                Response.Cookies.Add(sacredCookie);

                // Setup our session variables
                SessionInfo.UserId    = response.User.Id.ToString();
                SessionInfo.UserToken = response.UserToken.ToString();

                if (response.AutoLogoutInMinutes > 0)
                {
                    Session.Timeout = response.AutoLogoutInMinutes;
                }

                // Redirect to url or user profile
                if (returnUrl != null && Url.IsLocalUrl(returnUrl))
                {
                    return(Redirect(returnUrl));
                }
                else
                {
                    return(RedirectToAction("Profile", "User", new { id = response.User.Id }));
                }
            }
            else
            {
                user.Errors = new List <string>();
                user.Errors.Add(response.Message);
            }

            return(View(user));
        }
示例#5
0
        private void AddUserToCookies(Users user, SignInRequest signInRequest, SignInResponse signInResponse)
        {
            CookieUser cu = new CookieUser
            {
                u = user.Username
            };

            if (signInRequest.KeepMeSignIn)
            {
                var r = StaticFunctions.Request(
                    "Members/CreateSession/" + user.Uuid,
                    "",
                    HttpMethod.Post,
                    signInResponse.Token
                    );

                Sessions sessions = JsonConvert.DeserializeObject <Sessions>(r);
                cu.s  = sessions.Suid;
                cu.ui = sessions.Uuid;
            }

            Cookies.User = cu;
        }
示例#6
0
        public ActionResult SignIn(AuthenticationUserVM authUserVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    User user = _authUserLogic.TryAuthentication(authUserVM.Login, authUserVM.Password);
                    if (user != null)
                    {
                        CookieUser cookieUser = PLAutomapper.Mapper.Map <CookieUser>(user);

                        var encTicket = FormsAuthentication.Encrypt(
                            new FormsAuthenticationTicket(
                                1,
                                "name",
                                DateTime.Now,
                                DateTime.Now.Add(FormsAuthentication.Timeout),
                                false,
                                JsonConvert.SerializeObject(cookieUser))
                            );
                        HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
                        Response.Cookies.Add(faCookie);

                        return(RedirectToAction("Search", "Report"));
                    }

                    ModelState.AddModelError("Login", "You entered incorrect passord or login doesn't exist");
                }

                return(View(authUserVM));
            }
            catch (Exception e)
            {
                _customLogger.RecordError(e);
                return(new HttpStatusCodeResult(500));
            }
        }