Copied to clipboard

Flag this post as spam?

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


  • Bunnynut 136 posts 318 karma points
    Jun 13, 2014 @ 14:16
    Bunnynut
    0

    Unable to login user in frontend

    Hello,

     

    Im having a weird problem in an old website running on Umbraco umbraco v 4.0.4.1. Logging in users does not seem to work anymore. I use the following code to log in a user:

            string hashedPassword = AmatecWebsite.Extensions.Clients.ClientRepository.verifyHash(txtEmail.Text, txtPassword.Text);
            Member m = Member.GetMemberFromLoginNameAndPassword(txtEmail.Text, hashedPassword);

            if (m != null && txtEmail.Text != string.Empty && txtPassword.Text != string.Empty && hashedPassword != string.Empty)
            {
               
                //HttpContext.Current.Response.Write("ja" + ContinueUrl);
                Member.AddMemberToCache(m);
              
                //Add the shopping cart if the client has one
                string sSessionID = OrderManagement.SpecialSessionID();
                SessionHandler.CurrentClientID = m.Id;

            }

    Funny thing is is that logging in as actully succesful but it doesnt seem to be able to remember. So GetMemberFromLoginNameAndPassword actually returns a Member object but IsAuthenticated is always false and so umbraco.library.IsLoggedON() is also always false.

    Does anyone know how i shoudl remeber the user?

    thanks in advance.

  • Bunnynut 136 posts 318 karma points
    Jun 16, 2014 @ 16:07
    Bunnynut
    0

    shameless bump

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 10x admin c-trib
    Jun 16, 2014 @ 16:20
    Dave Woestenborghs
    0

    I think you also need to set the authentication cookie after logging in.

    FormsAuthentication.SetAuthCookie(txtEmail.Text,true);

    Dave

     

     

  • Bunnynut 136 posts 318 karma points
    Jun 16, 2014 @ 16:36
    Bunnynut
    0

    Hi Dawoe,

    Thank you for your reply, i will try your suggestion and get back to with the result.

  • Bunnynut 136 posts 318 karma points
    Jun 16, 2014 @ 20:14
    Bunnynut
    0

    That also doesnt seem to help, any other ideas?

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 10x admin c-trib
    Jun 16, 2014 @ 20:54
    Dave Woestenborghs
    0

    Looking at this page : http://24days.in/umbraco/2012/creating-a-login-form-with-umbraco-mvc-surfacecontroller

    I see it uses MemberShip.ValidateUser. You will probably need to call that too.

    Dave

  • Bunnynut 136 posts 318 karma points
    Jun 17, 2014 @ 21:02
    Bunnynut
    0

    Hi Dave,

    I have also added the line Membership.ValidateUser which returns true, but still umbraco.library:IsLoggedOn() returns false.

    I had a userControl with a standard textbox and password field to enable the user to login.

    i have now changed this to a standard ASP.Net Login Control and i use the following code to login:
            <asp:Login ID="login" runat="server" DisplayRememberMe="false" LoginButtonText="Login" LoginButtonStyle-CssClass="knop rechts" OnLoggingIn="Login_OnLoggingIn">

            </asp:Login>


        protected void Login_OnLoggingIn(object sender, EventArgs e)
        {
            string hashedPassword = AmatecWebsite.Extensions.Clients.ClientRepository.verifyHash(login.UserName, login.Password);
            Member m = Member.GetMemberFromLoginNameAndPassword(login.UserName, hashedPassword);
            bool validate = Membership.ValidateUser(login.UserName, hashedPassword);
            if (m != null && login.UserName != string.Empty && login.Password != string.Empty && hashedPassword != string.Empty)
            {
                Member.AddMemberToCache(m);
                FormsAuthentication.SetAuthCookie(login.UserName, true);
                string sSessionID = OrderManagement.SpecialSessionID();
                SessionHandler.CurrentClientID = m.Id;

                ShoppingCart.MergeShoppingCarts(sSessionID, m.Id);
                AmatecWebsite.Extensions.Orders.ShoppingCartManagement.UpdateItemsInShoppingCartMini();

                FormsAuthentication.RedirectFromLoginPage(login.UserName, true);
            }

    But still umbraco.library:IsLoggedOn is always false.

    It almost seems like i should be looking somewhere else?

  • Bunnynut 136 posts 318 karma points
    Jun 17, 2014 @ 22:59
    Bunnynut
    0

    As the line in my previous suggested: i had to look somewhere else.

    My web.config was missing: <authentication mode="Forms" />
    When i added that everything worked as it should.

    Thanks Dave for your help.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies