Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
uw_cfg_common
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
WCMS
uw_cfg_common
Commits
98c08c91
Commit
98c08c91
authored
2 years ago
by
Igor Biki
Browse files
Options
Downloads
Patches
Plain Diff
ISTWCMS-5983: Code standards with logic to load user using entity_type.manager service.
parent
c6115d8a
No related branches found
No related tags found
3 merge requests
!297
Feature/istwcms 5983 bulk account creation
,
!274
Draft: ISTWCMS-5551: fixing office hours display
,
!260
Feature/istwcms 5668 a5kulkar rename references to publications
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Form/UwAddUsersForm.php
+24
-8
24 additions, 8 deletions
src/Form/UwAddUsersForm.php
with
24 additions
and
8 deletions
src/Form/UwAddUsersForm.php
+
24
−
8
View file @
98c08c91
...
...
@@ -2,6 +2,7 @@
namespace
Drupal\uw_cfg_common\Form
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Drupal\Core\Form\FormBase
;
use
Drupal\Core\Form\FormStateInterface
;
use
Drupal\path_alias
\AliasManager
;
...
...
@@ -24,6 +25,13 @@ class UwAddUsersForm extends FormBase {
*/
protected
UWLdap
$uwLdap
;
/**
* Entity type interface manager from core.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected
EntityTypeManagerInterface
$entityTypeManager
;
/**
* {@inheritdoc}
*/
...
...
@@ -31,16 +39,18 @@ class UwAddUsersForm extends FormBase {
// Instantiates this form class.
return
new
static
(
$container
->
get
(
'path_alias.manager'
),
$container
->
get
(
'uw_cfg_common.uw_ldap'
)
$container
->
get
(
'uw_cfg_common.uw_ldap'
),
$container
->
get
(
'entity_type.manager'
)
);
}
/**
* Class constructor.
*/
public
function
__construct
(
AliasManager
$pathAliasManager
,
UWLdap
$uwLdap
)
{
public
function
__construct
(
AliasManager
$pathAliasManager
,
UWLdap
$uwLdap
,
EntityTypeManagerInterface
$entityTypeManager
)
{
$this
->
pathAliasManager
=
$pathAliasManager
;
$this
->
uwLdap
=
$uwLdap
;
$this
->
entityTypeManager
=
$entityTypeManager
;
}
/**
...
...
@@ -76,6 +86,7 @@ class UwAddUsersForm extends FormBase {
/**
* {@inheritdoc}
* @throws \Exception
*/
public
function
submitForm
(
array
&
$form
,
FormStateInterface
$form_state
)
{
...
...
@@ -95,7 +106,7 @@ class UwAddUsersForm extends FormBase {
$user
=
strtolower
(
$user
);
// Ignore blank lines.
if
(
!
strlen
(
$user
)
)
{
if
(
$user
===
''
)
{
continue
;
}
...
...
@@ -111,12 +122,17 @@ class UwAddUsersForm extends FormBase {
continue
;
}
/** @var UserInterface $existing_user */
$existing_user
=
user_load_by_name
(
$user
);
$existing_user
=
$this
->
entityTypeManager
->
getStorage
(
'user'
)
->
loadByProperties
([
[
'name'
=>
$user
],
]);
/** @var \Drupal\user\UserInterface|bool $existing_user */
$existing_user
=
$existing_user
?
reset
(
$existing_user
)
:
FALSE
;
if
(
$existing_user
)
{
$this
->
messenger
()
->
addError
(
$this
->
t
(
'The user ID <a href="@link"><em>@user</em></a> already exists and was skipped.'
,
[
'@link'
=>
$this
->
pathAliasManager
->
getAliasByPath
(
'/user/'
.
$existing_user
->
id
),
'@link'
=>
$this
->
pathAliasManager
->
getAliasByPath
(
'/user/'
.
$existing_user
->
id
()
),
'@user'
=>
$user
,
]
));
...
...
@@ -130,11 +146,11 @@ class UwAddUsersForm extends FormBase {
$sets
[]
=
'0123456789'
;
$sets
[]
=
'!@#$%^&*()-_=+[]{}?`~"'
;
$password
=
''
;
$password_length
=
rand
(
16
,
32
);
$password_length
=
rand
om_int
(
16
,
32
);
while
(
strlen
(
$password
)
<
$password_length
)
{
foreach
(
$sets
as
$set
)
{
$password
.
=
$set
[
array_rand
(
str_split
(
$set
))];
if
(
strlen
(
$password
)
==
$password_length
)
{
if
(
strlen
(
$password
)
==
=
$password_length
)
{
break
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment