mirror of
https://github.com/sigmasternchen/MyTube
synced 2025-03-15 04:48:55 +00:00
settings now work
This commit is contained in:
parent
995c2eadb6
commit
06a2406e55
4 changed files with 75 additions and 9 deletions
|
@ -198,7 +198,45 @@ class UserController extends AbstractController
|
|||
$okay = true;
|
||||
}
|
||||
|
||||
return $this->render("user/user-new.html.twig", [
|
||||
return $this->render("user/user-edit.html.twig", [
|
||||
"ok" => $okay,
|
||||
"form" => $form->createView()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Route("/settings", name="app_settings")
|
||||
*/
|
||||
public function settings(Request $request): Response
|
||||
{
|
||||
if (!$this->isGranted(User::ROLE_USER)) {
|
||||
throw new AccessDeniedHttpException();
|
||||
}
|
||||
|
||||
$user = $this->userService->getLoggedInUser();
|
||||
|
||||
|
||||
$form = $this->createForm(UserType::class, $user, [
|
||||
"password_optional" => true,
|
||||
"roles" => false
|
||||
]);
|
||||
|
||||
$okay = false;
|
||||
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$roles = $user->getRoles();
|
||||
|
||||
$user = $form->getData();
|
||||
|
||||
$user->setRoles($roles);
|
||||
|
||||
$this->userService->update($user);
|
||||
|
||||
$okay = true;
|
||||
}
|
||||
|
||||
return $this->render("user/settings.html.twig", [
|
||||
"ok" => $okay,
|
||||
"form" => $form->createView()
|
||||
]);
|
||||
|
|
|
@ -20,14 +20,19 @@ class UserType extends AbstractType
|
|||
{
|
||||
$builder
|
||||
->add("name", TextType::class)
|
||||
->add("email", EmailType::class)
|
||||
->add("roles", ChoiceType::class, [
|
||||
->add("email", EmailType::class);
|
||||
|
||||
if ($options["roles"]) {
|
||||
$builder->add("roles", ChoiceType::class, [
|
||||
"choices" => [
|
||||
"Admin" => User::ROLE_ADMIN
|
||||
],
|
||||
"multiple" => true,
|
||||
"expanded" => true,
|
||||
])
|
||||
]);
|
||||
}
|
||||
|
||||
$builder
|
||||
->add("newPassword", PasswordType::class, [
|
||||
"always_empty" => true,
|
||||
"required" => !$options["password_optional"]
|
||||
|
@ -39,7 +44,8 @@ class UserType extends AbstractType
|
|||
{
|
||||
$resolver->setDefaults([
|
||||
"data_class" => User::class,
|
||||
"password_optional" => false
|
||||
"password_optional" => false,
|
||||
"roles" => true,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
20
templates/user/settings.html.twig
Normal file
20
templates/user/settings.html.twig
Normal file
|
@ -0,0 +1,20 @@
|
|||
{% extends 'base.html.twig' %}
|
||||
|
||||
{% block title %}Settings{% endblock %}
|
||||
{% block stylesheets %}
|
||||
{% endblock %}
|
||||
|
||||
{% block javascripts %}
|
||||
{% if ok %}
|
||||
<script>
|
||||
window.setTimeout(function () {
|
||||
toast("Saved");
|
||||
}, 0);
|
||||
</script>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
||||
{% block body %}
|
||||
<h1>Settings</h1>
|
||||
{{ form(form) }}
|
||||
{% endblock %}
|
|
@ -28,7 +28,9 @@
|
|||
</th>
|
||||
</tr>
|
||||
{% for user in users %}
|
||||
{% set canEdit = (user.id == current.id) or (user.isSuperAdmin()) %}
|
||||
{% set isSelf = (user.id == current.id) %}
|
||||
{% set canEdit = current.isSuperAdmin() or not user.isSuperAdmin() %}
|
||||
{% set canDelete = not (isSelf or user.isSuperAdmin()) %}
|
||||
<tr>
|
||||
<td>
|
||||
<input type="checkbox">
|
||||
|
@ -53,8 +55,8 @@
|
|||
</td>
|
||||
<td>
|
||||
<div class="btn-group" role="group">
|
||||
<a class="btn btn-link {% if canEdit %}disabled{% endif %}"
|
||||
href="{{ path("app_user_edit") }}?user={{ user.customId }}">
|
||||
<a class="btn btn-link {% if not canEdit %}disabled{% endif %}"
|
||||
href="{% if isSelf %}{{ path("app_settings") }}{% else %}{{ path("app_user_edit") }}?user={{ user.customId }}{% endif %}">
|
||||
<i class="fas fa-cog"></i>
|
||||
</a>
|
||||
<form action="{{ path("app_user_delete") }}" method="POST">
|
||||
|
@ -65,7 +67,7 @@
|
|||
data-mdb-toggle="dropdown"
|
||||
aria-expanded="false"
|
||||
onclick=""
|
||||
{% if canEdit %}
|
||||
{% if not canDelete %}
|
||||
disabled
|
||||
{% endif %}
|
||||
>
|
||||
|
|
Loading…
Reference in a new issue