Developer forum

Forum » Development » Catch wrong login with notificationsubscriber

Catch wrong login with notificationsubscriber

Rob Lohmann
Reply

For a B2B customer we're developing a website containing an login. The login is loaded in a small popup and works fine when you enter the correct logindata. However, if you enter wrong login data you see a postback happening but no error is/can be shown that the login was unsuccesfull.

 

Due to a topic here I found out it is possible to use a notificationsubsriber to catch the OnExtranetLoginFailed event. The only thing I can't figure out is how I can call the template here? What I want to do is catch this event when the login failes, and then fill an custom template tag showing an error message. Is this even possible? Or should I use an different approach?

This is my current code;

<Subscribe(Dynamicweb.Notifications.Standard.User.OnExtranetLoginFailed)> _
Public Class INNO_LoginNotificationSubscriber
    Inherits NotificationSubscriber

    ''For notifications passing an object inheriting Dynamicweb.Extensibility.NotificationArgs
    Public Overrides Sub OnNotify(ByVal notification As String, ByVal args As Dynamicweb.Extensibility.NotificationArgs)
        Try
            If Not Dynamicweb.Helper.IsAdminCall() Then
                Dim extranetLoginArgs As Dynamicweb.Notifications.Standard.User.OnExtranetLoginFailedArgs = CType(args, Dynamicweb.Notifications.Standard.User.OnExtranetLoginFailedArgs)
                Dim template As Rendering.Template = TryCast(args, Dynamicweb.Notifications.Standard.Page.OnOutputArgs).template 'NullReference Excption is thrown here!
            End If
        Catch ex As Exception

        End Try

        'TODO: Add code here
        'Sample usage of notifications args
        'Dim paragraphArgs As Dynamicweb.Notifications.Standard.Paragraph.ParagraphNotificationArgs = DirectCast(args, Dynamicweb.Notifications.Standard.Paragraph.ParagraphNotificationArgs)
        'Dim pv As PageView = CType(args, PageView)
    End Sub
End Class

 


Replies

 
Morten Bengtson
Reply

Hi Rob,

 

When the login fails a few error tags are available in both the login template and the page template: DW_extranet_error_dk (danish error message) and DW_extranet_error_uk (english error message).

 

Here is a basic login template that displays a translated message when login fails:

<form action="" method="post">
	<fieldset>
		<legend><!--@Translate(Login,"Log in")--></legend>
		
		<!--@If Defined(DW_extranet_error_uk)-->
		<p class="error"><!--@Translate(Login.Error,"Sorry, but we found no user with that username and password.")--></p>
		<!--@EndIf(DW_extranet_error_uk)-->
		
		<label><!--@Translate(Login.Username,"Username")--><input type="text" name="username" /></label>
		<label><!--@Translate(Login.Password,"Password")--><input type="password" name="password" /></label>
		<input type="submit" value="<!--@Translate(Login,"Log in")-->" />
	</fieldset>
</form>

If you need to extend this and programatically add custom detailed messages then you can do so by implementing a OnGlobalTags NotificationSubscriber.

 

BR

Morten

 

 
Rob Lohmann
Reply

Hi morten,

Thanks for your response. I know about these tags, unfortunaltely they don't work. The code for the form is as below. And the form is shown in a small popup opened by a small piece of javascript.

Note that this code is taken from/based on the solutionset, I've check that one and unfortunately it also doesn't include any error messages when login failes

<div id="login-box" title='<!--@Translate(LoginBoxTitle, "Login")-->' class="login-form" style="display: none">
	<div class="tertiaryBackgroundColor LoginBoxWrapper secondaryLinkColor relative left">
		<div class="login-box-mode" data-login-box-mode="login">
			<span class="title uppercase left clear relative">
				<!--@Translate(Global_CustomerLogin, "Inloggen", global)-->
				<!--@If Defined(DW_extranet_error_uk)-->
					<p class="error"><!--@Translate(Login.Error,"Sorry, but we found no user with that username and password.")--></p>
				<!--@EndIf(DW_extranet_error_uk)-->
			</span>
			<span class="closeBtn"></span>
			<form action="<!--@Global:Pageview.Url-->" method="post" onsubmit="return Layout.LoginBox.validate(this);" class="clear left relative">
				
				<input type="hidden" name="DWExtranetUsernameRemember" value="True" />
				<input type="hidden" name="DWExtranetPasswordRemember" value="True" />

				<div class="login-form-field clear left relative">                    
					<input type="text" id="login-username" class="login-credentials login-username-field validate validate[required,custom[email]] primaryTextColor" name="username" spellcheck="false" placeholder="<!--@Translate(Global_YourMailaddress, 'Uw e-mailadres',global)-->"/>
				</div>

				<div class="login-form-field clear left relative">                    
					<input type="password" id="login-password" class="login-credentials login-password-field validate validate[required,length[0,255]] primaryTextColor" name="password" placeholder="<!--@Translate(Global_YourPassword, 'Uw Wachtwoord',global)-->" />
				</div>
				<div class="login-form-field login-form-field-buttons clear left relative width_100">
					<div class="left clear ">
						<a href="javascript:void(0)" onclick="Layout.LoginBox.mode('lostpassword', $(this).parents('form'));" class="secondaryLinkColor underline left clear"><!--@Translate(Global_LostPasswordRecovery, "Wachtwoord vergeten", global)-->?</a>
					</div>                    
					<input type="submit" class="button border secondaryLinkColor tertiaryBackgroundColor submit right bold" value="<!--@Translate(Global_Login, 'Inloggen', global)-->" />
				</div>
			</form>
		</div>
		
		<div class="login-box-mode" data-login-box-mode="lostpassword" style="display: none">       
			<span class="title uppercase left clear relative"><!--@Translate(Global_LostPasswordRecovery, "Wachtwoord vergeten", global)--></span>
			<span class="closeBtn"></span>
			<form action="<!--@Global:Pageview.Url-->" id="lostPasswordForm" method="post">
				<input type="hidden" name="ID" value="<!--@Global:Page.ID-->" />
				<input type="hidden" name="host" value="<!--@Global:Request.Host-->" />
				<input type="hidden" name="ForgotPassword" value="True" />
				<input type="hidden" name="ForgotPasswordMailSubject" value='Carmat - <!--@Translate(Global_LostPasswordMailTitle, "Wachtwoord Vergeten", global)-->'>
				<input type="hidden" name="ForgotPasswordConfirm" value='<!--@Translate(Global_NewPasswordSent, "Uw nieuwe wachtwoord is per e-mail verzonden", global)-->.'>
				<input type="hidden" name="ForgotPasswordMailTemplate" value="INNO_LostPassword.html" />

				<div class="login-form-field clear left relative">
					<input type="text" id="login-email" class="login-credentials login-email-field validate validate[required,custom[email]]" name="username" spellcheck="false" placeholder='<!--@Translate(EmailAddress, "Emailadres", global)-->'/>
				</div>
				
				<div id="lostPasswordSent" class="clear" style="display:none;"><strong><!--@Translate(Global_NewPasswordSent, 'Uw nieuwe wachtwoord is per e-mail verzonden', global)--></strong></div>
		
				<div class="login-form-field login-form-field-buttons">
					<input type="button" class="button tertiaryBackgroundColor" value='<!--@Translate(sendpassword, "Wachtwoord verzenden", global)-->' onclick="javascript:return Layout.LoginBox.SubmitLostPassword($(this).closest('form'))"/>
				</div>
			</form>
		</div>
	</div>
</div>

 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer

Have you seen this: http://devierkoeden.com/articles/notificationsubscribers-part-3-extranet-logins.aspx ?

 

Imar

 

Votes for this answer: 1
 
Rob Lohmann
Reply

Brillian! That's what I needed, thanks Imar!

Rob

 

You must be logged in to post in the forum