Skip to content

Commit 31e249f

Browse files
committed
Changed Autoload PSR-4
1 parent 0cc03ab commit 31e249f

13 files changed

+28
-38
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"autoload": {
1313
"psr-4": {
14-
"Auth\\" : "./"
14+
"Riculum\\Auth\\" : "src/"
1515
}
1616
},
1717
"require": {

setup/database.sql

+2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
CREATE TABLE IF NOT EXISTS user (
22
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
33
uuid VARCHAR(50) NOT NULL UNIQUE,
4+
gender ENUM('male', 'female') NOT NULL,
45
firstname VARCHAR(50) NOT NULL,
56
lastname VARCHAR(50) NOT NULL,
67
email VARCHAR(100) NOT NULL UNIQUE,
78
password VARCHAR(255) NOT NULL,
89
token VARCHAR(255) NOT NULL,
10+
resetToken VARCHAR(255) NOT NULL,
911
attempts TINYINT NOT NULL DEFAULT 0,
1012
online TINYINT NOT NULL DEFAULT 0,
1113
verified TINYINT NOT NULL DEFAULT 0,

core/Authentication.php renamed to src/Authentication.php

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?php
2-
namespace Auth\Core;
2+
namespace Riculum\Auth;
33

4-
use Auth\Exceptions\InvalidEmailException;
5-
use Auth\Exceptions\InvalidPasswordException;
6-
use Auth\Exceptions\TooManyAttemptsException;
7-
use Auth\Exceptions\UserAlreadyExistsException;
8-
use Auth\Exceptions\UserNotEnabledException;
4+
use Riculum\Auth\core\Session;
5+
use Riculum\Auth\core\User;
6+
use Riculum\Auth\exceptions\InvalidEmailException;
7+
use Riculum\Auth\exceptions\InvalidPasswordException;
8+
use Riculum\Auth\exceptions\TooManyAttemptsException;
9+
use Riculum\Auth\exceptions\UserAlreadyExistsException;
10+
use Riculum\Auth\exceptions\UserNotEnabledException;
911

1012
class Authentication
1113
{
@@ -47,11 +49,13 @@ static function login(string $email, string $password): bool
4749
return true;
4850
}
4951

50-
static function logout()
52+
static function logout(): bool
5153
{
5254
if (!empty(Session::getUserUUID())) {
5355
User::logout();
5456
}
57+
58+
return true;
5559
}
5660

5761
static function verify(): bool

core/Session.php renamed to src/core/Session.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
namespace Auth\Core;
2+
namespace Riculum\Auth\core;
33

44
if (session_status() == PHP_SESSION_NONE) {
55
session_start();

core/User.php renamed to src/core/User.php

+5-21
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
2-
namespace Auth\Core;
2+
namespace Riculum\Auth\core;
33

4-
use Auth\Exceptions\UserAlreadyExistsException;
5-
use Database\Core\Database as DB;
64
use Exception;
5+
use Riculum\Auth\exceptions\UserAlreadyExistsException;
6+
use Riculum\Database as DB;
77

88
class User
99
{
@@ -18,7 +18,7 @@ private static function emailIsUnique(string $email): bool
1818
}
1919

2020
/**
21-
* Output the 36 character UUID
21+
* Output the 36 character UUIDv4
2222
* @throws Exception
2323
*/
2424
private static function generateUuid(): string
@@ -76,21 +76,13 @@ static function addUser(array $user): ?int
7676
{
7777
if (self::emailIsUnique($user['email'])) {
7878
$user['uuid'] = self::generateUuid();
79+
$user['resetToken'] = bin2hex(random_bytes(16));
7980
return DB::insertAssoc($_ENV['DB_PREFIX'].'user', $user);
8081
} else {
8182
throw new UserAlreadyExistsException('User with email ' . $user['email'] . ' already exists');
8283
}
8384
}
8485

85-
/**
86-
* @param string $uuid
87-
* @return void
88-
*/
89-
static function deleteUser(string $uuid)
90-
{
91-
DB::delete("DELETE FROM " . $_ENV['DB_PREFIX'] . "user WHERE uuid = ?", [$uuid]);
92-
}
93-
9486
/**
9587
* @param string $uuid
9688
* @return array|null
@@ -100,14 +92,6 @@ static function getUser(string $uuid): ?array
10092
return DB::single('SELECT * FROM ' . $_ENV['DB_PREFIX'] . 'user WHERE uuid = ?', [$uuid]);
10193
}
10294

103-
/**
104-
* @return array|null
105-
*/
106-
static function getUsers(): ?array
107-
{
108-
return DB::select('SELECT * FROM ' . $_ENV['DB_PREFIX'] . 'user', []);
109-
}
110-
11195
/**
11296
* @param string $email
11397
* @return array|null
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?php
2-
namespace Auth\Exceptions;
2+
namespace Riculum\Auth\exceptions;
33

44
class ForbiddenException extends \Exception {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?php
2-
namespace Auth\Exceptions;
2+
namespace Riculum\Auth\exceptions;
33

44
class InvalidEmailException extends \Exception {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?php
2-
namespace Auth\Exceptions;
2+
namespace Riculum\Auth\exceptions;
33

44
class InvalidPasswordException extends \Exception {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?php
2-
namespace Auth\Exceptions;
2+
namespace Riculum\Auth\exceptions;
33

44
class InvalidTokenException extends \Exception {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?php
2-
namespace Auth\Exceptions;
2+
namespace Riculum\Auth\exceptions;
33

44
class NotFoundException extends \Exception {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?php
2-
namespace Auth\Exceptions;
2+
namespace Riculum\Auth\exceptions;
33

44
class TooManyAttemptsException extends \Exception {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?php
2-
namespace Auth\Exceptions;
2+
namespace Riculum\Auth\exceptions;
33

44
class UserAlreadyExistsException extends \Exception {}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<?php
2-
namespace Auth\Exceptions;
2+
namespace Riculum\Auth\exceptions;
33

44
class UserNotEnabledException extends \Exception {}

0 commit comments

Comments
 (0)