Skip to content

Commit

Permalink
Merge pull request #37 from VEAF/feature/23-edit-user-from-list
Browse files Browse the repository at this point in the history
Feature/23 edit user from list
  • Loading branch information
mitch10593 authored Feb 10, 2021
2 parents 23b6c36 + 28a85e3 commit ca100ab
Show file tree
Hide file tree
Showing 22 changed files with 449 additions and 120 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"doctrine/orm": "^2.8",
"karser/karser-recaptcha3-bundle": "^0.1.15",
"kilik/table": "^2.5",
"knplabs/knp-time-bundle": "^1.15",
"phpdocumentor/reflection-docblock": "^5.2",
"sensio/framework-extra-bundle": "^5.1",
"symfony/asset": "4.4.*",
Expand Down
68 changes: 67 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/bundles.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@
Kilik\TableBundle\KilikTableBundle::class => ['all' => true],
Symfony\Bundle\SwiftmailerBundle\SwiftmailerBundle::class => ['all' => true],
Karser\Recaptcha3Bundle\KarserRecaptcha3Bundle::class => ['all' => true],
Knp\Bundle\TimeBundle\KnpTimeBundle::class => ['all' => true],
];
1 change: 1 addition & 0 deletions config/packages/framework.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ framework:
secret: '%env(APP_SECRET)%'
#csrf_protection: true
#http_method_override: true
default_locale: fr

# Enables session support. Note that the session will ONLY be started if you read or write from it.
# Remove or comment this section to explicitly disable session support.
Expand Down
8 changes: 4 additions & 4 deletions fixtures/user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ App\Entity\User:
# test1234
password: '\$2y\$10\$rXysKOG/6HEW9acoV3gISuaxQ6yX5K6aN/.ogx3lQtdsD8R6.E3Ry'
roles: [ROLE_USER]
nickname: 'zip'
nickname: 'fifi'
createdAt: "<dateTimeBetween('-1 month', 'now')>"
updatedAt: "<dateTimeBetween('-1 month', 'now')>"
simBms: false
Expand All @@ -42,7 +42,7 @@ App\Entity\User:
# test1234
password: '\$2y\$10\$rXysKOG/6HEW9acoV3gISuaxQ6yX5K6aN/.ogx3lQtdsD8R6.E3Ry'
roles: [ROLE_USER]
nickname: 'user'
nickname: 'lost'
createdAt: "<dateTimeBetween('-1 month', 'now')>"
updatedAt: "<dateTimeBetween('-1 month', 'now')>"
simBms: false
Expand Down Expand Up @@ -174,7 +174,7 @@ App\Entity\User:
# test1234
password: '\$2y\$10\$rXysKOG/6HEW9acoV3gISuaxQ6yX5K6aN/.ogx3lQtdsD8R6.E3Ry'
roles: [ROLE_USER]
nickname: 'sky'
nickname: 'mge'
createdAt: "<dateTimeBetween('-1 month', 'now')>"
updatedAt: "<dateTimeBetween('-1 month', 'now')>"
simBms: true
Expand All @@ -186,7 +186,7 @@ App\Entity\User:
# test1234
password: '\$2y\$10\$rXysKOG/6HEW9acoV3gISuaxQ6yX5K6aN/.ogx3lQtdsD8R6.E3Ry'
roles: [ROLE_USER]
nickname: 'firstName'
nickname: '<firstName()>'
createdAt: "<dateTimeBetween('-1 month', 'now')>"
updatedAt: "<dateTimeBetween('-1 month', 'now')>"
simBms: true
Expand Down
1 change: 1 addition & 0 deletions migrations/Version20210207121750.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function up(Schema $schema) : void
$this->addSql('ALTER TABLE pe_OnlinePlayers ADD CONSTRAINT FK_676CFD2FB0467609 FOREIGN KEY (pe_OnlinePlayers_id) REFERENCES pe_DataPlayers (pe_DataPlayers_id)');
$this->addSql('ALTER TABLE pe_OnlinePlayers ADD CONSTRAINT FK_676CFD2FC31A124 FOREIGN KEY (pe_OnlinePlayers_instance) REFERENCES pe_OnlineStatus (pe_OnlineStatus_instance)');
$this->addSql('ALTER TABLE user ADD CONSTRAINT FK_8D93D64999E6F5DF FOREIGN KEY (player_id) REFERENCES pe_DataPlayers (pe_DataPlayers_id)');
$this->addSql('CREATE TABLE pe_LogEvent (pe_LogEvent_id BIGINT AUTO_INCREMENT NOT NULL, pe_LogEvent_datetime DATETIME DEFAULT CURRENT_TIMESTAMP, pe_LogEvent_missionhash_id BIGINT DEFAULT NULL, pe_LogEvent_type VARCHAR(100) CHARACTER SET utf8 NOT NULL COLLATE `utf8_general_ci`, pe_LogEvent_content TEXT CHARACTER SET utf8 NOT NULL COLLATE `utf8_general_ci`, pe_LogEvent_arg1 VARCHAR(150) CHARACTER SET utf8 DEFAULT NULL COLLATE `utf8_general_ci`, pe_LogEvent_arg2 VARCHAR(150) CHARACTER SET utf8 DEFAULT NULL COLLATE `utf8_general_ci`, pe_LogEvent_argPlayers VARCHAR(150) CHARACTER SET utf8 DEFAULT NULL COLLATE `utf8_general_ci`, INDEX pe_LogEvent_datetime (pe_LogEvent_datetime), INDEX pe_LogEvent_type_2 (pe_LogEvent_type), INDEX pe_LogEvent_missionhash_id (pe_LogEvent_missionhash_id), PRIMARY KEY(pe_LogEvent_id)) DEFAULT CHARACTER SET utf8 COLLATE `utf8_unicode_ci` ENGINE = InnoDB COMMENT = \'\' ');
}

public function down(Schema $schema) : void
Expand Down
31 changes: 0 additions & 31 deletions migrations/Version20210209220324.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20210208184131 extends AbstractMigration
final class Version20210210205251 extends AbstractMigration
{
public function getDescription() : string
{
Expand All @@ -20,12 +20,16 @@ public function getDescription() : string
public function up(Schema $schema) : void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE user ADD password_request_token VARCHAR(255) DEFAULT NULL, ADD created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, ADD updated_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL');
$this->addSql('ALTER TABLE user ADD password_request_token VARCHAR(255) DEFAULT NULL, ADD created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, ADD updated_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, ADD sim_bms TINYINT(1) NOT NULL, ADD sim_dcs TINYINT(1) NOT NULL, ADD status INT DEFAULT NULL');
$this->addSql('CREATE UNIQUE INDEX nickname_idx ON user (nickname)');
$this->addSql('ALTER TABLE user RENAME INDEX uniq_8d93d649e7927c74 TO email_idx');
}

public function down(Schema $schema) : void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE user DROP password_request_token, DROP created_at, DROP updated_at');
$this->addSql('DROP INDEX nickname_idx ON user');
$this->addSql('ALTER TABLE user DROP password_request_token, DROP created_at, DROP updated_at, DROP sim_bms, DROP sim_dcs, DROP status');
$this->addSql('ALTER TABLE user RENAME INDEX email_idx TO UNIQ_8D93D649E7927C74');
}
}
26 changes: 22 additions & 4 deletions public/css/custom.css
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
body {
padding-top: 100px;
background-color:white;
background-image:url(https://cdn.veaf.org/website/dev/img/background-01-blur.jpg);
background-attachment:fixed;
background-color: white;
background-image: url(https://cdn.veaf.org/website/dev/img/background-01-blur.jpg);
background-attachment: fixed;
background-repeat: no-repeat;
min-height: 100%;
}

body, html {
height: 100%;
}

pre {
Expand Down Expand Up @@ -152,6 +155,10 @@ iframe {
margin-bottom: 10px
}

#main {
min-height: 100%;
}

#footer {
margin: 1em 0
}
Expand All @@ -167,6 +174,17 @@ iframe {
margin-bottom: 0
}

#footer {
padding-top: 10px;
padding-left: 50px;
padding-right: 50px;
/*height:150px;*/
/*position:absolute;*/
width: 100%;
bottom: 0;
background-color: rgba(255, 255, 255, .5);
}

.splash {
padding: 12em 0 6em;
background: #349aed;
Expand Down
35 changes: 35 additions & 0 deletions src/Controller/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Controller\Admin;

use App\Entity\User;
use App\Form\UserType;
use App\Manager\UserManager;
use Kilik\TableBundle\Components\Column;
use Kilik\TableBundle\Components\Filter;
use Kilik\TableBundle\Components\FilterSelect;
Expand Down Expand Up @@ -129,4 +131,37 @@ public function _listAction(TableService $tableService, Request $request)
{
return $tableService->handleRequest($this->getTable(), $request);
}

/**
* @Route("/{user}", name="admin_user_view")
*/
public function view(User $user): Response
{
return $this->render('admin/user/view.html.twig', [
'user' => $user,
]);
}

/**
* @Route("/{user}/edit", name="admin_user_edit")
*/
public function edit(UserManager $userManager, Request $request, User $user): Response
{
$form = $this->createForm(UserType::class, $user);

$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$userManager->save($user, true, true);
$this->addFlash('success', 'L\'utilisateur a été enregistré');

return $this->redirectToRoute('admin_user_view', ['user' => $user->getId()]);
}

return $this->render('admin/user/edit.html.twig', [
'form' => $form->createView(),
'user' => $user,
]);
}

}
2 changes: 1 addition & 1 deletion src/Controller/RegistrationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function register(
$tokenStorage->setToken($token);
$session->set('_security_main', serialize($token));

return $this->redirectToRoute('home');
return $this->redirectToRoute('app_login');
}

return $this->render(
Expand Down
17 changes: 11 additions & 6 deletions src/Controller/ResetPasswordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Entity\User;
use App\Form\NewPasswordType;
use App\Form\PasswordRequestType;
use App\Manager\UserManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -33,8 +34,10 @@ public function __construct(string $mailFrom)
public function reset(
Request $request,
EntityManagerInterface $entityManager,
\Swift_Mailer $mailer
) {
\Swift_Mailer $mailer,
UserManager $userManager
)
{
$form = $this->createForm(PasswordRequestType::class);
$form->handleRequest($request);

Expand All @@ -45,7 +48,7 @@ public function reset(
if ($user instanceof User) {
$token = bin2hex(random_bytes(32));
$user->setPasswordRequestToken($token);
$entityManager->flush();
$userManager->save($user, true, true);
// send your email with SwiftMailer or anything else here
$this->addFlash('success', 'Si l\'adresse email est correcte, vous allez recevoir un email');

Expand Down Expand Up @@ -95,8 +98,10 @@ public function confirm(
EntityManagerInterface $entityManager,
UserPasswordEncoderInterface $encoder,
TokenStorageInterface $tokenStorage,
SessionInterface $session
) {
SessionInterface $session,
UserManager $userManager
)
{
$user = $entityManager->getRepository(User::class)->findOneBy(['passwordRequestToken' => $token]);

if (!$token || !$user instanceof User) {
Expand All @@ -113,7 +118,7 @@ public function confirm(
$password = $encoder->encodePassword($user, $plainPassword);
$user->setPassword($password);
$user->setPasswordRequestToken(null);
$entityManager->flush();
$userManager->save($user, true, true);

$token = new UsernamePasswordToken($user, $password, 'main');
$tokenStorage->setToken($token);
Expand Down
Loading

0 comments on commit ca100ab

Please sign in to comment.