Exemplo n.º 1
0
 public override void OnActionExecuting(ActionExecutingContext filterContext)
 {
     try
     {
         if (Global.IsLoggedIn)
         {
             return;
         }
         if (filterContext.HttpContext.User.Identity == null)
         {
             return;
         }
         if (filterContext.HttpContext.User.Identity is FormsIdentity)
         {
             var id     = filterContext.HttpContext.User.Identity as FormsIdentity;
             var ticket = id.Ticket;
             if (!ticket.IsPersistent)
             {
                 return;
             }
             var userdata = new TicketUserData(ticket.UserData);
             Global.TrySignIn(userdata.UserName, userdata.Password, true);
         }
     }
     catch
     {
         return;
     }
 }
Exemplo n.º 2
0
        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
            if (Context.User == null)
            {
                // Not logined
                return;
            }
            var formsIdentity = Context.User.Identity as FormsIdentity;

            if (formsIdentity == null)
            {
                return;
            }
            try
            {
                TicketUserData userData = TicketUserData.FromString(formsIdentity.Ticket.UserData);
                if (Context.User != null)
                {
                    Context.User = new GenericPrincipal(Context.User.Identity, new[] { userData.UserRole.ToString() });
                }
            }
            catch
            {
                return;
            }
        }
Exemplo n.º 3
0
 public ActionResult UserProfilePost(UserProfileVM userProfile)
 {
     if (!ModelState.IsValid)
     {
         return(View(userProfile));
     }
     try
     {
         var userData = TicketUserData.FromContext(HttpContext);
         var command  = new UpdateUserCommand
         {
             Email     = userProfile.Email,
             FirstName = userProfile.FirstName,
             LastName  = userProfile.LastName,
             Password  = userProfile.Password,
             Phone     = userProfile.Phone,
             UserId    = userData.UserId
         };
         pipelineService.HandleCommand(command);
     }
     catch (DomainException ex)
     {
         ModelState.AddModelError(string.Empty, ex);
         return(View(userProfile));
     }
     return(Redirect("~"));
 }
Exemplo n.º 4
0
        public ActionResult UserProfile()
        {
            TicketUserData userData = TicketUserData.FromContext(HttpContext);
            User           user     = userQueries.GetById(userData.UserId);

            return(View(new UserProfileVM(user)));
        }
Exemplo n.º 5
0
        private void AddCookieAndRedirect(User user)
        {
            var customData = new TicketUserData {
                UserId = user.Id, UserRole = user.Role
            };
            var expiration = DateTime.Now.AddDays(1);
            var ticket     = new FormsAuthenticationTicket(1, user.Email, DateTime.Now, expiration, false, customData.ToString());
            var cookie     = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket));

            Response.Cookies.Add(cookie);
        }
Exemplo n.º 6
0
        public static string GetStructuredUserData(IPrincipal user, TicketUserData keyName)
        {
            var ticketData = GetStructuredUserData(user);

            return(ticketData[keyName.ToString()]);
        }
Exemplo n.º 7
0
 public static string GetStructuredUserData(IPrincipal user, TicketUserData keyName)
 {
     var ticketData = GetStructuredUserData(user);
     return ticketData[keyName.ToString()];
 }