-
-
Notifications
You must be signed in to change notification settings - Fork 547
Expand file tree
/
Copy pathLoginUrlCommand.php
More file actions
116 lines (102 loc) · 3.03 KB
/
LoginUrlCommand.php
File metadata and controls
116 lines (102 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/**
* @file
* Contains Drupal\Console\Command\User\LoginUrlCommand.
*/
namespace Drupal\Console\Command\User;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Url;
/**
* Class UserLoginCommand.
*
* @package Drupal\Console
*/
class LoginUrlCommand extends UserBase
{
/**
* LoginUrlCommand constructor.
*
* @param EntityTypeManagerInterface $entityTypeManager
*/
public function __construct(EntityTypeManagerInterface $entityTypeManager)
{
parent::__construct($entityTypeManager);
}
/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('user:login:url')
->setDescription($this->trans('commands.user.login.url.description'))
->addArgument(
'user',
InputArgument::REQUIRED,
$this->trans('commands.user.login.url.options.user'),
null
)
->setAliases(['ulu']);
}
/**
* {@inheritdoc}
*/
protected function interact(InputInterface $input, OutputInterface $output)
{
$this->getUserArgument();
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$user = $input->getArgument('user');
$userEntity = $this->getUserEntity($user);
if (!$userEntity) {
$this->getIo()->error(
sprintf(
$this->trans('commands.user.login.url.errors.invalid-user'),
$user
)
);
return 1;
}
if($input->hasOption('uri')){
//validate if https is on uri
$regx = '/^https:.*/s';
if(preg_match($regx, $input->getOption('uri'))){
$timestamp = \Drupal::time()->getRequestTime();
$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'),
$userEntity->getAccountName(),
null
)
);
$this->getIo()->simple($url);
$this->getIo()->newLine();
return 0;
}
}