Custom Authentication
We have implemented the Membership and Role providers to use our database for user and role management.
The site is going to be used to host pages for multiple customers identified by their organisation. The user will be unique for an organisation. We want the user to select the organisation when logging in and the organisation along with the user credentials will be used to authenticate the user. Any suggestions on how we could achieve this?
Hi,
What I can suggest is that you add a custom field to the user profile to hold the information about the organization. This way, each user will have the name of the organization in this field.
Then you can create custom Login control where you can add a dropdown that lists all the organizations and the user will be able to select an organization when logging in Sitefinity using this control. You can add textboxes for the username and the passwords as well.
Then when the user selects the organization name from the dropdown and then enters the username and the password and clicks submit button, in the code behind of the custom login control you can get the selected value for the organization, the username and the password. Then you can use the API to get the user which has the specified username and the specified company name. If you can find this user, you can authenticate the user using the API as shown in the sample in this article.
http://docs.sitefinity.com/for-developers-authenticate-users
Here is also an article with samples on how to query users in Sitefinity:
http://docs.sitefinity.com/for-developers-query-users
Since you are using custom membership provider, please note to get the user manager by passing the name of your custom membership provider:
var userManager = UserManager.GetManager(
"YourCustomMembershipProviderName"
);