Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Biagio Paruolo 1619 posts 1912 karma points c-trib
    May 06, 2014 @ 22:29
    Biagio Paruolo
    0

    Membership and Member: How retrieve info using one class?

    I need to read membertype from username. Till now, I use this code, but I don't like that I need to read data from two class as Membership and Member.

    Is it possible to read data from one class?

    @{

      var isSubmitLogin = (IsPost && Request["submit"]=="login");

      var isSubmitLogout = (IsPost && Request["submit"]=="logout");

      var currentUser = Membership.GetUser();

      var currentMember = Member.GetCurrentMember();

      var requestedUrl = Request.Url.PathAndQuery.ToString(); // Model.Url;

      if (Request["ReturnUrl"]!=null)  {

        requestedUrl = Request["ReturnUrl"];

      }

      if (currentUser!=null)

       {    

        if (!isSubmitLogout)

         {

        @Message("Logged in : " + currentUser.UserName)

                 @LogoutForm()

    if (currentMember!=null)

            {

                if(@currentMember.ContentType.Alias.ToString()=="Customer") 

                {

                  Response.Redirect("/");

                }

            }

      Response.Redirect("/my-zone");

         }

        else

         {

           FormsAuthentication.SignOut();

           FormsAuthentication.RedirectToLoginPage();

         } 

       }

      if (currentUser==null)

       {

        if (!isSubmitLogin)  

         {

           @LoginForm()

          }

        else

         {

          string username=Request["username"];

          string password=Request["password"];

          if (Membership.ValidateUser(username, password))

          {

            // RedirectFromLoginPage does not work that good within the Umbraco context

            // FormsAuthentication.RedirectFromLoginPage(username, true);

     

            FormsAuthentication.SetAuthCookie(username, true);

     

            // Redirect to / refresh the requested page

            Response.Redirect(requestedUrl);

          }

          else

          {

            @Message("Login failed for " + username)

            @LoginForm()

          }

         }       

        }

      }

Please Sign in or register to post replies

Write your reply to:

Draft