green-plastic / Legacy-Login

A seamless legacy authentication workflow for CraftCMS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Legacy Login

Seamless legacy authentication for CraftCMS

by Michael Rog
http://topshelfcraft.com

TL;DR.

The Legacy Login plugin provides a way to authenticate users from a legacy system into your Craft CMS site.

The plugin replaces the normal login form action. If a submitted loginName/password fails Craft's native authentication (i.e. the legacy user doesn't yet exist in the new Craft site), the plugin checks the legacy system's user data table and tries to authenticate a user from there. If a matching legacy user is found and authenticated, the plugin imports the User into Craft and logs into the newly created account.


What legacy systems are supported?

Drivers are provided for authenticating legacy users from:

  • ExpressionEngine 2.x
  • BigCommerce (Self-hosted)

In the future, I'd like to add drivers for:

  • WordPress

Setup

First, copy the legacylogin folder into your Craft plugins directory.

Then, navitage to the Settings > Plugins area of the control panel, and Install the plugin.

The plugin creates a data table for each supported legacy system (i.e. craft_legacylogin_data_ee2 for storing ExpressionEngine member data).

Import your legacy user data into the appropriate title. The schema should more-or-less match up; Some fields may be mismatched/skipped based on the version of the legacy system you're using, but the key fields (the username, id, email, and password hash) will be covered.

Finally, add the Legacy Login form to your login template. The template follows the same design as Craft's native login form, except the form action should point to the LegacyLoginController rather than Craft's native UsersController:

<form method="post" accept-charset="UTF-8">

	{{ getCsrfInput() }}
	<input type="hidden" name="action" value="legacyLogin/login">

	<label for="loginName">Username or email</label>
	<input id="loginName" type="text" name="loginName" value="{{ craft.session.rememberedUsername }}">

	<label for="password">Password</label>
	<input id="password" type="password" name="password">

	<label>
		<input type="checkbox" name="rememberMe" value="1">
		Remember me
	</label>

	<input type="submit" value="Login">

	{% if errorMessage is defined %}
		<p>{{ errorMessage }}</p>
	{% endif %}
	
</form>

Configuration

To customize the plugin's behavior, add a legacylogin.php file to your Craft config directory. (You can use plugins/legacylogin/config.php as a template.) The file should return an array; Like Craft's own General Configs, the Legacy Login config supports Craft's Multi-Environment Configs syntax.

The following settings are available:

allowedSystems

An array containing allowed legacy system names: 'BigCommerce', 'EE2', or both

Default: ['BigCommerce', 'EE2']

matchBy

A string which determines what attribute(s) of legacy users will be used to potentially match them with an existing Craft user: 'email', 'username', or 'both'

Default: 'email'

setPassword

A boolean which determines whether to set the password of a matched/created Craft user to match the legacy password.

Default: true

requirePasswordReset

A boolean which determines whether to set the Require Password Reset flag on a matched/created Craft user, i.e. requiring them to change their password upon their next login.

Default: false

What are the system requirements?

Craft 2.6+ and PHP 5.4+

I found a bug.

I'm not surprised... Legacy Login is still in development. Please open a GitHub Issue, submit a PR, or just email me to let me know.


Contributors:

About

A seamless legacy authentication workflow for CraftCMS

License:MIT License


Languages

Language:PHP 100.0%