MAPG-142 save user creation date
This commit is contained in:
		
							parent
							
								
									38885849de
								
							
						
					
					
						commit
						32392590bd
					
				@ -0,0 +1,2 @@
 | 
			
		||||
ALTER TABLE `users`
 | 
			
		||||
  ADD `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP;
 | 
			
		||||
@ -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'));
 | 
			
		||||
 | 
			
		||||
@ -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;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -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) {
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user