Handle Logged In Event

Posted by Community Admin on 05-Aug-2018 19:14

Handle Logged In Event

All Replies

Posted by Community Admin on 09-Jun-2011 00:00

Afternoon all,

I'm new to the 4.1 model of Sitefinity. I would like to override (or handle) an event that fires after a user has logged into Sitefinity. I need to fire some environment specific code that shoves some information into session state.

I could handle this in my membership provider, but I was trying to find a way to isolate this code outside my provider (for reasons of portability in the near future).

Thanks everybody!
Joel

Posted by Community Admin on 13-Jun-2011 00:00

Hi Joel,

There aren't global events that are thrown when a user tries to log in or it gets log out. For the time being I think that you should handle this in your provider.

All the best,
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 13-Jun-2011 00:00

Thanks Ivan!

Sadly, my vendor has built all of their code on top of user controls and obfuscated their code. So I need a page lifecycle in order to properly instanciate their classes.

I've built my own login user control to get around the issue, but I'd like to know: can I add to the existing sitefinity login page? I seem to remember finding the existing codebase in 3.7, but I didn't know if that held thru to 4.1.

If I cannot modify (or add some code) to the existing Sitefinity login page, can I direct all logins to my login page? (I believe that I have tried setting it in the web.config's membership section to no avail, but I'm more than willing to try again).

Thank you sir!
Joel

Posted by Community Admin on 14-Jun-2011 00:00

Hi Joel,

I suppose that you want to modify the backend login control. There are two options

1. Map the external template and subscriber for Authenticate event directly in the ascx

You can simply map the templates for LoginForm and LogoutForm in the backend by going to Administration->Settings->Advanced->Controls>ViewMap->Create new and fill in the fields accordingly(all without the quotes):
for LoginForm:
HostType: Telerik.Sitefinity.Security.Web.UI.LoginForm
LayoutTemplatePath: "relative path to your custom LoginForm.ascx where you have specified the custom paths to the ChangePassword and ForgotPassword pages"

for LogoutForm:
HostType: Telerik.Sitefinity.Security.Web.UI.LogoutForm
LayoutTemplatePath: "relative path to your custom LogoutForm.ascx where you have specified the custom path to the ChangePassword page"


default templates


Copy Code
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI"
    TagPrefix="sitefinity" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI.Fields"
    TagPrefix="sffields" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<%@ Control Language="C#" %>
<sitefinity:ResourceLinks ID="resourcesLinks" runat="server">
    <sitefinity:ResourceFile JavaScriptLibrary="JQuery">
    </sitefinity:ResourceFile>
</sitefinity:ResourceLinks>
 
<sitefinity:ClientLabelManager id="clientLabelManager" runat="server">
    <Labels>
        <sitefinity:ClientLabel ClassId="Labels" Key="SelfLogoutUserConfirm" runat="server" />
        <sitefinity:ClientLabel ClassId="Labels" Key="UserNotSelected" runat="server" />
        <sitefinity:ClientLabel ClassId="Labels" Key="LogoutUserConfirm" runat="server" />
    </Labels>
</sitefinity:ClientLabelManager>
 
<sffields:FormManager runat="server" id="formManager" />
<asp:Panel ID="loginPanel" runat="server">
    <div class="sfForm">
        <div class="sfFormIn">
            <div class="sfLoginShadowTopRight">
            </div>
            <div class="sfLoginShadowBottomLeft">
            </div>
            <h2>
                <asp:Literal ID="LoginTitle" Text="<%$ Resources:Labels, LoginToManage %>" runat="server" />
            </h2>
            <asp:Label runat="server" ID="FailureText" EnableViewState="False" Visible="false"
                CssClass="sfFailure" />        
            <ol>
                <li id="ProvidersHolder" runat="server">
                    <asp:Label ID="ProvidersLabel" Text="<%$ Resources:Labels, Provider %>" AssociatedControlID="ProvidersList"
                        runat="server" CssClass="sfTxtLbl" />
                    <asp:DropDownList ID="ProvidersList" AutoPostBack="false" AccessKey="l" runat="server" />
                </li>
                <li>
                    <asp:Label ID="UserNameLabel" Text="<%$ Resources:Labels, Username %>" AssociatedControlID="UserName"
                        runat="server" CssClass="sfTxtLbl" />
                    <asp:TextBox ID="UserName" AccessKey="u" runat="server" CssClass="sfTxt" />
                    <asp:RequiredFieldValidator ID="UserNameRequired" Display="Dynamic" ControlToValidate="UserName"
                        ValidationGroup="LoginBox" ErrorMessage="<%$ Resources:Labels, UsernameCannotBeEmpty %>"
                        CssClass="sfValidator" runat="server">
                <strong><asp:Literal ID="UserNameRequiredLiteral" runat="server" Text="<%$ Resources:Labels, UsernameCannotBeEmpty %>" /></strong>
                    </asp:RequiredFieldValidator>
                </li>
                <li>
                    <asp:Label ID="PasswordLabel" Text="<%$ Resources:Labels, Password %>" AssociatedControlID="Password"
                        runat="server" CssClass="sfTxtLbl" />
                    <asp:TextBox ID="Password" TextMode="Password" AccessKey="p" runat="server" CssClass="sfTxt" />
                    <asp:RequiredFieldValidator ID="PasswordRequired" Display="Dynamic" ControlToValidate="Password"
                        ValidationGroup="LoginBox" ErrorMessage="<%$ Resources:Labels, PasswordCannotBeEmpty %>"
                        CssClass="sfValidator" runat="server">
                <strong><asp:Literal ID="PasswordRequiredLiteral" runat="server" Text="<%$ Resources:Labels, PasswordCannotBeEmpty %>" /></strong>
                    </asp:RequiredFieldValidator>
                </li>
                <li class="sfCheckBoxWrapper">
                    <asp:CheckBox runat="server" ID="RememberMe" />
                    <asp:Label ID="RememberMeTextLabel" Text="<%$ Resources:Labels, RememberMe %>" AssociatedControlID="RememberMe"
                        runat="server" />
                </li>
            </ol>
            <p class="sfSubmitBtn sfMainFormBtns">
                <asp:LinkButton ID="LoginButton" CommandName="Login" CssClass="sfLinkBtn sfSave"
                    ValidationGroup="LoginBox" runat="server">
                    <strong class="sfLinkBtnIn">
                        <asp:Literal ID="LoginButtonLiteral" runat="server" Text="<%$ Resources:Labels, LoginCaps %>"></asp:Literal>
                    </strong>
                </asp:LinkButton>
                <!-- do not remove this button. It is used for the default form submit (pressing enter) -->
                <div style="display: none;">
                    <asp:Button ID="hiddenSubmitButton" runat="server" CommandName="Login" ValidationGroup="LoginBox" />
                </div>
            </p>       
        </div>
    </div>
</asp:Panel>
<asp:Panel ID="userListPanel" runat="server" Visible="false">
    <div class="sfForm">
        <div class="sfFormIn">
            <div class="sfLoginShadowTopRight"></div>
            <div class="sfLoginShadowBottomLeft"></div>
            <h2><asp:Literal ID="UsersListPanelLoginTitle" Text="<%$ Resources:Labels, LoginToManage %>" runat="server" /></h2>
            <p class="sfNeutral"><asp:Literal ID="userLimitLabel" runat="server" Text="<%$ Resources:Labels, UserLimitLabel%>" /></p>
            <sffields:ChoiceField runat="server" id="userListChoice" RenderChoicesAs="RadioButtons"
                DisplayMode="Write" />
            <p class="sfSubmitBtn sfMainFormBtns">
                <asp:LinkButton ID="logoutButton" runat="server" OnClientClick="return AlertLogOut();" CssClass="sfLinkBtn sfPrimary">
                    <strong class="sfLinkBtnIn">
                        <asp:Literal ID="LogoutButtonLiteral" runat="server" Text="<%$ Resources:Labels, LogoutButtonText%>"></asp:Literal>
                    </strong>
                </asp:LinkButton>
            </p>
        </div>
    </div>
</asp:Panel>
 
<asp:Panel ID="selfLogoffPanel" runat="server" Visible="false">
    <div class="sfForm">
        <div class="sfFormIn">
            <div class="sfLoginShadowTopRight"></div>
            <div class="sfLoginShadowBottomLeft"></div>
            <h2><asp:Literal ID="SelfLogoffPanelLoginTitle" Text="<%$ Resources:Labels, LoginToManage %>" runat="server" /></h2>
            <p class="sfNeutral"><asp:Literal ID="selfLogoffLabel" runat="server" Text="<%$ Resources:Labels, SelfLogoffLabel%>" /></p>
            <p class="sfSubmitBtn sfMainFormBtns">
                <asp:LinkButton ID="selfLogoutButton" runat="server" OnClientClick="return AlertSelfLogOut();" CssClass="sfLinkBtn sfPrimary">
                    <strong class="sfLinkBtnIn">
                        <asp:Literal ID="LogoutOtherUserAndEnterLiteral" runat="server" Text="<%$ Resources:Labels, SelftLogoutButtonText%>"></asp:Literal>
                    </strong>
                </asp:LinkButton>
                <asp:LinkButton ID="selfLogoutCancelButton" runat="server" Text="<%$ Resources:Labels, Cancel%>" CssClass="sfCancel" />
            </p>
        </div>
    </div>
</asp:Panel>
 
<asp:Panel ID="denyLogonPanel" runat="server" Visible="false">
    <div class="sfForm">
        <div class="sfFormIn">
            <div class="sfLoginShadowTopRight"></div>
            <div class="sfLoginShadowBottomLeft"></div>
                <h2><asp:Literal ID="DenyLogonPanelLoginTitle" Text="<%$ Resources:Labels, LoginToManage %>" runat="server" /></h2>
                <p class="sfNeutral"><asp:Literal ID="denyLogonMesage" runat="server" Text="<%$ Resources:Labels, DenyLogonMesage%>" /></p>
                <p><asp:Literal ID="loginRetryMessage" runat="server" Text="<%$ Resources:Labels, LoginRetryMessage%>" /></p>
        </div>
    </div>
</asp:Panel>
 
<asp:PlaceHolder ID="loginLinksHolder" runat="server">
    <div class="sfLoginHelp">
        <asp:Literal ID="HelpTitleLiteral" runat="server" Text="<%$ Resources:Labels, Help %>" />:
        <a id="PasswordRecoveryLink" href="~/Sitefinity/Login/PasswordRecovery" runat="server" onclick="toggleSmtpErrorMessage();">
            <asp:Literal ID="PasswordRecoveryTextLiteral" runat="server" Text="<%$ Resources:Labels, ForgotYourPassword %>" />
        </a>
        <a id="ChangePasswordLink" href="~/Sitefinity/Login/ChangePassword" runat="server" onclick="toggleSmtpErrorMessage();">
            <asp:Literal ID="ChangePasswordTextLiteral" runat="server" Text="<%$ Resources:Labels, ChangePassword %>" />
        </a>
        <a id="CreateUserLink" href="~/Sitefinity/Login/Register" runat="server">
            <asp:Literal ID="RegisterUserTextLiteral" runat="server" Text="<%$ Resources:Labels, Register %>" />
        </a>
        <a id="HelpLink" href="~/Sitefinity/Help/UsersAndRoles/LoggingIn" runat="server">
            <asp:Literal ID="HelpLinkLiteral" runat="server" Text="<%$ Resources:Labels, Help %>" />
        </a>       
    </div>
</asp:PlaceHolder>
 
<div id="smtpNotSetContainer" class="sfNeutral sfDetailedInfo" style="display:none;">  
    <h3>
        <asp:Literal ID="ErrorMessageNoSmtpConfigLiteral" runat="server" Text="<%$ Resources:ErrorMessages, TheSystemHasNotBeenConfiguredToSendEmails %>" />
    </h3>
    <ul>
        <li><asp:Literal ID="ErrorMessageContactAdminToResetYourPasswordLiteral" runat="server" Text="<%$ Resources:ErrorMessages, ContactAnAdministratorToResetYourPasswordManually %>" /></li>
        <li>
            <asp:Literal ID="ErrorOrAskAnAdministratorToConfigureTheSystemLiteral" runat="server" Text="<%$ Resources:ErrorMessages, OrAskAnAdministratorToConfigureThSystem %>" />
            <a href="javascript:void(0)" onclick="toggleVisibility('smtpNotSetSolution')">
                <asp:Literal ID="ErrorMessageSmtpDetailsTitle" runat="server" Text="<%$ Resources:ErrorMessages, Details %>" />
            </a>
        </li>
    </ul>
    <div id="smtpNotSetSolution" class="sfDetailedHowTo" style="display: none; ">
        <p><asp:Literal ID="ErrorMessageSmtpSettingsNotSetLiteral" runat="server" Text="<%$ Resources:ErrorMessages, SmtpSettingsAreNotSet %>" /></p>
        <h3><asp:Literal ID="ErrorMessageHowToSetSmtpLiteral" runat="server" Text="<%$ Resources:ErrorMessages, HowToSetSMTP %>" /></h3>
        <ol>
            <li><asp:Literal ID="Literal20" runat="server" Text="<%$ Resources:ErrorMessages, GoToSettingsConfiguration %>" /></li>
            <li><asp:Literal ID="Literal21" runat="server" Text="<%$ Resources:ErrorMessages, SelectSystemSMTPSettings %>" /></li>
        </ol>
    </div>
</div>
 
<div id="smtpPermissionDeniedContainer" class="sfNeutral sfDetailedInfo" style="display:none;">
    <h3>
        <asp:Literal ID="ErrorMessageTheSysIsNotPermittedToSendEmailsLiteral" runat="server" Text="<%$ Resources:ErrorMessages, TheSystemHasIsNotPermittedToSendEmails %>" />
    </h3>
    <ul>
        <li><asp:Literal ID="ErrorMessageContactAdminToResetYourPasswordSmtpLiteral" runat="server" Text="<%$ Resources:ErrorMessages, ContactAnAdministratorToResetYourPasswordManually %>" /></li>
        <li>
            <asp:Literal ID="ErrorOrAskAnAdministratorToConfigureTheSystemSmtpLiteral" runat="server" Text="<%$ Resources:ErrorMessages, OrAskAnAdministratorToConfigureThSystem %>" />
            <a href="javascript:void(0)" onclick="toggleVisibility('smtpPermissionsDeniedDetails')">
                <asp:Literal ID="ErrorMessageSmtpPermissionDeniedDetailsTitle" runat="server" Text="<%$ Resources:ErrorMessages, Details %>" />
            </a>
        </li>
    </ul>
    <div id="smtpPermissionsDeniedDetails" class="sfDetailedHowTo" style="display: none; ">
        <p><asp:Literal ID="SmtpPermissionErrorMessage" runat="server" /></p>       
    </div>
</div>
 
<asp:HiddenField id="logoutUser" runat="server" value="" />
<asp:HiddenField id="loginTicket" runat="server" value="" />
<asp:HiddenField id="mode" runat="server" value="" />
<asp:HiddenField id="smtpSettingsAreSet" runat="server" value="" />
<asp:HiddenField id="smtpPermissionDenied" runat="server" value="" />
 
<telerik:RadCodeBlock runat="server">
<script type="text/javascript">
 
    var userChoices;
    var smtpSettingsAreSet;
    var smtpPermissionDenied;
 
    function pageLoad()
        userChoices = $find("<%= userListChoice.ClientID %>");
        smtpSettingsAreSet = getBooleanHiddenField("<%= smtpSettingsAreSet.ClientID %>");
        smtpPermissionDenied = getBooleanHiddenField("<%= smtpPermissionDenied.ClientID %>");
    
 
    function getBooleanHiddenField(id)
        var field = $get(id);
 
        if (field !== null && field.value)
            return Boolean.parse(field.value);
        
 
        return false;
    
 
    function toggleVisibility()
        var elem = arguments[0] ? document.getElementById(arguments[0]) : this;
        if (elem.style.display == "block")
            elem.style.display = "none";
        
        else
            elem.style.display = "block";
        
    
 
    function toggleSmtpErrorMessage()
        if (!smtpSettingsAreSet)
            toggleVisibility('smtpNotSetContainer');
         else if (smtpPermissionDenied)
            toggleVisibility('smtpPermissionDeniedContainer');
        
    
 
    function AlertSelfLogOut()
        var clientLabelManager = $find('<%= clientLabelManager.ClientID %>');
        var result = confirm(clientLabelManager.getLabel('Labels', 'SelfLogoutUserConfirm'));
        return result;
    
 
    function AlertLogOut()
        var clientLabelManager = $find('<%= clientLabelManager.ClientID %>');
        var value = userChoices.get_value();
 
        if (value == null || value.length == 0)
            alert(clientLabelManager.getLabel('Labels', 'UserNotSelected'));
            return false;
        
 
        var selectedItemId = userChoices.get_value(); // selectedItem[0].id;
        var result = confirm(clientLabelManager.getLabel('Labels', 'LogoutUserConfirm'));
 
        if (result)
            $get('<%= logoutUser.ClientID %>').value = value;
 
        
        return result;
    
 
</script>
</telerik:RadCodeBlock>
 and for LogoutForm:
Copy Code
<%@ Control Language="C#" %>
<%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %>
<div class="sfForm">
    <div class="sfFormIn">
        <div class="sfLoginShadowTopRight"></div>
        <div class="sfLoginShadowBottomLeft"></div>
        <h2>
            <asp:Literal ID="Literal1" Text="<%$ Resources:Labels, LoginToManage %>" runat="server" /> 
        </h2>
        <p class="sfSuccess">
            <asp:Literal ID="LoginStatus" runat="server" />
        </p>
        <asp:PlaceHolder ID="MessageHolder" runat="server">
        <p>
            <asp:Literal ID="Message" runat="server" />
        </p>
        </asp:PlaceHolder>
             
        <p>
            <asp:Literal Text="<%$ Resources:Labels, WhatToDo %>" runat="server" />
        </p>
        <ul class="sfLoginHelp">
            <li>
                <asp:LinkButton ID="Logout" Text="<%$ Resources:Labels, Logout %>" runat="server" />
            </li>
            <li>
                <asp:LinkButton ID="SwitchUser" Text="<%$ Resources:Labels, SwitchUser %>" runat="server" />
            </li>
            <li>
                <sf:SitefinityHyperLink
                    ID="ChangePassword"
                    NavigateUrl="~/Sitefinity/Login/ChangePassword"
                    Text="<%$ Resources:Labels, ChangePassword %>"
                    runat="server" />
            </li>
        </ul>
    </div>
</div>


2. Replace the LoginForm - this is the backend control. It is added through ObjectFactory so you can use Ioc to replace the LoginRouteHandler with a custom one. You need to inject a custom handler inside RegisterRoutes method of Telerik.Sitefinity.Abstractions.Bootstraper

routes.Add("LoginUtil", new Route("Sitefinity/Login/View", new LoginRouteHandlerCustom()));

In LoginRouteHandlerCustom you should override InitializeHttpHandler and add your custom LoginControl.

If the first option works for you this would be the easiest solution. The second one is quite complicated.

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

This thread is closed