Overwrite the Login function to add custom code

Posted by Community Admin on 04-Aug-2018 16:38

Overwrite the Login function to add custom code

All Replies

Posted by Community Admin on 16-Nov-2011 00:00

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?

Posted by Community Admin on 17-Nov-2011 00:00

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

Posted by Community Admin on 21-Nov-2011 00:00

Could you provide me with the code of the login control widget?
Otherwise I have to rewrite it to get my custom code executed.

Posted by Community Admin on 21-Nov-2011 00:00

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

Posted by Community Admin on 09-Dec-2012 00:00

Hi, following up on this question .... how can I access the username provided after successful authentication??

Posted by Community Admin on 10-Dec-2012 00:00

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?

Posted by Community Admin on 14-Dec-2012 00:00

For claims based you inherit Telerik.Sitefinity.Web.UI.PublicControls.LoginWidget

But there are not the same nor similar methods to override.

Posted by Community Admin on 19-Dec-2012 00:00

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

Posted by Community Admin on 08-Apr-2013 00:00

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

Posted by Community Admin on 08-Apr-2013 00:00

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

Posted by Community Admin on 08-Apr-2013 00:00

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

Posted by Community Admin on 28-Nov-2013 00:00

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



�$�

Posted by Community Admin on 03-Dec-2013 00:00

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

Posted by Community Admin on 04-Dec-2013 00:00

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? 

Posted by Community Admin on 18-Jan-2015 00:00

 

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 ??

 

 

This thread is closed