Copied to clipboard

Flag this post as spam?

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


  • Tom 713 posts 952 karma points
    Mar 08, 2011 @ 00:45
    Tom
    0

    Log in to backend when logging in to front end

    Hi Guys,

    I am going to set it up so when a member logs in to the front end, if there is a user in the backend with the same username and password i log them in to the front end so they can get a list of docs to preview with front-end livery etc..

     

    yes it is reinventing the wheel!

     

    but just wondering could i do something like this:?

     

    public partial class LoginUserControl : BasePage
    protected void MemberLogin_OnLoggedIn(object sender, System.EventArgs e)
            {
                var member = Member.GetCurrentMember();
    
                //if the member is a content admin person then attempt to log them in to the back-end
                if ((member != null) && (member.Id > 0) && Roles.GetRolesForUser(member.LoginName).Any(r => ContentEditorRoleNames.Contains(r)))
                {
                    // Authenticate users by using the provider specified in umbracoSettings.config
                    if (Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].ValidateUser(MemberLogin.UserName, MemberLogin.Password))
                    {
                        if (Membership.Providers[UmbracoSettings.DefaultBackofficeProvider] is ActiveDirectoryMembershipProvider)
                            ActiveDirectoryMapping(MemberLogin.UserName, Membership.Providers[UmbracoSettings.DefaultBackofficeProvider].GetUser(MemberLogin.UserName, false).Email);
    
                        umbraco.BusinessLogic.User u = new User(MemberLogin.UserName);
                        doLogin(u);
                    }
                    else
                    {
    #warning report some exception about not logging someone in to the back-end
                    }
                }
            }
    
            /// <summary>
            /// Maps active directory account to umbraco user account
            /// </summary>
            /// <param name="loginName">Name of the login.</param>
            private void ActiveDirectoryMapping(string loginName, string email)
            {
                // Password is not copied over because it is stored in active directory for security!
                // The user is create with default access to content and as a writer user type
                if (umbraco.BusinessLogic.User.getUserId(loginName) == -1)
                {
                    umbraco.BusinessLogic.User.MakeNew(loginName, loginName, string.Empty, email, umbraco.BusinessLogic.UserType.GetUserType(2));
                    umbraco.BusinessLogic.User u = new umbraco.BusinessLogic.User(loginName);
                    u.addApplication("content");
                }
            }
    
            string[] ContentEditorRoleNames = new[] { "Content Editor", "Content Approver", "Administrator" };
  • Tom 713 posts 952 karma points
    Mar 08, 2011 @ 01:10
    Tom
    0

    Member.GetCurrentMember() is null at this point.. is there any way to retrieve the active member?

     

    wow microsoft's response is use: var member = Membership.GetUser(MemberLogin.UserName);

     

    in the OnLoggedIn event because the cookie hasn't been set yet for auth..

    ok.. feels a bit dirty but ok..

  • 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