Extending Sitefinity's LOGIN (ForgotPassword) widget

Posted by Community Admin on 04-Aug-2018 10:51

Extending Sitefinity's LOGIN (ForgotPassword) widget

All Replies

Posted by Community Admin on 29-Mar-2016 00:00

Hi 

We are using sitefinity's Login widget for user authentication.
We want to customize the forgot password functionality and redirect the user, if the user belongs to a specific role.

Scenario:

When the new applicant registers sitefinity is creating a new account with a default  password and assigns a role to them.
We don't want the user to login until some checks were done on the user. But what the user doing was they are trying to login using the forgot password link. They are clicking the forgotpassword link adding their email address to reset their password. 

But when they login there was nothing to see as their account (dashboard) was not ready by that time.So we want to redirect the new applicant users to a specific page until their role changes from applicant to staff. We are using the default Sitefinity login widget for user registration and login (which comes with forgotpassword).

Is there anyway we can extend(customize) the forgot password so that if the user applicant user comes to forgot password page we can redirect him to a holding page instead of sending him a link to reset his password.

To achieve:

 So when the applicant user comes to forgotpassword page and enters his email and on submission we would like to show eithe a message saying that "user account not ready"  OR redirect the user to a holding page which says their account was not ready and we will send an invitation email once the account was ready.

What was the best way to achieve this
1) Do we need to customize the Sitefinity's login widget (which has forgotpassword)
2) Is there any administration (GUI) feature that we can achieve this.

Thanks 
Harry

Posted by Community Admin on 01-Apr-2016 00:00

Hi Harry,

It's not entirely clear to me from your explanation whether you are using the built-in functionality to prevent the users from logging in prior to their account activation.
More info on this in the documentation: 
- Registration widget > Account activation  http://docs.sitefinity.com/registration-widget
- Account activation widget  - http://docs.sitefinity.com/account-activation-widget

Now regarding your request, you can extend the Login widget functionality by creating a custom Web User Control in Visual Studio in order to implement some checks where you verify the user's role for example, or anything else for that matter.
Then, you map the widget in the backend, so that Sitefinity redirects to your custom Login widget instead of the regular one.

However since this one extends the default login widget there is a no way to override the actual sending of the email when submitting the email in order to retrieve the "reset password link".

I came up with following logic to work around that. After submitting the email, the control will check the user's role and if this one is of "applicant" then:
- the error will be displayed: "Your account not ready yet - it is waiting approval, please try again later .... "
and
- the email will be temporarily changed into another nonexisting email which will be forwarded to the Login widget. Since the email is not in the system no mail will be sent and the error catched.

For the widget markup I used the same as the regular Login widget. Of course all the above can be tailored by you.

You can copy the attached files in the root of your project and build the solution.

Afterwards you need to map in the backend the custom Login widget to the standard one. 
For this you navigate to Administration » Settings » Advanced » Controls » ViewMap and click Create new.
In the HostType field, enter the following value: 

Telerik.Sitefinity.Web.UI.PublicControls.LoginWidget, Telerik.Sitefinity

In the LayoutTemplatePath, enter the path to the widget: 

~/CustomLoginControl.ascx

Now your Login widget should have the implemented logic. 

You can also instead of mapping the custom widget to the standard one create a complete new widget/control that you register in the Toolboxes to be used on your page.
For this, please have a look at the sample in the documentation: NewsRotator widget: Create the NewsRotator as a user widget
http://docs.sitefinity.com/newsrotator-widget-create-the-newsrotator-as-a-user-widget


Regards,
Dimitri Cools
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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

Posted by Community Admin on 02-Apr-2016 00:00

Hi

Thanks for that.

I copied the code into project and  now its not building. Below is the error I was getting. Im not sure if its related to new addition of the custom control or not.

The 'securityConfig' element is not declared.D:\xxx\App_Data\Sitefinity\Configuration\SecurityConfig.config22SitefinityWebApp

 

Do I need to do any changes to the web.config file. I tried to look for this issues in the Sitefinity forum but dont see any posts related to that.

Any help is great.

 

Thanks

Harry

Posted by Community Admin on 05-Apr-2016 00:00

Hi, 

I don't see how this can be cause by the additional control. When you say that you copied the code, I suppose you mean that you copied the actual files ? 
Where exactly are you getting this error? 
Can you build your project successfully even without the additional files ? 
Is this an actual error or just a warning ? 

 
Regards,
Dimitri Cools
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 Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
 

This thread is closed