MAPG-142 save user creation date

This commit is contained in:
Bence Pőcze 2020-07-05 12:49:02 +02:00
parent 38885849de
commit 32392590bd
Signed by: bence
GPG Key ID: AA52B11A3269D1C1
4 changed files with 30 additions and 1 deletions

View File

@ -0,0 +1,2 @@
ALTER TABLE `users`
ADD `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP;

View File

@ -1,5 +1,6 @@
<?php namespace MapGuesser\Cli;
use DateTime;
use MapGuesser\PersistentData\PersistentDataManager;
use MapGuesser\PersistentData\Model\User;
use Symfony\Component\Console\Command\Command;
@ -24,6 +25,7 @@ class AddUserCommand extends Command
$user->setEmail($input->getArgument('email'));
$user->setPlainPassword($input->getArgument('password'));
$user->setActive(true);
$user->setCreatedDate(new DateTime());
if ($input->hasArgument('type')) {
$user->setType($input->getArgument('type'));

View File

@ -311,6 +311,7 @@ class LoginController
$user = new User();
$user->setEmail($this->request->post('email'));
$user->setPlainPassword($this->request->post('password'));
$user->setCreatedDate(new DateTime());
\Container::$dbConnection->startTransaction();
@ -349,6 +350,7 @@ class LoginController
$user = new User();
$user->setEmail($userData['email']);
$user->setCreatedDate(new DateTime());
} else {
$sendWelcomeEmail = false;
}

View File

@ -1,12 +1,13 @@
<?php namespace MapGuesser\PersistentData\Model;
use DateTime;
use MapGuesser\Interfaces\Authentication\IUser;
class User extends Model implements IUser
{
protected static string $table = 'users';
protected static array $fields = ['email', 'password', 'type', 'active', 'google_sub'];
protected static array $fields = ['email', 'password', 'type', 'active', 'google_sub', 'created'];
private static array $types = ['user', 'admin'];
@ -20,6 +21,8 @@ class User extends Model implements IUser
private ?string $googleSub = null;
private DateTime $created;
public function setEmail(string $email): void
{
$this->email = $email;
@ -52,6 +55,16 @@ class User extends Model implements IUser
$this->googleSub = $googleSub;
}
public function setCreatedDate(DateTime $created): void
{
$this->created = $created;
}
public function setCreated(string $created): void
{
$this->created = new DateTime($created);
}
public function getEmail(): string
{
return $this->email;
@ -77,6 +90,16 @@ class User extends Model implements IUser
return $this->googleSub;
}
public function getCreatedData(): DateTime
{
return $this->created;
}
public function getCreated(): string
{
return $this->created->format('Y-m-d H:i:s');
}
public function hasPermission(int $permission): bool
{
switch ($permission) {