Overwrite the Login function to add custom code
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?
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
Could you provide me with the code of the login control widget?
Otherwise I have to rewrite it to get my custom code executed.
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);
SitefinityWebApp.Custom
.
Class1
in my case (namespace class).Hi, following up on this question .... how can I access the username provided after successful authentication??
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?
For claims based you inherit Telerik.Sitefinity.Web.UI.PublicControls.LoginWidget
But there are not the same nor similar methods to override.
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 authentication: Telerik.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;
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,
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,
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,
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
�$�
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)
Dim userIdentity = ClaimsManager.GetCurrentIdentity()
Dim isAuthenticated As Boolean = userIdentity.IsAuthenticated
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?
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 ??