+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Getting and Signing in as a user via backend code

Getting and Signing in as a user via backend code

5 posts, 0 answered
  1. Troy Benedict
    Troy Benedict avatar
    37 posts
    Registered:
    29 Apr 2009
    29 Jun
    Link to this post
    Our business works with many clients who are users of our Sitefinity system.  Occasionally, we receive inquires from our customers who are having issues completing requests, and it'd be helpful for certain support staff to be able to emulate the customer's view by logging in as them, once permission is given by the customer.

     

    I am able to successfully retrieve the UserGuid for a specific customer, but I'm looking for the process of using the code that once the customer's UserGuid is identified, that it would sign-out the current employee's account, and sign-in as the customer account. 

     

    Once our staff assist's their customer with their issue, it is policy for the user to sign out, and log back in as themselves.

    Thanks!

  2. Pavel Benov
    Pavel Benov avatar
    21 posts
    Registered:
    26 Aug 2016
    04 Jul
    Link to this post
    Hi Troy,

    You can check the following forum thread where a similar question has been discussed:

    http://www.sitefinity.com/developer-network/forums/developing-with-sitefinity-/sitefinity-6-x-impersonation

    And for logging out users via API you can check the following:

    http://docs.sitefinity.com/for-developers-authentication-sign-out-api

    Regards,
    Pavel Benov
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Troy Benedict
    Troy Benedict avatar
    37 posts
    Registered:
    29 Apr 2009
    21 Jul in reply to Pavel Benov
    Link to this post
    Thanks for your help.  This helped allow us to sign in as a customer.  However, I noticed something odd.  Everytime this action was performed, that user's "is_backend_user" variable in the sf_users was changed from false to true! 

     

    I'm using the code below to authenticate the user.  Is there something I can do to prevent the customer from being granted this privilege that we certainly don't want them to have?  Thanks! 

    UserLoggingReason result = SecurityManager.AuthenticateUser("OpenAccessMembership37Provider", membershipUser.UserName.ToString(), true, out membershipUser);
                       

  4. Troy Benedict
    Troy Benedict avatar
    37 posts
    Registered:
    29 Apr 2009
    21 Jul in reply to Troy Benedict
    Link to this post

    I resolved this issue in the post above.  When I imported users from our Sitefinity 3.7 site, it gave all users backend access.  I simply updated the sf_users is_backend_user to 0 via SQL Server.  I didn't realize that users still had the Backend Users" role associated.  When I authenticated the user I guess it reapplied the is_backend_user flag to true.  Removing that role prevented this from happening again.

     

    On a related note, I noticed that when a user is created via the dashboard module, it automatically has the backend user checkbox checked.  Is there a way to uncheck that by default, just in the event that an employee creates an account for a customer and doesn't uncheck the box.  Thanks!

  5. Telerik Admin
    Telerik Admin avatar
    188 posts
    Registered:
    02 Oct 2004
    26 Jul
    Link to this post

    Hi Troy,

    Sitefinity expects that backend user creation screen will most frequently be used to create backend users and therefore the option is checked by default. To fix this a customization on the UserNew.ascx template needs to be done. This template is used by the NewUserDialog control that is working on the backend.

    You can get the template from our SDK repository: https://github.com/Sitefinity-SDK/SitefinityResources Once you get the template add it in your project and alter the setCheckBoxes and ClearForm functions to set the default value of the "This user can access site backend" to false.

    I have attached a sample template for your convenience (note that this one is from Sitefinity 9.0). You also need to map the customized template via the ViewMap: http://www.sitefinity.com/blogs/team-blog/2011/07/26/customizing_sitefinity_4_controls_with_the_viewmap

    For the new entry you will need to populated the following:

    HostType: Telerik.Sitefinity.Security.Web.UI.Principals

    LayoutTemplatePath: Relative path to the customized template.

    Regards,

    Pavel Benov

5 posts, 0 answered