MAPG-69 add menu with user info to header

This commit is contained in:
Bence Pőcze 2020-06-14 17:13:54 +02:00
parent 01db72796b
commit 334df3462b
3 changed files with 43 additions and 7 deletions

View File

@ -7,4 +7,6 @@ interface IUser
const PERMISSION_ADMIN = 1; const PERMISSION_ADMIN = 1;
public function hasPermission(int $permission): bool; public function hasPermission(int $permission): bool;
public function getDisplayName(): string;
} }

View File

@ -6,7 +6,7 @@ class User extends BaseModel implements IUser
{ {
private static array $types = ['user', 'admin']; private static array $types = ['user', 'admin'];
protected static array $fields = ['email', 'password', 'type']; protected static array $fields = ['email', 'password', 'type', 'active'];
private string $email; private string $email;
@ -14,6 +14,8 @@ class User extends BaseModel implements IUser
private string $type = 'user'; private string $type = 'user';
private bool $active = false;
public function setEmail(string $email): void public function setEmail(string $email): void
{ {
$this->email = $email; $this->email = $email;
@ -36,6 +38,11 @@ class User extends BaseModel implements IUser
} }
} }
public function setActive($active): void
{
$this->active = (bool) $active;
}
public function getEmail(): string public function getEmail(): string
{ {
return $this->email; return $this->email;
@ -51,6 +58,11 @@ class User extends BaseModel implements IUser
return $this->type; return $this->type;
} }
public function getActive(): bool
{
return $this->active;
}
public function hasPermission(int $permission): bool public function hasPermission(int $permission): bool
{ {
switch ($permission) { switch ($permission) {
@ -63,6 +75,11 @@ class User extends BaseModel implements IUser
} }
} }
public function getDisplayName(): string
{
return $this->email;
}
public function checkPassword(string $password): bool public function checkPassword(string $password): bool
{ {
return password_verify($password, $this->password); return password_verify($password, $this->password);

View File

@ -1,8 +1,25 @@
<div class="header"> <div class="header">
<h1> <div class="grid">
<a href="/" title="MapGuesser"> <h1>
<img class="inline" width="1em" height="1em" src="<?= $_ENV['STATIC_ROOT'] ?>/img/icon.svg?rev=<?= REVISION ?>"> <a href="/" title="MapGuesser">
MapGuesser <img class="inline" width="1em" height="1em" src="<?= $_ENV['STATIC_ROOT'] ?>/img/icon.svg?rev=<?= REVISION ?>">
</a> MapGuesser
</h1> </a>
</h1>
<p>
<?php if (Container::$request->user()) : ?>
<span><a href="/profile" title="Profile">
<?php /* Copyright (c) 2019 The Bootstrap Authors. License can be found in 'USED_SOFTWARE' in section 'Bootstrap Icons'. */ ?>
<svg class="inline" width="1em" height="1em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" d="M3 14s-1 0-1-1 1-4 6-4 6 3 6 4-1 1-1 1H3zm5-6a3 3 0 1 0 0-6 3 3 0 0 0 0 6z"/>
</svg>
<?= Container::$request->user()->getDisplayName() ?><!--
--></a></span><!--
--><span><a href="/logout" title="Logout">Logout</a></span>
<?php else : ?>
<span><a href="/signup" title="Login">Sign up</a></span><!--
--><span><a href="/login" title="Login">Login</a></span>
<?php endif; ?>
</p>
</div>
</div> </div>