Skip to content

Commit 1bc9f1b

Browse files
nequetemeenzolutions
authored andcommitted
validate https and create the url if have https (#4183)
1 parent 9b5e8ac commit 1bc9f1b

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

src/Command/User/LoginUrlCommand.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Symfony\Component\Console\Input\InputArgument;
1212
use Symfony\Component\Console\Output\OutputInterface;
1313
use Drupal\Core\Entity\EntityTypeManagerInterface;
14+
use Drupal\Core\Url;
1415

1516
/**
1617
* Class UserLoginCommand.
@@ -59,6 +60,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
5960
*/
6061
protected function execute(InputInterface $input, OutputInterface $output)
6162
{
63+
6264
$user = $input->getArgument('user');
6365
$userEntity = $this->getUserEntity($user);
6466

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

76-
$url = user_pass_reset_url($userEntity) . '/login';
78+
if($input->hasOption('uri')){
79+
//validate if https is on uri
80+
$regx = '/^https:.*/s';
81+
if(preg_match($regx, $input->getOption('uri'))){
82+
$timestamp = REQUEST_TIME;
83+
$langcode = $userEntity->getPreferredLangcode();
84+
$url = Url::fromRoute('user.reset',
85+
[
86+
'uid' => $userEntity->id(),
87+
'timestamp' => $timestamp,
88+
'hash' => user_pass_rehash($userEntity, $timestamp),
89+
],
90+
[
91+
'absolute' => TRUE,
92+
'language' => \Drupal::languageManager()->getLanguage($langcode),
93+
'https' => TRUE,
94+
]
95+
)->toString();
96+
97+
} else{
98+
$url = user_pass_reset_url($userEntity) . '/login';
99+
}
100+
} else{
101+
$url = user_pass_reset_url($userEntity) . '/login';
102+
}
77103
$this->getIo()->success(
78104
sprintf(
79105
$this->trans('commands.user.login.url.messages.url'),

0 commit comments

Comments
 (0)