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

Forums / Developing with Sitefinity / Overwrite the Login function to add custom code

Overwrite the Login function to add custom code

15 posts, 0 answered
  1. Erik
    Erik avatar
    8 posts
    Registered:
    02 Nov 2010
    16 Nov 2011
    Link to this post
    I want to add some custom code during the login function for my frontend users.
    Now I would like to execute some code and get the customers data from a webserver when the customer signs in.
    So I have to overwrite the onlogin function and also add some custom profile fields on the code side.

    Do I have to create my own control and widget or can I use the given one and overwrite it.

    Has someone done something similar already and can provide me some sample code?
  2. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    25 Nov 2016
    17 Nov 2011
    Link to this post
    Hi Erik,

    You can inherit from the public login control (Telerik.Sitefinity.Web.UI.PublicControls.LoginControl)and override its virtual methods where you can inject your logic. You can override LoginForm_Authenticate and after the base execute your logic.

    Greetings,
    Ivan Dimitrov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. Erik
    Erik avatar
    8 posts
    Registered:
    02 Nov 2010
    21 Nov 2011
    Link to this post
    Could you provide me with the code of the login control widget?
    Otherwise I have to rewrite it to get my custom code executed.
  4. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    06 Dec 2016
    21 Nov 2011
    Link to this post
    Hi Erik,

    The approach with overriding LoginForm_Authenticate is to create a class in your project and inherit from Telerik.Sitefinity.Web.UI.PublicControls.LoginControl. Place this as a .cs file in your project and register as a new custom control. Go to Administration->Settings->Advanced->Toolboxes choose at which section to register and use Namespace.Class for registration. When you inherit the template for the control will be the same and you will just tweak the logic.
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
     
    namespace SitefinityWebApp.Custom
    {
        public class Class1 : Telerik.Sitefinity.Web.UI.PublicControls.LoginControl
        {
            protected override void LoginForm_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e)
            {
                base.LoginForm_Authenticate(sender, e);
            }
        }
    }
    Register with SitefinityWebApp.Custom.Class1 in my case (namespace class).
    The approach with Global.asax will not be valid in the case.

    Kind regards,
    Stanislav Velikov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  5. Eric
    Eric avatar
    4 posts
    Registered:
    18 Oct 2012
    09 Dec 2012 in reply to Stanislav Velikov
    Link to this post
    Hi, following up on this question .... how can I access the username provided after successful authentication??
  6. Keith
    Keith avatar
    3 posts
    Registered:
    12 Sep 2012
    10 Dec 2012
    Link to this post
    When I try to to add my new control to the page, I get an error:

    Login (backward compatibility) widget is not compatible with Claims Authentication mode, use Login instead. Learn more in our documentation 

    Is there a separate control that I need to overwrite for Claims based auth?
  7. Marvin
    Marvin avatar
    1 posts
    Registered:
    13 Nov 2012
    14 Dec 2012
    Link to this post
    For claims based you inherit Telerik.Sitefinity.Web.UI.PublicControls.LoginWidget

    But there are not the same nor similar methods to override.
  8. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    06 Dec 2016
    19 Dec 2012
    Link to this post
    Hi,

    As the previous reply was written before the introduction of claims based authentication so as for sitefinity version 5.0 to 5.3 (the current version) there are two login controls
    The legacy login control for forms authenticationTelerik.Sitefinity.Web.UI.PublicControls.LoginControl
    Claims login widget:
    Telerik.Sitefinity.Web.UI.PublicControls.LoginWidget

    @Erick to retreive the currently logged in user use
    //retreives the current user ID
               var userId = ClaimsManager.GetCurrentUserId();
               //using the UserManager the retreived ID can be used to get the user object
               UserManager manager = UserManager.GetManager();
               var currentUser = manager.GetUser(userId);
               var userMail = currentUser.Email;
               //password will return the hashed password
               var password = currentUser.Password;

    Greetings,
    Stanislav Velikov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  9. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    06 Dec 2016
    08 Apr 2013
    Link to this post
    Hello,

    I hope the provided solution has helped in achieving this, let me know if additional clarifications are needed, I will be happy to assist further.

    All the best,
    Stanislav Velikov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  10. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    06 Dec 2016
    08 Apr 2013
    Link to this post
    Hello,

    I hope the provided solution has helped in achieving this, let me know if additional clarifications are needed, I will be happy to assist further.

    All the best,
    Stanislav Velikov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  11. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    06 Dec 2016
    08 Apr 2013
    Link to this post
    Hello,

    I hope the provided solution has helped in achieving this, let me know if additional clarifications are needed, I will be happy to assist further.

    All the best,
    Stanislav Velikov
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  12. Neha
    Neha avatar
    7 posts
    Registered:
    21 May 2013
    28 Nov 2013 in reply to Stanislav Velikov
    Link to this post
    Hi Stanislav,
    my issue is little different, i want your help here i am stuck. 


    i have created one web service integrated with sitefinity and i want to write code for  sitefinity login using sitefinity admin credential means i want to login programmatically  with sitefinity admin credentials.but outside the web service . 
    i have write one function but it returns me 2 from LoginSitefinityUser () function of sitefinity
     that menas loggin not succeded..:( 

     code implemented:
    Public Function Loggedin(ByVal username As String, ByVal password As String) As Integer
            username = System.Configuration.ConfigurationManager.AppSettings.Get("UserID")
            password = System.Configuration.ConfigurationManager.AppSettings.Get("Password") 
    // set admin credentials in web.config
     Return LoginSitefinityUser(username, password)
    End Function

     then called it to my web method, there i want it should return 1 i.e. login succeed but its not.
    please advise its on priority?
     
    or tell me how can i programmatically  login in sitefinity manager not manually?

    thanks in advance!













    login outside of the Web Service using the
    credentials



    �$�













    login outside of the Web Service using the
    credentials



    �$�













    login outside of the Web Service using the
    credentials



    �$�













    login outside of the Web Service using the
    credentials



    �$�
  13. Stanislav Velikov
    Stanislav Velikov avatar
    1113 posts
    Registered:
    06 Dec 2016
    03 Dec 2013
    Link to this post
    Hello,

    If the web service is executed from outside sitefintiy API can`t be used to authenticate the user and in this case the user must be logged in using http requests without touching sitefinity API as sampled in this blog post.

    Using Sitefintiy API to authenticate a user use the below static method
    SecurityManager.AuthenticateUser("Default", "username", "password", True)
    "Default" is the membership provider for the site, by default its name is "Default"
    the second and third parameters are username and password of the user, the last parameter is if the user authentication cookie must be persisted even when the user closes the browser (the case when set to True) and when set to False the user is kept logged in until the user closes the browser or until the login timeout expires. By default a user is kept logged in for two hours this is configurable from Administration->Settings->Advanced->Security in textbox Auth Chookie Timetout.

    To check if a user is logged in or not perform the below query
    Dim userIdentity = ClaimsManager.GetCurrentIdentity()
    Dim isAuthenticated As Boolean = userIdentity.IsAuthenticated

    Regards,
    Stanislav Velikov
    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 Public Issue Tracking system and vote to affect the priority of the items
  14. Neha
    Neha avatar
    7 posts
    Registered:
    21 May 2013
    04 Dec 2013 in reply to Stanislav Velikov
    Link to this post
    means are you saying that, we can't use the how can i identify the SecurityManager.AuthenticateUser() method when web service is executed from outside sitefintiy API for e.f. REST client(my case).

    so, how can i identify the calling user identity.. thanks a lot for your suggested article but in my case i  can't use the token string concept. do you have other option for sitefinity webservice outside calls authentication? 
  15. Anish
    Anish avatar
    1 posts
    Registered:
    07 Jan 2015
    18 Jan 2015
    Link to this post

     

    Hi,

    I am using sitefinity version 7 latest one.

    i am doing custom login and registration implementation.

    Is there sample code available for reference to do custom login and registration in sitefinity

    how set cookie  after user login ??

     

     

15 posts, 0 answered