diff --git a/app/Http/Controllers/ManageUsersController.php b/app/Http/Controllers/ManageUsersController.php index df777cac41..4363357664 100644 --- a/app/Http/Controllers/ManageUsersController.php +++ b/app/Http/Controllers/ManageUsersController.php @@ -9,36 +9,31 @@ final class ManageUsersController extends AbstractController { - /** - * TODO: (williamjallen) this function contains legacy XSL templating and should be converted - * to a proper Blade template with Laravel-based DB queries eventually. This contents - * this function are originally from manageUsers.php and have been copied (almost) as-is. - */ public function showPage(): View|RedirectResponse { - $xml = begin_XML_for_XSLT(); - $xml .= 'user.php'; - - @$postuserid = $_POST['userid']; - if ($postuserid != null && $postuserid > 0) { + $postuserid = (int) ($_POST['userid'] ?? -1); + if ($postuserid > 0) { $post_user = User::find($postuserid); } + $warning = ''; + $error = ''; + if (isset($_POST['adduser'])) { // arrive from register form - $email = $_POST['email']; - $passwd = $_POST['passwd']; - $passwd2 = $_POST['passwd2']; - if (!($passwd == $passwd2)) { - $xml .= add_XML_value('error', 'Passwords do not match!'); + $email = $_POST['email'] ?? ''; + $passwd = $_POST['passwd'] ?? ''; + $passwd2 = $_POST['passwd2'] ?? ''; + if ($passwd !== $passwd2) { + $error = 'Passwords do not match!'; } else { - $fname = $_POST['fname']; - $lname = $_POST['lname']; - $institution = $_POST['institution']; - if ($email && $passwd && $passwd2 && $fname && $lname && $institution) { + $fname = $_POST['fname'] ?? ''; + $lname = $_POST['lname'] ?? ''; + $institution = $_POST['institution'] ?? ''; + if ($email !== '' && $passwd !== '' && $passwd2 !== '' && $fname !== '' && $lname !== '' && $institution !== '') { $new_user = User::where('email', $email)->first(); - if (!is_null($new_user)) { - $xml .= add_XML_value('error', 'Email already registered!'); + if ($new_user !== null) { + $error = 'Email already registered!'; } else { $new_user = new User(); $passwordHash = password_hash($passwd, PASSWORD_DEFAULT); @@ -49,49 +44,39 @@ public function showPage(): View|RedirectResponse $new_user->lastname = $lname; $new_user->institution = $institution; if ($new_user->save()) { - $xml .= add_XML_value('warning', 'User ' . $email . ' added successfully with password:' . $passwd); + $warning = "User $email added successfully with password: $passwd"; } else { - $xml .= add_XML_value('error', 'Cannot add user'); + $error = 'Cannot add user'; } } } else { - $xml .= add_XML_value('error', 'Please fill in all of the required fields'); + $error = 'Please fill in all of the required fields'; } } } elseif (isset($_POST['makenormaluser'])) { if ($postuserid > 1) { $post_user->admin = 0; $post_user->save(); - $xml .= "$post_user->full_name is not administrator anymore."; + $warning = "$post_user->full_name is not administrator anymore."; } else { - $xml .= 'Administrator should remain admin.'; + $error = 'Administrator should remain admin.'; } } elseif (isset($_POST['makeadmin'])) { $post_user->admin = 1; $post_user->save(); - $xml .= "$post_user->full_name is now an administrator."; + $warning = "$post_user->full_name is now an administrator."; } elseif (isset($_POST['removeuser'])) { $name = $post_user->full_name; $post_user->delete(); - $xml .= "$name has been removed."; - } - - if (isset($_POST['search'])) { - $xml .= '' . $_POST['search'] . ''; - } - - $config = Config::getInstance(); - if ($config->get('CDASH_FULL_EMAIL_WHEN_ADDING_USER') == 1) { - $xml .= add_XML_value('fullemail', '1'); + $warning = "$name has been removed."; } - $xml .= ''; - return view('cdash', [ - 'xsl' => true, - 'xsl_content' => generate_XSLT($xml, base_path() . '/app/cdash/public/manageUsers', true), - 'title' => 'Manage Users' - ]); + return view('admin.manage-users') + ->with('warning', $warning) + ->with('error', $error) + ->with('search', $_POST['search'] ?? '') + ->with('fullemail', Config::getInstance()->get('CDASH_FULL_EMAIL_WHEN_ADDING_USER')); } public function ajaxFindUsers(): View diff --git a/app/cdash/public/manageUsers.xsl b/app/cdash/public/manageUsers.xsl deleted file mode 100644 index 5b1b97f189..0000000000 --- a/app/cdash/public/manageUsers.xsl +++ /dev/null @@ -1,125 +0,0 @@ - - - - - - - -

-
- -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Search for already registered users
- - - type the full email address of the user to add - - - start typing a name or email address (% to display all users) - - -
Search:
- - -
Add new user
First Name:
Last Name:
Email:
Password:
- - -
Confirm Password:
Institution:
- (password will be display in clear upon addition) -
-
- - - - - - <script language="JavaScript" type="text/javascript"> - - $(document).ready(function() { - $(window).keydown(function(event){ - if(event.keyCode == 13) { - event.preventDefault(); - return false; - } - }); - }); - - function confirmRemove() { - if (window.confirm("Are you sure you want to remove this user from the database?")){ - return true; - } - return false; - } - - function generatePassword() - { - var chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"; - var passwd = ""; - for(x=0;x<12;x++) - { - i = Math.floor(Math.random() * 62); - passwd += chars.charAt(i); - } - $("input#passwd").val(passwd); - $("input#passwd2").val(passwd); - $("#clearpasswd").html("("+passwd+")"); - } - - </script> - - -
-
diff --git a/resources/views/admin/manage-users.blade.php b/resources/views/admin/manage-users.blade.php new file mode 100644 index 0000000000..891970933c --- /dev/null +++ b/resources/views/admin/manage-users.blade.php @@ -0,0 +1,167 @@ +@extends('cdash', [ + 'title' => 'Manage Users' +]) + +@section('main_content') + @if(strlen($warning) > 0) +
{{ $warning }}

+ @endif + @if(strlen($error) > 0) +
{{ $error }}
+ @endif + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ Search for already registered users +
+ @if($fullemail) + type the full email address of the user to add + @else + start typing a name or email address (% to display all users) + @endif +
Search:
+ +
+
+
+ Add new user +
+
First Name:
+
+ +
+
Last Name:
+
+ +
+
Email:
+
+ +
+
Password:
+
+ + + +
+
Confirm Password:
+
+ +
+
Institution:
+
+ +
+ + (password will be displayed in clear text upon addition) +
+
+ + + + + + +@endsection