Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate manageUsers.php from XSL to Blade #1639

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 28 additions & 43 deletions app/Http/Controllers/ManageUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 .= '<backurl>user.php</backurl>';

@$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);
Expand All @@ -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 .= "<warning>$post_user->full_name is not administrator anymore.</warning>";
$warning = "$post_user->full_name is not administrator anymore.";
} else {
$xml .= '<error>Administrator should remain admin.</error>';
$error = 'Administrator should remain admin.';
}
} elseif (isset($_POST['makeadmin'])) {
$post_user->admin = 1;
$post_user->save();
$xml .= "<warning>$post_user->full_name is now an administrator.</warning>";
$warning = "$post_user->full_name is now an administrator.";
} elseif (isset($_POST['removeuser'])) {
$name = $post_user->full_name;
$post_user->delete();
$xml .= "<warning>$name has been removed.</warning>";
}

if (isset($_POST['search'])) {
$xml .= '<search>' . $_POST['search'] . '</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 .= '</cdash>';

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
Expand Down
125 changes: 0 additions & 125 deletions app/cdash/public/manageUsers.xsl

This file was deleted.

Loading