Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PlanetRed
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jeff Sturek
PlanetRed
Commits
6acbb485
Commit
6acbb485
authored
9 years ago
by
Michael Fairchild
Browse files
Options
Downloads
Patches
Plain Diff
add a script to add a user
parent
e0364c63
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
plugins/cas_auth_unl/add_user.php
+62
-0
62 additions, 0 deletions
plugins/cas_auth_unl/add_user.php
with
62 additions
and
0 deletions
plugins/cas_auth_unl/add_user.php
0 → 100644
+
62
−
0
View file @
6acbb485
<?php
require_once
__DIR__
.
'/../../elgg/vendor/autoload.php'
;
if
(
!
isset
(
$argv
[
1
]))
{
echo
"usage: php add_user.php username"
.
PHP_EOL
;
exit
();
}
\Elgg\Application
::
start
();
$uid
=
$argv
[
1
];
$info
=
array
();
if
(
!
$json
=
@
file_get_contents
(
UnlCAS
::
DIRECTORY_URL
.
'?uid='
.
$uid
.
'&format=json'
))
{
echo
'unable to get that ID'
.
PHP_EOL
;
exit
();
}
if
(
!
$json
=
json_decode
(
$json
,
true
))
{
echo
'error decoding data'
.
PHP_EOL
;
exit
();
}
$map
=
array
(
'givenName'
=>
'first_name'
,
'sn'
=>
'last_name'
,
'mail'
=>
'email'
);
foreach
(
$map
as
$from
=>
$to
)
{
if
(
isset
(
$json
[
$from
][
0
]))
{
$info
[
$to
]
=
$json
[
$from
][
0
];
}
}
$info
[
'name'
]
=
$info
[
'first_name'
]
.
' '
.
$info
[
'last_name'
];
if
(
!
isset
(
$info
[
'email'
]))
{
echo
'no email is available'
.
PHP_EOL
;
exit
();
}
$password
=
generate_random_cleartext_password
();
$elgg_uid
=
str_replace
(
'-'
,
'_'
,
$uid
);
$elgg_uid
=
'unl_'
.
$elgg_uid
;
try
{
$user_guid
=
register_user
(
$elgg_uid
,
$password
,
$info
[
'name'
],
$info
[
'email'
],
false
);
}
catch
(
RegistrationException
$e
)
{
//Looks like we had an invalid email address... ask for it again.
echo
'Unable to register, probably due to invalid email address or the user already exists'
.
PHP_EOL
;
exit
();
}
if
(
!
$user_guid
)
{
echo
'Unable to register'
.
PHP_EOL
;
exit
();
}
echo
'User added: '
.
$elgg_uid
.
PHP_EOL
;
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