Exemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        IUserProfile            UserProfileObj = new UserProfile();
        UserProfileMenuResponse ProfileMenu    = new UserProfileMenuResponse();

        try
        {
            ProfileMenu.IsProfileAvailable = false;
            if (CookieProxy.Instance().HasKey("t"))
            {
                UserProfileObj.SetToken(CookieProxy.Instance().GetValue("t").ToString());
                if (CookieProxy.Instance().HasKey("um"))
                {
                    ProfileMenu = new UserActions(UserProfileObj).GetProfileMenu(CookieProxy.Instance().GetValue("um").ToString());
                }
                else
                {
                    ProfileMenu = new UserActions(UserProfileObj).GetProfileMenu(null);
                }
                if (ProfileMenu.ShouldReupdate)
                {
                    RemoveProfileCookie();
                    ProfileMenu = new UserActions(null).GetProfileMenu(null);
                }
                CookieProxy.Instance().SetValue("um", new JavaScriptSerializer().Serialize(ProfileMenu), DateTime.Now.AddDays(2));
            }
        }
        catch (Exception ex)
        {
            ProfileMenu.IsProfileAvailable = false;
        }

        Response.Write(new JavaScriptSerializer().Serialize(ProfileMenu));
    }
Exemplo n.º 2
0
        public UserProfileMenuResponse GetProfileMenu(string CookieMenu)
        {
            UserProfileMenuResponse ProfileMenu = new UserProfileMenuResponse();
            bool   ShouldFetchProfileFromServer = false;
            string Token = UserProfileObj.GetToken();

            try
            {
                // check if token exists
                if (Token == null)
                {
                    ProfileMenu.IsProfileAvailable = false;
                    return(ProfileMenu);
                }
                else
                {
                    bool response = new Security(UserProfileObj).AuthenticateUser();
                    if (response == false)
                    {
                        ProfileMenu.IsProfileAvailable = false;
                        return(ProfileMenu);
                    }
                    else
                    {
                        if (CookieMenu == null)
                        {
                            ShouldFetchProfileFromServer = true;
                        }
                        else
                        {
                            ProfileMenu = new JavaScriptSerializer().Deserialize <UserProfileMenuResponse>(CookieMenu);
                            if (ProfileMenu.IsProfileAvailable == false)
                            {
                                ShouldFetchProfileFromServer = true;
                            }
                        }
                    }
                }
                // get the profile menu
                if (CookieMenu == null)
                {
                    ShouldFetchProfileFromServer = true;
                }
                else
                {
                    ProfileMenu = new JavaScriptSerializer().Deserialize <UserProfileMenuResponse>(CookieMenu);
                    if (ProfileMenu.ShouldReupdate)
                    {
                        ShouldFetchProfileFromServer = true;
                    }
                }
                if (ShouldFetchProfileFromServer)
                {
                    ProfileMenu.SetUserProfile(new NormalUserTemplate(UserProfileObj).FetchParticularProfile(UserProfileObj));
                    ProfileMenu.IsProfileAvailable = true;
                }
            }
            catch (Exception ex)
            {
                Logger.Instance().Log(Fatal.Instance(), ex);
                ProfileMenu.IsProfileAvailable = false;
                throw ex;
            }

            return(ProfileMenu);
        }