From d9f1830d276a52592e69c3f284a43546f12a7bb8 Mon Sep 17 00:00:00 2001 From: as6325400 Date: Sun, 27 Oct 2024 04:35:35 +0800 Subject: [PATCH] button --- webapp/migrations/Version20241026085041.php | 40 +++++++++++++++++++ webapp/src/Entity/User.php | 14 +++++++ webapp/src/Form/Type/UserType.php | 7 ++++ .../menu_change_password_button.html.twig | 17 ++++++++ webapp/templates/team/menu.html.twig | 1 + 5 files changed, 79 insertions(+) create mode 100644 webapp/migrations/Version20241026085041.php create mode 100644 webapp/templates/partials/menu_change_password_button.html.twig diff --git a/webapp/migrations/Version20241026085041.php b/webapp/migrations/Version20241026085041.php new file mode 100644 index 0000000000..de2e1c3e90 --- /dev/null +++ b/webapp/migrations/Version20241026085041.php @@ -0,0 +1,40 @@ +addSql('ALTER TABLE executable DROP zipfile'); + $this->addSql('ALTER TABLE problem CHANGE multipass_limit multipass_limit INT UNSIGNED DEFAULT NULL COMMENT \'Optional limit on the number of rounds; defaults to 1 for traditional problems, 2 for multi-pass problems if not specified.\''); + $this->addSql('ALTER TABLE user ADD can_change_password TINYINT(1) DEFAULT 0 NOT NULL COMMENT \'Whether the user can change their password\''); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE executable ADD zipfile LONGBLOB DEFAULT NULL COMMENT \'Zip file\''); + $this->addSql('ALTER TABLE user DROP can_change_password'); + $this->addSql('ALTER TABLE problem CHANGE multipass_limit multipass_limit INT UNSIGNED DEFAULT NULL COMMENT \'Optional limit on the number of rounds for multi-pass problems; defaults to 2 if not specified.\''); + } + + public function isTransactional(): bool + { + return false; + } +} diff --git a/webapp/src/Entity/User.php b/webapp/src/Entity/User.php index 20a54dcfdb..7783e5860f 100644 --- a/webapp/src/Entity/User.php +++ b/webapp/src/Entity/User.php @@ -120,6 +120,10 @@ class User extends BaseApiEntity implements #[Serializer\Groups([ARC::GROUP_NONSTRICT])] private bool $enabled = true; + #[ORM\Column(options: ['comment' => 'Whether the user can change their password', 'default' => 0])] + #[Serializer\Groups([ARC::GROUP_NONSTRICT])] + private bool $canChangePassword = false; + #[ORM\ManyToOne(inversedBy: 'users')] #[ORM\JoinColumn(name: 'teamid', referencedColumnName: 'teamid', onDelete: 'SET NULL')] #[Serializer\Exclude] @@ -514,4 +518,14 @@ public function getCalculatedExternalId(): string { return $this->getUsername(); } + + public function getCanChangePassword(): bool + { + return $this->canChangePassword; + } + public function setCanChangePassword(bool $canChangePassword): self + { + $this->canChangePassword = $canChangePassword; + return $this; + } } diff --git a/webapp/src/Form/Type/UserType.php b/webapp/src/Form/Type/UserType.php index 73002221d6..bd596f39b7 100644 --- a/webapp/src/Form/Type/UserType.php +++ b/webapp/src/Form/Type/UserType.php @@ -70,6 +70,13 @@ public function buildForm(FormBuilderInterface $builder, array $options): void 'No' => false, ], ]); + $builder->add('canChangePassword', ChoiceType::class, [ + 'expanded' => true, + 'choices' => [ + 'Yes' => true, + 'No' => false, + ], + ]); $builder->add('team', ChoiceType::class, [ 'choice_label' => 'effective_name', 'required' => false, diff --git a/webapp/templates/partials/menu_change_password_button.html.twig b/webapp/templates/partials/menu_change_password_button.html.twig new file mode 100644 index 0000000000..167641446b --- /dev/null +++ b/webapp/templates/partials/menu_change_password_button.html.twig @@ -0,0 +1,17 @@ +{% if is_granted('IS_AUTHENTICATED_FULLY') %} + + Change Password + +{% else %} + {% if allow_registration %} + + Register + + {% endif %} + + Login + +{% endif %} diff --git a/webapp/templates/team/menu.html.twig b/webapp/templates/team/menu.html.twig index 3a47499d63..7e10c3e425 100644 --- a/webapp/templates/team/menu.html.twig +++ b/webapp/templates/team/menu.html.twig @@ -86,6 +86,7 @@ {% include 'partials/menu_login_logout_button.html.twig' with {confirmLogout: true} %} + {% include 'partials/menu_change_password_button.html.twig' with {confirmLogout: true} %}