Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Craft;
- class CustomLoginController extends BaseController
- {
- protected $allowAnonymous = true;
- public function actionLogin()
- {
- // Attempt to log the user in
- $this->_login();
- // Now pass back to the normal login controller
- craft()->runController('users/login');
- }
- private function _login()
- {
- if (craft()->userSession->isLoggedIn())
- {
- return;
- }
- if (craft()->request->isPostRequest())
- {
- $loginName = craft()->request->getPost('loginName');
- $password = craft()->request->getPost('password');
- $rememberMe = (bool) craft()->request->getPost('rememberMe');
- // Try logging them in normally
- if (craft()->userSession->login($loginName, $password, $rememberMe))
- {
- return;
- }
- // Is it an actual user account, at least?
- $user = craft()->users->getUserByUsernameOrEmail($loginName);
- if ($user)
- {
- // See if they had an EE user account
- $host = craft()->config->get('server', ConfigFile::Db);
- $port = craft()->config->get('port', ConfigFile::Db);
- $dbName = 'ee_database_name';
- $dbUser = 'ee_database_username';
- $dbPass = 'ee_database_password';
- $db = new DbConnection('mysql:host='.$host.';dbname='.$dbName.';port='.$port.';', $dbUser, $dbPass);
- $row = $db->createCommand()
- ->select('member_id, password, salt')
- ->from('exp_members')
- ->where(array('or', 'username=:login', 'email=:login'), array(':login' => $loginName))
- ->queryRow();
- if ($row)
- {
- $hashedPassword = $this->_hashEEPassword($password);
- if ($hashedPassword == $row['password'])
- {
- // Eureka! Now update the local user account
- $user->newPassword = $password;
- craft()->users->changePassword($user);
- // Delete the old user row so their old password stops working
- $db->createCommand()->delete('exp_members',
- array('member_id=:id'),
- array(':id' => $row['member_id']));
- }
- }
- }
- }
- }
- private function _hashEEPassword($password)
- {
- // Hash the password using EE's hashing technique
- // ...
- return $hashedPassword;
- }
- }
- <input type="hidden" name="action" value="customLogin/login">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement