mirror of
https://github.com/openclassify/openclassify.git
synced 2026-02-06 05:16:05 -06:00
#1042 Send new password if user passoword is empty (for migration)
This commit is contained in:
parent
aa511fff07
commit
fded095c60
@ -26,4 +26,5 @@ return [
|
|||||||
'error_valid_phone' => 'Phone number format is not correct.',
|
'error_valid_phone' => 'Phone number format is not correct.',
|
||||||
'registered_phone' => 'This phone number has already been registered.',
|
'registered_phone' => 'This phone number has already been registered.',
|
||||||
'ajax_address_error' => 'No address or not authorized to view.',
|
'ajax_address_error' => 'No address or not authorized to view.',
|
||||||
|
'empty_password_sms_message' => 'Due to security issues, we changed your password! Your new password is:',
|
||||||
];
|
];
|
||||||
|
|||||||
@ -0,0 +1,27 @@
|
|||||||
|
<?php namespace Visiosoft\ProfileModule\Profile\Events;
|
||||||
|
|
||||||
|
use Anomaly\UsersModule\User\UserModel;
|
||||||
|
|
||||||
|
class SendEmptyPassword
|
||||||
|
{
|
||||||
|
public $password;
|
||||||
|
public $userId;
|
||||||
|
|
||||||
|
public function __construct($userId, $password)
|
||||||
|
{
|
||||||
|
$this->password = $password;
|
||||||
|
$this->userId = $userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function user()
|
||||||
|
{
|
||||||
|
$user_model = new UserModel();
|
||||||
|
$user = $user_model->find($this->userId);
|
||||||
|
return $user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function password()
|
||||||
|
{
|
||||||
|
return $this->password;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -4,20 +4,28 @@ use Anomaly\Streams\Platform\Addon\Extension\ExtensionCollection;
|
|||||||
use Anomaly\UsersModule\User\Authenticator\Contract\AuthenticatorExtensionInterface;
|
use Anomaly\UsersModule\User\Authenticator\Contract\AuthenticatorExtensionInterface;
|
||||||
use Anomaly\UsersModule\User\Contract\UserInterface;
|
use Anomaly\UsersModule\User\Contract\UserInterface;
|
||||||
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;
|
use Anomaly\UsersModule\User\Contract\UserRepositoryInterface;
|
||||||
|
use Illuminate\Contracts\Events\Dispatcher;
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
use Visiosoft\ProfileModule\Profile\Events\SendEmptyPassword;
|
||||||
use Visiosoft\ProfileModule\Profile\SignIn\SignInFormBuilder;
|
use Visiosoft\ProfileModule\Profile\SignIn\SignInFormBuilder;
|
||||||
|
|
||||||
|
|
||||||
class ValidateCredentials
|
class ValidateCredentials
|
||||||
{
|
{
|
||||||
|
private $extensions;
|
||||||
|
private $repository;
|
||||||
|
private $dispatcher;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
ExtensionCollection $extensions,
|
ExtensionCollection $extensions,
|
||||||
UserRepositoryInterface $userRepository
|
UserRepositoryInterface $userRepository,
|
||||||
|
Dispatcher $dispatcher
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
$this->extensions = $extensions;
|
$this->extensions = $extensions;
|
||||||
$this->repository = $userRepository;
|
$this->repository = $userRepository;
|
||||||
|
$this->dispatcher = $dispatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function authenticate(array $credentials)
|
public function authenticate(array $credentials)
|
||||||
@ -41,6 +49,23 @@ class ValidateCredentials
|
|||||||
}
|
}
|
||||||
$response = $this->repository->findByCredentials($credentials);
|
$response = $this->repository->findByCredentials($credentials);
|
||||||
|
|
||||||
|
// Send new password if users password is empty
|
||||||
|
if (is_null($response)) {
|
||||||
|
if (isset($credentials['email'])) {
|
||||||
|
$probableUser = $this->repository->findByEmail($credentials['email']);
|
||||||
|
} elseif (isset($credentials['username'])) {
|
||||||
|
$probableUser = $this->repository->findByUsername($credentials['username']);
|
||||||
|
}
|
||||||
|
if ($probableUser) {
|
||||||
|
if (is_null($probableUser->password) || empty($probableUser->password)) {
|
||||||
|
$password = $this->randomPassword();
|
||||||
|
$probableUser->setAttribute('password', $password);
|
||||||
|
$probableUser->update();
|
||||||
|
$this->dispatcher->dispatch(new SendEmptyPassword($probableUser->id, $password));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$response = $authenticator->authenticate($credentials);
|
$response = $authenticator->authenticate($credentials);
|
||||||
}
|
}
|
||||||
@ -57,6 +82,16 @@ class ValidateCredentials
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function randomPassword() {
|
||||||
|
$alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
|
||||||
|
$pass = array(); //remember to declare $pass as an array
|
||||||
|
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
|
||||||
|
for ($i = 0; $i < 8; $i++) {
|
||||||
|
$n = rand(0, $alphaLength);
|
||||||
|
$pass[] = $alphabet[$n];
|
||||||
|
}
|
||||||
|
return implode($pass); //turn the array into a string
|
||||||
|
}
|
||||||
|
|
||||||
public function handle(SignInFormBuilder $builder)
|
public function handle(SignInFormBuilder $builder)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user