Пример #1
0
        public static RestaurantUserIdentity GetRestaurantUserIdentityFromCookie(HttpCookie cookie)
        {
            var identity = (RestaurantUserIdentity)null;

            if (cookie != null && cookie.Name == FormsAuthentication.FormsCookieName && cookie.Value != null)
            {
                var ticket = FormsAuthentication.Decrypt(cookie.Value);
                if (ticket != null)
                {
                    dynamic userdata = null;
                    try
                    {
                        userdata = DeserializeUserData(ticket.UserData);
                    }
                    // ReSharper disable EmptyGeneralCatchClause
                    catch { }
                    // ReSharper restore EmptyGeneralCatchClause
                    if (userdata != null)
                    {
                        var authenticationtype = GetAuthenticationTypeForRestaurantUser(userdata.UserId);
                        if ((int)authenticationtype > -1)
                        {
                            identity = new RestaurantUserIdentity(
                                ticket.Name,
                                authenticationtype,
                                true, //if we are this far then the user is obviously authenticated
                                userdata.UserId,
                                userdata.FriendlyName,
                                userdata.UserGuid
                                );
                        }
                    }
                }
            }
            return(identity);
        }
 public static RestaurantUserIdentity GetRestaurantUserIdentityFromCookie(HttpCookie cookie)
 {
     var identity = (RestaurantUserIdentity)null;
     if (cookie != null && cookie.Name == FormsAuthentication.FormsCookieName && cookie.Value != null)
     {
         var ticket = FormsAuthentication.Decrypt(cookie.Value);
         if (ticket != null)
         {
             dynamic userdata = null;
             try
             {
                 userdata = DeserializeUserData(ticket.UserData);
             }
             // ReSharper disable EmptyGeneralCatchClause
             catch { }
             // ReSharper restore EmptyGeneralCatchClause
             if (userdata != null)
             {
                 var authenticationtype = GetAuthenticationTypeForRestaurantUser(userdata.UserId);
                 if ((int)authenticationtype > -1)
                     identity = new RestaurantUserIdentity(
                         ticket.Name,
                         authenticationtype,
                         true, //if we are this far then the user is obviously authenticated
                         userdata.UserId,
                         userdata.FriendlyName,
                         userdata.UserGuid
                         );
             }
         }
     }
     return identity;
 }