33 const NAME =
"user_edit";
48 function __construct()
50 parent::__construct(self::NAME, array(
51 self::TITLE => _(
"Edit User Account"),
52 self::MENU_LIST =>
'Admin::Users::Edit User Account',
53 self::REQUIRES_LOGIN =>
true,
58 $this->authHelper = $this->
getObject(
'helper.authHelper');
59 $this->userDao = $this->
getObject(
'dao.user');
71 protected function handle(Request $request)
74 $user_pk = Auth::getUserId();
82 }
catch (\Exception $e) {
83 $vars[
'message'] = $e->getMessage();
87 $user_pk_to_modify = intval($request->get(
'user_pk'));
88 if (! ($SessionIsAdmin || empty($user_pk_to_modify) ||
89 $user_pk == $user_pk_to_modify)) {
90 $vars[
'content'] = _(
"Your request is not valid.");
91 return $this->
render(
'include/base.html.twig', $this->mergeWithDefault($vars));
94 $vars = array(
'refreshUri' =>
Traceback_uri() .
"?mod=" . self::NAME);
100 $BtnText = $request->get(
'UpdateBtn');
101 if (! empty($BtnText)) {
105 $rv = $this->
UpdateUser($UserRec, $SessionIsAdmin);
108 $vars[
'message'] =
"User $UserRec[user_name] updated.";
111 $UserRec = $this->
CreateUserRec($request, $UserRec[
'user_pk']);
113 $vars[
'message'] = $rv;
116 $NewUserpk = intval($request->get(
'newuser'));
121 $vars = array_merge($vars, $this->
DisplayForm($UserRec, $SessionIsAdmin));
122 $vars[
'userId'] = $UserRec[
'user_pk'];
123 $vars[
'newToken'] = $newToken;
126 $vars[
'maxTokenDate'] = $this->authHelper->getMaxTokenValidity();
127 $vars[
'writeAccess'] = ($_SESSION[Auth::USER_LEVEL] >= 3);
129 return $this->
render(
'user_edit.html.twig', $this->mergeWithDefault($vars));
141 $vars = array(
'isSessionAdmin' => $SessionIsAdmin,
142 'userId' => $UserRec[
'user_pk']);
147 if ($SessionIsAdmin) {
148 $stmt = __METHOD__ .
'.asSessionAdmin';
149 $sql =
"SELECT * FROM users ORDER BY user_name";
153 while ($row = $this->
dbManager->fetchArray($res)) {
154 $allUsers[$row[
'user_pk']] = htmlentities($row[
'user_name']);
157 $vars[
'allUsers'] = $allUsers;
160 $vars[
'userName'] = $UserRec[
'user_name'];
161 $vars[
'userDescription'] = $UserRec[
'user_desc'];
162 $vars[
'userEMail'] = $UserRec[
"user_email"];
163 $vars[
'eMailNotification'] = ($UserRec[
'email_notify'] ==
'y');
165 if ($SessionIsAdmin) {
166 $vars[
'allAccessLevels'] = array(
168 PLUGIN_DB_READ => _(
"Read-only (read, but no writes or downloads)"),
169 PLUGIN_DB_WRITE => _(
"Read-Write (read, download, or edit information)"),
170 PLUGIN_DB_CADMIN => _(
"Clearing Administrator (read, download, edit information and edit decisions)"),
171 PLUGIN_DB_ADMIN => _(
"Full Administrator (all access including adding and deleting users)")
173 $vars[
'accessLevel'] = $UserRec[
'user_perm'];
175 $SelectedFolderPk = $UserRec[
'root_folder_fk'];
176 $vars[
'folderListOption'] =
FolderListOption($ParentFolder = -1, $Depth = 0, $IncludeTop = 1, $SelectedFolderPk);
179 $vars[
'isBlankPassword'] = ($UserRec[
'_blank_pass'] ==
'on');
181 "agent_adj2nest",
"wget_agent"), $UserRec[
'user_name']);
202 if (empty($UserRec[
'user_pk'])) {
203 $Errors .=
"<li>" . _(
"Consistency error (User_pk missing). Please start over.") .
"</li>";
207 if (empty($UserRec[
'user_name'])) {
208 $Errors .=
"<li>" . _(
"Username must be specified.") .
"</li>";
212 $CheckUserRec =
GetSingleRec(
"users",
"WHERE user_name='$UserRec[user_name]'");
213 if ((!empty($CheckUserRec)) and ( $CheckUserRec[
'user_pk'] != $UserRec[
'user_pk'])) {
214 $Errors .=
"<li>" . _(
"Username is not unique.") .
"</li>";
218 if ($UserRec[
'_pass1'] != $UserRec[
'_pass2']) {
219 $Errors .=
"<li>" . _(
"Passwords do not match.") .
"</li>";
223 $Check = preg_replace(
"/[^a-zA-Z0-9@_.+-]/",
"", $UserRec[
'user_email']);
224 if ($Check != $UserRec[
'user_email']) {
225 $Errors .=
"<li>" . _(
"Invalid email address.") .
"</li>";
229 if (!empty($UserRec[
'_blank_pass']) and ( !empty($UserRec[
'_pass1']) or ! empty($UserRec[
'_pass2']))) {
230 $Errors .=
"<li>" . _(
"You cannot specify both a password and a blank password.") .
"</li>";
234 if (!empty($UserRec[
'group_fk'])) {
235 $group_map = $this->userDao->getUserGroupMap($UserRec[
'user_pk']);
236 if (array_search($UserRec[
'group_fk'], array_keys($group_map)) ===
false) {
237 $Errors .=
"<li>" . _(
"User is not member of provided group.") .
243 if (!empty($Errors)) {
244 return _(
"Errors") .
":<ol>$Errors </ol>";
249 if (!empty($UserRec[
'_blank_pass']) ) {
250 $UserRec[
'user_seed'] = rand() . rand();
251 $UserRec[
'user_pass'] = sha1($UserRec[
'user_seed'] .
"");
252 }
else if (empty($UserRec[
'_pass1'])) {
253 unset( $UserRec[
'user_pass']);
254 unset( $UserRec[
'user_seed']);
258 $sql =
"UPDATE users SET ";
260 foreach ($UserRec as $key=>$val) {
261 if ($key[0] ==
'_' || $key ==
"user_pk") {
264 if (!$SessionIsAdmin && ($key ==
"user_perm" || $key ==
"root_folder_fk")) {
271 $sql .=
"$key='" . pg_escape_string($val) .
"'";
274 $sql .=
" WHERE user_pk=$UserRec[user_pk]";
275 $result = pg_query($PG_CONN, $sql);
277 pg_free_result($result);
290 if (empty($user_pk)) {
291 throw new Exception(
"Invalid access. Your session has expired.",1);
294 $UserRec =
GetSingleRec(
"users",
"WHERE user_pk=$user_pk");
295 if (empty($UserRec)) {
296 throw new Exception(
"Invalid user. ",1);
325 if (!empty($user_pk)) {
327 $UserRec[
'_pass1'] =
"";
328 $UserRec[
'_pass2'] =
"";
329 $UserRec[
'_blank_pass'] = ($UserRec[
'user_pass'] == sha1($UserRec[
'user_seed'] .
"")) ?
"on" :
"";
332 $UserRec[
'user_pk'] = intval($request->get(
'user_pk'));
333 $UserRec[
'user_name'] = stripslashes($request->get(
'user_name'));
334 $UserRec[
'root_folder_fk'] = intval($request->get(
'root_folder_fk'));
335 $UserRec[
'user_desc'] = stripslashes($request->get(
'user_desc'));
336 $UserRec[
'group_fk'] = intval($request->get(
'default_group_fk'));
338 $UserRec[
'_pass1'] = stripslashes($request->get(
'_pass1'));
339 $UserRec[
'_pass2'] = stripslashes($request->get(
'_pass2'));
340 if (!empty($UserRec[
'_pass1'])) {
341 $UserRec[
'user_seed'] = rand() . rand();
342 $UserRec[
'user_pass'] = sha1($UserRec[
'user_seed'] . $UserRec[
'_pass1']);
343 $UserRec[
'_blank_pass'] =
"";
345 $UserRec[
'user_pass'] =
"";
346 $UserRec[
'_blank_pass'] = stripslashes($request->get(
"_blank_pass"));
347 if (empty($UserRec[
'_blank_pass'])) {
349 $StoredUserRec = $this->
GetUserRec($UserRec[
'user_pk']);
350 $UserRec[
'_blank_pass'] = ($UserRec[
'user_pass'] == sha1($StoredUserRec[
'user_seed'] .
"")) ?
"on" :
"";
354 $UserRec[
'user_perm'] = intval($request->get(
'user_perm'));
355 $UserRec[
'user_email'] = stripslashes($request->get(
'user_email'));
356 $UserRec[
'email_notify'] = stripslashes($request->get(
'email_notify'));
357 if (!empty($UserRec[
'email_notify'])) {
358 $UserRec[
'email_notify'] =
'y';
361 $UserRec[
'default_bucketpool_fk'] = intval($request->get(
"default_bucketpool_fk"));
380 $user_pk = Auth::getUserId();
383 if ($_SESSION[Auth::USER_LEVEL] < 3) {
388 $tokenScope = array_search($tokenScope, RestHelper::SCOPE_DB_MAP);
389 $restHelper = $container->get(
'helper.restHelper');
390 $isTokenRequestValid = $restHelper->validateTokenRequest($tokenExpiry,
391 $tokenName, $tokenScope);
393 if ($isTokenRequestValid !==
true) {
394 throw new \UnexpectedValueException($isTokenRequestValid->getMessage());
396 $restDbHelper = $container->get(
'helper.dbHelper');
398 openssl_random_pseudo_bytes(RestHelper::TOKEN_KEY_LENGTH / 2));
400 $jti = $restDbHelper->insertNewTokenKey($user_pk, $tokenExpiry,
401 RestHelper::SCOPE_DB_MAP[$tokenScope], $tokenName, $key);
405 openssl_random_pseudo_bytes(RestHelper::TOKEN_KEY_LENGTH / 2));
407 $jti = $restDbHelper->insertNewTokenKey($user_pk, $tokenExpiry,
408 RestHelper::SCOPE_DB_MAP[$tokenScope], $tokenName, $key);
414 throw new \UnexpectedValueException($e->getMessage());
416 return $this->authHelper->generateJwtToken($tokenExpiry,
417 $jti[
'created_on'], $jti[
'jti'], $tokenScope, $key);
432 $user_pk = Auth::getUserId();
433 $sql =
"SELECT pat_pk, user_fk, expire_on, token_scope, token_name, created_on, active " .
434 "FROM personal_access_tokens " .
435 "WHERE user_fk = $1 AND active = true;";
436 $rows = $this->
dbManager->getRows($sql, [$user_pk],
437 __METHOD__ .
".getActiveTokens");
439 foreach ($rows as $row) {
440 if ($this->authHelper->isTokenActive($row, $row[
"pat_pk"]) ===
true) {
442 "id" => $row[
"pat_pk"] .
"." . $user_pk,
443 "name" => $row[
"token_name"],
444 "created" => $row[
"created_on"],
445 "expire" => $row[
"expire_on"],
446 "scope" => $row[
"token_scope"]
448 $response[] = $entry;
451 array_multisort(array_column($response,
"created"), SORT_ASC, $response);
463 $user_pk = Auth::getUserId();
464 $sql =
"SELECT pat_pk, user_fk, expire_on, token_scope, token_name, created_on " .
465 "FROM personal_access_tokens " .
466 "WHERE user_fk = $1 AND active = false;";
467 $rows = $this->
dbManager->getRows($sql, [$user_pk],
468 __METHOD__ .
".getActiveTokens");
470 foreach ($rows as $row) {
472 "id" => $row[
"pat_pk"] .
"." . $user_pk,
473 "name" => $row[
"token_name"],
474 "created" => $row[
"created_on"],
475 "expire" => $row[
"expire_on"],
476 "scope" => $row[
"token_scope"]
478 $response[] = $entry;
480 array_multisort(array_column($response,
"created"), SORT_ASC, $response);
491 $groups = $this->userDao->getUserGroupMap($userRec[
'user_pk']);
492 $userDefaults = $this->userDao->getUserAndDefaultGroupByUserName($userRec[
'user_name']);
494 foreach ($groups as $groupId => $groupName) {
495 $options .=
"<option value='$groupId' ";
496 if ($groupId == $userDefaults[
'group_fk']) {
497 $options .=
"selected='selected'";
499 $options .=
">$groupName</option>";
Exception when a token has duplicate name for same user.
SelectBucketPool($selected, $active='Y')
Return a select list containing all the active bucketpool's.
Traceback_uri()
Get the URI without query to this location.
userAgents()
Read the UI form and format the user selected agents into a comma separated list. ...
generateNewToken(Request $request)
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
IsSessionAdmin($UserRec)
Determine if the session user is an admin.
FolderListOption($ParentFolder, $Depth, $IncludeTop=1, $SelectId=-1, $linkParent=false, $OldParent=0)
Create the folder tree, using OPTION tags.
UpdateUser($UserRec, $SessionIsAdmin)
Validate and update the user data.
render($templateName, $vars=null, $headers=null)
AgentCheckBoxMake($upload_pk, $SkipAgents=array(), $specified_username="")
Generate a checkbox list of available agents.
GetSingleRec($Table, $Where="")
Retrieve a single database record.
getListOfActiveTokens()
Get a list of active tokens for current user.
GetUserRec($user_pk)
Get a user record.
#define PLUGIN_DB_READ
Plugin requires read permission on DB.
Exception when a token has duplicate key for same user.
getUserGroupSelect($userRec)
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.
handle(Request $request)
Allow user to change their account settings (users db table).
CreateUserRec(Request $request, $user_pk="")
Create a user record.
#define PLUGIN_DB_NONE
Plugin requires no DB permission.
DisplayForm($UserRec, $SessionIsAdmin)
Display the user record edit form.
#define PLUGIN_DB_WRITE
Plugin requires write permission on DB.
fo_dbManager * dbManager
fo_dbManager object
#define PERM_READ
Read-only permission.
foreach($Options as $Option=> $OptVal) if(0==$reference_flag &&0==$nomos_flag) $PG_CONN
DBCheckResult($result, $sql, $filenm, $lineno)
Check the postgres result for unexpected errors. If found, treat them as fatal.