Skip to content

Commit

Permalink
validate https and create the url if have https (#4183)
Browse files Browse the repository at this point in the history
  • Loading branch information
nequeteme authored and enzolutions committed Oct 23, 2019
1 parent 9b5e8ac commit 1bc9f1b
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/Command/User/LoginUrlCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Url;

/**
* Class UserLoginCommand.
Expand Down Expand Up @@ -59,6 +60,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
*/
protected function execute(InputInterface $input, OutputInterface $output)
{

$user = $input->getArgument('user');
$userEntity = $this->getUserEntity($user);

Expand All @@ -73,7 +75,31 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 1;
}

$url = user_pass_reset_url($userEntity) . '/login';
if($input->hasOption('uri')){
//validate if https is on uri
$regx = '/^https:.*/s';
if(preg_match($regx, $input->getOption('uri'))){
$timestamp = REQUEST_TIME;
$langcode = $userEntity->getPreferredLangcode();
$url = Url::fromRoute('user.reset',
[
'uid' => $userEntity->id(),
'timestamp' => $timestamp,
'hash' => user_pass_rehash($userEntity, $timestamp),
],
[
'absolute' => TRUE,
'language' => \Drupal::languageManager()->getLanguage($langcode),
'https' => TRUE,
]
)->toString();

} else{
$url = user_pass_reset_url($userEntity) . '/login';
}
} else{
$url = user_pass_reset_url($userEntity) . '/login';
}
$this->getIo()->success(
sprintf(
$this->trans('commands.user.login.url.messages.url'),
Expand Down

0 comments on commit 1bc9f1b

Please sign in to comment.