public void SignIn(IrisUser user, bool createPersistentCookie)
        {
            if (user == null)
                throw new ArgumentNullException("user");

            var cookie = new IrisCookie
            {
                UserName = user.UserName,
                RememberMe = createPersistentCookie,
                Roles = new List<string> { user.Role.Name ?? "user" }
            };

            var userData = JsonConvert.SerializeObject(cookie);

            var ticket = new FormsAuthenticationTicket(1, cookie.UserName, DateTime.Now,
                                                       DateTime.Now.Add(FormsAuthentication.Timeout),
                                                       createPersistentCookie, userData);

            var encTicket = FormsAuthentication.Encrypt(ticket);

            var httpCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)
            {
                HttpOnly = true,
            };

            if (createPersistentCookie)
            {
                httpCookie.Expires = DateTime.Now.Add(FormsAuthentication.Timeout);
            }

            _httpContext.Response.Cookies.Add(httpCookie);
        }
示例#2
0
        public IrisIdentity(IrisUser user)
        {
            if (user == null)
            {
                AsGuest();
                return;
            }

            UserName = user.UserName;
            //Email = user.Email;
            //FirstName = user.FirstName;
            //LastName = user.LastName;
            //Name = string.IsNullOrWhiteSpace(UserName) 
            //           ? user.Email
            //           : string.Format("{0} {1}", FirstName, LastName);

            Name = UserName;

            //try
            //{
            //    TimeZone = TimeZoneInfo.FindSystemTimeZoneById(user.TimeZone);
            //}
            //catch (Exception)
            //{
            //    TimeZone = TimeZoneInfo.Utc;
            //}

            Roles = new List<string> { user.Role.Name ?? "user" };
        }
        public IrisIdentity(IrisUser user)
        {
            if (user == null)
            {
                AsGuest();
                return;
            }

            UserName = user.UserName;
            //Email = user.Email;
            //FirstName = user.FirstName;
            //LastName = user.LastName;
            //Name = string.IsNullOrWhiteSpace(UserName)
            //           ? user.Email
            //           : string.Format("{0} {1}", FirstName, LastName);

            Name = UserName;

            //try
            //{
            //    TimeZone = TimeZoneInfo.FindSystemTimeZoneById(user.TimeZone);
            //}
            //catch (Exception)
            //{
            //    TimeZone = TimeZoneInfo.Utc;
            //}

            Roles = new List <string> {
                user.Role.Name ?? "user"
            };
        }
示例#4
0
        public void SignIn(IrisUser user, bool createPersistentCookie)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            var cookie = new IrisCookie
            {
                UserName   = user.UserName,
                RememberMe = createPersistentCookie,
                Roles      = new List <string> {
                    user.Role.Name ?? "user"
                }
            };

            var userData = JsonConvert.SerializeObject(cookie);

            var ticket = new FormsAuthenticationTicket(1, cookie.UserName, DateTime.Now,
                                                       DateTime.Now.Add(FormsAuthentication.Timeout),
                                                       createPersistentCookie, userData);

            var encTicket = FormsAuthentication.Encrypt(ticket);

            var httpCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)
            {
                HttpOnly = true,
            };

            if (createPersistentCookie)
            {
                httpCookie.Expires = DateTime.Now.Add(FormsAuthentication.Timeout);
            }

            _httpContext.Response.Cookies.Add(httpCookie);
        }