Ejemplo n.º 1
0
        public void SignIn(User user, bool createPersistentCookie)
        {
            var now = DateTime.Now.ToLocalTime();

            var ticket = new FormsAuthenticationTicket(
                1 /*version*/,
                user.Email,
                now,
                now.Add(ExpirationTimeSpan),
                createPersistentCookie,
                user.Email,
                FormsAuthentication.FormsCookiePath);

            var encryptedTicket = FormsAuthentication.Encrypt(ticket);

            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
            cookie.HttpOnly = true;
            cookie.Secure = FormsAuthentication.RequireSSL;
            cookie.Path = FormsAuthentication.FormsCookiePath;
            if (FormsAuthentication.CookieDomain != null)
            {
                cookie.Domain = FormsAuthentication.CookieDomain;
            }

            httpContext.Response.Cookies.Add(cookie);
            cachedUser = user;
        }
Ejemplo n.º 2
0
        public User GetAuthenticatedUser()
        {
            if (cachedUser != null)
                return cachedUser;

            if (httpContext == null ||
                httpContext.Request == null ||
                !httpContext.Request.IsAuthenticated ||
                !(httpContext.User.Identity is FormsIdentity))
            {
                return null;
            }

            var formsIdentity = (FormsIdentity)httpContext.User.Identity;
            var usernameOrEmail = formsIdentity.Ticket.UserData;

            if (String.IsNullOrWhiteSpace(usernameOrEmail))
                return null;
            var user = userService.GetUserByEmail(usernameOrEmail);
            if (user != null && user.IsApproved)
                cachedUser = user;
            return cachedUser;
        }
Ejemplo n.º 3
0
 public void SetUsername(User user, string newUsername)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 4
0
 public void SignOut()
 {
     cachedUser = null;
     FormsAuthentication.SignOut();
 }
Ejemplo n.º 5
0
 public void SetEmail(User user, string newEmail)
 {
     throw new NotImplementedException();
 }