@@ -1,21 +1,21 @@ |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | |
| 3 | -namespace App\Facades; |
|
| 3 | + namespace App\Facades; |
|
| 4 | 4 | |
| 5 | -use Illuminate\Support\Facades\Facade; |
|
| 5 | + use Illuminate\Support\Facades\Facade; |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * Class Validation. |
| 9 | 9 | */ |
| 10 | -class Validation extends Facade |
|
| 11 | -{ |
|
| 12 | - /** |
|
| 10 | + class Validation extends Facade |
|
| 11 | + { |
|
| 12 | + /** |
|
| 13 | 13 | * Get the registered name of the component. |
| 14 | 14 | * |
| 15 | 15 | * @return string |
| 16 | 16 | */ |
| 17 | - protected static function getFacadeAccessor() |
|
| 18 | - { |
|
| 19 | - return 'chocovalidate'; |
|
| 20 | - } |
|
| 17 | + protected static function getFacadeAccessor() |
|
| 18 | + { |
|
| 19 | + return 'chocovalidate'; |
|
| 20 | + } |
|
| 21 | 21 | } |
@@ -1,24 +1,24 @@ |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | |
| 3 | -namespace App\Providers; |
|
| 3 | + namespace App\Providers; |
|
| 4 | 4 | |
| 5 | -use App\Helpers\Validation; |
|
| 6 | -use Illuminate\Support\ServiceProvider; |
|
| 5 | + use App\Helpers\Validation; |
|
| 6 | + use Illuminate\Support\ServiceProvider; |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Class ValidationServiceProvider. |
| 10 | 10 | */ |
| 11 | -class ValidationServiceProvider extends ServiceProvider |
|
| 12 | -{ |
|
| 13 | - /** |
|
| 11 | + class ValidationServiceProvider extends ServiceProvider |
|
| 12 | + { |
|
| 13 | + /** |
|
| 14 | 14 | * Register the Session Service Provider. |
| 15 | 15 | * |
| 16 | 16 | * @return void |
| 17 | 17 | */ |
| 18 | - public function register() |
|
| 19 | - { |
|
| 20 | - $this->app->bind('chocovalidate', function () { |
|
| 21 | - return Validation::getInstance(); |
|
| 22 | - }); |
|
| 23 | - } |
|
| 18 | + public function register() |
|
| 19 | + { |
|
| 20 | + $this->app->bind('chocovalidate', function () { |
|
| 21 | + return Validation::getInstance(); |
|
| 22 | + }); |
|
| 23 | + } |
|
| 24 | 24 | } |
@@ -1,26 +1,26 @@ |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | |
| 3 | -namespace App\Providers; |
|
| 3 | + namespace App\Providers; |
|
| 4 | 4 | |
| 5 | -use App\Helpers\User; |
|
| 6 | -use Illuminate\Support\ServiceProvider; |
|
| 5 | + use App\Helpers\User; |
|
| 6 | + use Illuminate\Support\ServiceProvider; |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Class AuthServiceProvider. |
| 10 | 10 | */ |
| 11 | -class AuthServiceProvider extends ServiceProvider |
|
| 12 | -{ |
|
| 13 | - /** |
|
| 11 | + class AuthServiceProvider extends ServiceProvider |
|
| 12 | + { |
|
| 13 | + /** |
|
| 14 | 14 | * Boot the authentication services for the application. |
| 15 | 15 | * If an User is stored in the Session recover it |
| 16 | 16 | * Only will recover if the Path() isn't the Authentcation Path. |
| 17 | 17 | * |
| 18 | 18 | * @return void |
| 19 | 19 | */ |
| 20 | - public function boot() |
|
| 21 | - { |
|
| 22 | - $this->app['auth']->viaRequest('api', function ($request) { |
|
| 23 | - return User::getInstance()->getUser(); |
|
| 24 | - }); |
|
| 25 | - } |
|
| 20 | + public function boot() |
|
| 21 | + { |
|
| 22 | + $this->app['auth']->viaRequest('api', function ($request) { |
|
| 23 | + return User::getInstance()->getUser(); |
|
| 24 | + }); |
|
| 25 | + } |
|
| 26 | 26 | } |
@@ -1,24 +1,24 @@ |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | |
| 3 | -namespace App\Providers; |
|
| 3 | + namespace App\Providers; |
|
| 4 | 4 | |
| 5 | -use Illuminate\Support\ServiceProvider; |
|
| 5 | + use Illuminate\Support\ServiceProvider; |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * Class AppServiceProvider. |
| 9 | 9 | */ |
| 10 | -class AppServiceProvider extends ServiceProvider |
|
| 11 | -{ |
|
| 12 | - /** |
|
| 10 | + class AppServiceProvider extends ServiceProvider |
|
| 11 | + { |
|
| 12 | + /** |
|
| 13 | 13 | * Register any application services. |
| 14 | 14 | * |
| 15 | 15 | * @return void |
| 16 | 16 | */ |
| 17 | - public function register() |
|
| 18 | - { |
|
| 19 | - // Register Mailing Services |
|
| 20 | - $this->app->singleton('mailer', function ($app) { |
|
| 21 | - return $app->loadComponent('mail', 'Illuminate\Mail\MailServiceProvider', 'mailer'); |
|
| 22 | - }); |
|
| 23 | - } |
|
| 17 | + public function register() |
|
| 18 | + { |
|
| 19 | + // Register Mailing Services |
|
| 20 | + $this->app->singleton('mailer', function ($app) { |
|
| 21 | + return $app->loadComponent('mail', 'Illuminate\Mail\MailServiceProvider', 'mailer'); |
|
| 22 | + }); |
|
| 23 | + } |
|
| 24 | 24 | } |
@@ -1,30 +1,30 @@ |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | |
| 3 | -namespace App\Providers; |
|
| 3 | + namespace App\Providers; |
|
| 4 | 4 | |
| 5 | -use App\Facades\User; |
|
| 6 | -use Illuminate\Support\Facades\Config; |
|
| 7 | -use Illuminate\Support\Facades\View; |
|
| 8 | -use Illuminate\Support\ServiceProvider; |
|
| 5 | + use App\Facades\User; |
|
| 6 | + use Illuminate\Support\Facades\Config; |
|
| 7 | + use Illuminate\Support\Facades\View; |
|
| 8 | + use Illuminate\Support\ServiceProvider; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Class ViewServiceProvider. |
| 12 | 12 | */ |
| 13 | -class ViewServiceProvider extends ServiceProvider |
|
| 14 | -{ |
|
| 15 | - /** |
|
| 13 | + class ViewServiceProvider extends ServiceProvider |
|
| 14 | + { |
|
| 15 | + /** |
|
| 16 | 16 | * Configures all Global Blade Variables. |
| 17 | 17 | * |
| 18 | 18 | * @return void |
| 19 | 19 | */ |
| 20 | - public function register() |
|
| 21 | - { |
|
| 22 | - View::share('chocolatey', json_decode(json_encode(Config::get('chocolatey')))); |
|
| 20 | + public function register() |
|
| 21 | + { |
|
| 22 | + View::share('chocolatey', json_decode(json_encode(Config::get('chocolatey')))); |
|
| 23 | 23 | |
| 24 | - View::share('user', User::getUser() ?? 'null'); |
|
| 24 | + View::share('user', User::getUser() ?? 'null'); |
|
| 25 | 25 | |
| 26 | - View::share('mail', json_decode(json_encode(Config::get('mail')))); |
|
| 26 | + View::share('mail', json_decode(json_encode(Config::get('mail')))); |
|
| 27 | 27 | |
| 28 | - View::share('maintenance', json_decode(json_encode(Config::get('maintenance')))); |
|
| 29 | - } |
|
| 28 | + View::share('maintenance', json_decode(json_encode(Config::get('maintenance')))); |
|
| 29 | + } |
|
| 30 | 30 | } |
@@ -1,41 +1,41 @@ discard block |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | |
| 3 | -namespace App\Helpers; |
|
| 3 | + namespace App\Helpers; |
|
| 4 | 4 | |
| 5 | -use App\Models\Mail as MailModel; |
|
| 6 | -use App\Singleton; |
|
| 7 | -use Illuminate\Support\Facades\Config; |
|
| 8 | -use Illuminate\Support\Facades\Mail as MailFacade; |
|
| 5 | + use App\Models\Mail as MailModel; |
|
| 6 | + use App\Singleton; |
|
| 7 | + use Illuminate\Support\Facades\Config; |
|
| 8 | + use Illuminate\Support\Facades\Mail as MailFacade; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Class Mail. |
| 12 | 12 | */ |
| 13 | -final class Mail extends Singleton |
|
| 14 | -{ |
|
| 15 | - /** |
|
| 13 | + final class Mail extends Singleton |
|
| 14 | + { |
|
| 15 | + /** |
|
| 16 | 16 | * Stored Mail Model. |
| 17 | 17 | * |
| 18 | 18 | * @var MailModel |
| 19 | 19 | */ |
| 20 | - protected $mailModel; |
|
| 20 | + protected $mailModel; |
|
| 21 | 21 | |
| 22 | - /** |
|
| 22 | + /** |
|
| 23 | 23 | * Send an Email. |
| 24 | 24 | * |
| 25 | 25 | * @param array $configuration |
| 26 | 26 | * @param string $view |
| 27 | 27 | */ |
| 28 | - public function send(array $configuration, string $view = 'habbo-web-mail.confirm-mail') |
|
| 29 | - { |
|
| 30 | - if (Config::get('mail.enable')) { |
|
| 31 | - MailFacade::send($view, $configuration, function ($message) use ($configuration) { |
|
| 32 | - $message->from(Config::get('mail.from.address'), Config::get('mail.from.name')); |
|
| 33 | - $message->to($configuration['email'])->subject($configuration['subject']); |
|
| 34 | - }); |
|
| 35 | - } |
|
| 36 | - } |
|
| 28 | + public function send(array $configuration, string $view = 'habbo-web-mail.confirm-mail') |
|
| 29 | + { |
|
| 30 | + if (Config::get('mail.enable')) { |
|
| 31 | + MailFacade::send($view, $configuration, function ($message) use ($configuration) { |
|
| 32 | + $message->from(Config::get('mail.from.address'), Config::get('mail.from.name')); |
|
| 33 | + $message->to($configuration['email'])->subject($configuration['subject']); |
|
| 34 | + }); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | + /** |
|
| 39 | 39 | * Store an E-mail. |
| 40 | 40 | * |
| 41 | 41 | * @param string $email |
@@ -43,72 +43,72 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return string |
| 45 | 45 | */ |
| 46 | - public function store(string $email, string $url): string |
|
| 47 | - { |
|
| 48 | - (new MailModel())->store($token = uniqid('HabboMail', true), $url, $email, date('Y-m-d H:i:s', time())); |
|
| 46 | + public function store(string $email, string $url): string |
|
| 47 | + { |
|
| 48 | + (new MailModel())->store($token = uniqid('HabboMail', true), $url, $email, date('Y-m-d H:i:s', time())); |
|
| 49 | 49 | |
| 50 | - return $token; |
|
| 51 | - } |
|
| 50 | + return $token; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 53 | + /** |
|
| 54 | 54 | * Return if Exists E-Mail with that Token. |
| 55 | 55 | * |
| 56 | 56 | * @param string $token |
| 57 | 57 | * |
| 58 | 58 | * @return bool |
| 59 | 59 | */ |
| 60 | - public function has(string $token) |
|
| 61 | - { |
|
| 62 | - return $this->get($token) !== null; |
|
| 63 | - } |
|
| 60 | + public function has(string $token) |
|
| 61 | + { |
|
| 62 | + return $this->get($token) !== null; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 65 | + /** |
|
| 66 | 66 | * Get an E-mail by Token. |
| 67 | 67 | * |
| 68 | 68 | * @param string $token |
| 69 | 69 | * |
| 70 | 70 | * @return MailModel |
| 71 | 71 | */ |
| 72 | - public function get(string $token = '') |
|
| 73 | - { |
|
| 74 | - if ($this->mailModel == null && !empty($token)) { |
|
| 75 | - $mailModel = MailModel::where('token', $token)->where('used', '0')->first(); |
|
| 72 | + public function get(string $token = '') |
|
| 73 | + { |
|
| 74 | + if ($this->mailModel == null && !empty($token)) { |
|
| 75 | + $mailModel = MailModel::where('token', $token)->where('used', '0')->first(); |
|
| 76 | 76 | |
| 77 | - if ($mailModel !== null) { |
|
| 78 | - if (strtotime($mailModel->created_at) + (Config::get('mail.expire') * 24 * 60 * 60) >= time()) { |
|
| 79 | - $this->set($mailModel); |
|
| 77 | + if ($mailModel !== null) { |
|
| 78 | + if (strtotime($mailModel->created_at) + (Config::get('mail.expire') * 24 * 60 * 60) >= time()) { |
|
| 79 | + $this->set($mailModel); |
|
| 80 | 80 | |
| 81 | - $this->update(['used' => '1']); |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - } |
|
| 81 | + $this->update(['used' => '1']); |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - return $this->mailModel; |
|
| 87 | - } |
|
| 86 | + return $this->mailModel; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - /** |
|
| 89 | + /** |
|
| 90 | 90 | * Set Mail Model in Cache. |
| 91 | 91 | * |
| 92 | 92 | * @param MailModel $model |
| 93 | 93 | * |
| 94 | 94 | * @return MailModel |
| 95 | 95 | */ |
| 96 | - public function set(MailModel $model) |
|
| 97 | - { |
|
| 98 | - return $this->mailModel = $model; |
|
| 99 | - } |
|
| 96 | + public function set(MailModel $model) |
|
| 97 | + { |
|
| 98 | + return $this->mailModel = $model; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - /** |
|
| 101 | + /** |
|
| 102 | 102 | * Update Mail Model Data. |
| 103 | 103 | * |
| 104 | 104 | * @param array $parameters |
| 105 | 105 | * |
| 106 | 106 | * @return MailModel |
| 107 | 107 | */ |
| 108 | - public function update(array $parameters) |
|
| 109 | - { |
|
| 110 | - $this->mailModel->update($parameters); |
|
| 108 | + public function update(array $parameters) |
|
| 109 | + { |
|
| 110 | + $this->mailModel->update($parameters); |
|
| 111 | 111 | |
| 112 | - return $this->mailModel; |
|
| 113 | - } |
|
| 112 | + return $this->mailModel; |
|
| 113 | + } |
|
| 114 | 114 | } |
@@ -1,29 +1,29 @@ discard block |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | |
| 3 | -namespace App\Helpers; |
|
| 3 | + namespace App\Helpers; |
|
| 4 | 4 | |
| 5 | -use App\Singleton; |
|
| 6 | -use Illuminate\Support\Facades\Config; |
|
| 5 | + use App\Singleton; |
|
| 6 | + use Illuminate\Support\Facades\Config; |
|
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | 9 | * Class Validation. |
| 10 | 10 | */ |
| 11 | -final class Validation extends Singleton |
|
| 12 | -{ |
|
| 13 | - /** |
|
| 11 | + final class Validation extends Singleton |
|
| 12 | + { |
|
| 13 | + /** |
|
| 14 | 14 | * Filter an Username from the Invalid Names Base. |
| 15 | 15 | * |
| 16 | 16 | * @param string $username |
| 17 | 17 | * |
| 18 | 18 | * @return bool |
| 19 | 19 | */ |
| 20 | - public function filterUserName(string $username): bool |
|
| 21 | - { |
|
| 22 | - return $this->checkSize($username, 4, 15) && $this->checkWords($username) && |
|
| 23 | - preg_match('/^[a-zA-Z0-9_\-=?!@:.$]+$/', $username); |
|
| 24 | - } |
|
| 20 | + public function filterUserName(string $username): bool |
|
| 21 | + { |
|
| 22 | + return $this->checkSize($username, 4, 15) && $this->checkWords($username) && |
|
| 23 | + preg_match('/^[a-zA-Z0-9_\-=?!@:.$]+$/', $username); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | - /** |
|
| 26 | + /** |
|
| 27 | 27 | * Check String Size. |
| 28 | 28 | * |
| 29 | 29 | * @param string $needle |
@@ -32,22 +32,22 @@ discard block |
||
| 32 | 32 | * |
| 33 | 33 | * @return bool |
| 34 | 34 | */ |
| 35 | - public function checkSize(string $needle, int $min, int $max) |
|
| 36 | - { |
|
| 37 | - return strlen($needle) <= $max && strlen($needle) >= $min; |
|
| 38 | - } |
|
| 35 | + public function checkSize(string $needle, int $min, int $max) |
|
| 36 | + { |
|
| 37 | + return strlen($needle) <= $max && strlen($needle) >= $min; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 40 | + /** |
|
| 41 | 41 | * Check for Illegal Words. |
| 42 | 42 | * |
| 43 | 43 | * @param string $needle |
| 44 | 44 | * |
| 45 | 45 | * @return bool |
| 46 | 46 | */ |
| 47 | - public function checkWords(string $needle): bool |
|
| 48 | - { |
|
| 49 | - return count(array_filter(Config::get('chocolatey.invalid'), function ($illegal) use ($needle) { |
|
| 50 | - return stripos($needle, $illegal) !== false; |
|
| 51 | - })) == 0; |
|
| 52 | - } |
|
| 47 | + public function checkWords(string $needle): bool |
|
| 48 | + { |
|
| 49 | + return count(array_filter(Config::get('chocolatey.invalid'), function ($illegal) use ($needle) { |
|
| 50 | + return stripos($needle, $illegal) !== false; |
|
| 51 | + })) == 0; |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -1,41 +1,41 @@ discard block |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | |
| 3 | -namespace App\Helpers; |
|
| 3 | + namespace App\Helpers; |
|
| 4 | 4 | |
| 5 | -use App\Singleton; |
|
| 5 | + use App\Singleton; |
|
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * Class Session. |
| 9 | 9 | */ |
| 10 | -final class Session extends Singleton |
|
| 11 | -{ |
|
| 12 | - /** |
|
| 10 | + final class Session extends Singleton |
|
| 11 | + { |
|
| 12 | + /** |
|
| 13 | 13 | * Rename the Session ID. |
| 14 | 14 | * |
| 15 | 15 | * @param string $name |
| 16 | 16 | */ |
| 17 | - public function rename($name) |
|
| 18 | - { |
|
| 19 | - session_name($name); |
|
| 20 | - } |
|
| 17 | + public function rename($name) |
|
| 18 | + { |
|
| 19 | + session_name($name); |
|
| 20 | + } |
|
| 21 | 21 | |
| 22 | - /** |
|
| 22 | + /** |
|
| 23 | 23 | * Start Session Handler. |
| 24 | 24 | */ |
| 25 | - public function start() |
|
| 26 | - { |
|
| 27 | - @session_start(); |
|
| 28 | - } |
|
| 25 | + public function start() |
|
| 26 | + { |
|
| 27 | + @session_start(); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 30 | + /** |
|
| 31 | 31 | * Stop Session Handler. |
| 32 | 32 | */ |
| 33 | - public function destroy() |
|
| 34 | - { |
|
| 35 | - @session_destroy(); |
|
| 36 | - } |
|
| 33 | + public function destroy() |
|
| 34 | + { |
|
| 35 | + @session_destroy(); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | + /** |
|
| 39 | 39 | * Store a Variable in the Session. |
| 40 | 40 | * |
| 41 | 41 | * @param string $key |
@@ -43,46 +43,46 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return mixed |
| 45 | 45 | */ |
| 46 | - public function set($key, $value) |
|
| 47 | - { |
|
| 48 | - $_SESSION[$key] = $value; |
|
| 46 | + public function set($key, $value) |
|
| 47 | + { |
|
| 48 | + $_SESSION[$key] = $value; |
|
| 49 | 49 | |
| 50 | - return $value; |
|
| 51 | - } |
|
| 50 | + return $value; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 53 | + /** |
|
| 54 | 54 | * Get a Attribute Value from Session. |
| 55 | 55 | * |
| 56 | 56 | * @param string $key |
| 57 | 57 | * |
| 58 | 58 | * @return mixed |
| 59 | 59 | */ |
| 60 | - public function get($key) |
|
| 61 | - { |
|
| 62 | - return $this->has($key) ? $_SESSION[$key] : null; |
|
| 63 | - } |
|
| 60 | + public function get($key) |
|
| 61 | + { |
|
| 62 | + return $this->has($key) ? $_SESSION[$key] : null; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 65 | + /** |
|
| 66 | 66 | * Check if a Key exists in the Session. |
| 67 | 67 | * |
| 68 | 68 | * @param mixed $key |
| 69 | 69 | * |
| 70 | 70 | * @return bool |
| 71 | 71 | */ |
| 72 | - public function has($key) |
|
| 73 | - { |
|
| 74 | - return array_key_exists($key, $_SESSION); |
|
| 75 | - } |
|
| 72 | + public function has($key) |
|
| 73 | + { |
|
| 74 | + return array_key_exists($key, $_SESSION); |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 77 | + /** |
|
| 78 | 78 | * Erase a Attribute from Session. |
| 79 | 79 | * |
| 80 | 80 | * @param string $key |
| 81 | 81 | */ |
| 82 | - public function erase($key) |
|
| 83 | - { |
|
| 84 | - $_SESSION[$key] = null; |
|
| 82 | + public function erase($key) |
|
| 83 | + { |
|
| 84 | + $_SESSION[$key] = null; |
|
| 85 | 85 | |
| 86 | - unset($_SESSION[$key]); |
|
| 87 | - } |
|
| 86 | + unset($_SESSION[$key]); |
|
| 87 | + } |
|
| 88 | 88 | } |
@@ -1,44 +1,44 @@ discard block |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | |
| 3 | -namespace App\Helpers; |
|
| 3 | + namespace App\Helpers; |
|
| 4 | 4 | |
| 5 | -use App\Facades\Session; |
|
| 6 | -use App\Models\ChocolateyId; |
|
| 7 | -use App\Models\User as UserModel; |
|
| 8 | -use App\Singleton; |
|
| 9 | -use Illuminate\Http\Request; |
|
| 10 | -use Illuminate\Support\Facades\Config; |
|
| 5 | + use App\Facades\Session; |
|
| 6 | + use App\Models\ChocolateyId; |
|
| 7 | + use App\Models\User as UserModel; |
|
| 8 | + use App\Singleton; |
|
| 9 | + use Illuminate\Http\Request; |
|
| 10 | + use Illuminate\Support\Facades\Config; |
|
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | 13 | * Class User. |
| 14 | 14 | */ |
| 15 | -final class User extends Singleton |
|
| 16 | -{ |
|
| 17 | - /** |
|
| 15 | + final class User extends Singleton |
|
| 16 | + { |
|
| 17 | + /** |
|
| 18 | 18 | * Update User Data without overwriting Session. |
| 19 | 19 | * |
| 20 | 20 | * @param array $parameters |
| 21 | 21 | * |
| 22 | 22 | * @return UserModel |
| 23 | 23 | */ |
| 24 | - public function updateSession(array $parameters) |
|
| 25 | - { |
|
| 26 | - return $this->setSession($this->updateUser($this->getUser(), $parameters)); |
|
| 27 | - } |
|
| 24 | + public function updateSession(array $parameters) |
|
| 25 | + { |
|
| 26 | + return $this->setSession($this->updateUser($this->getUser(), $parameters)); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 29 | + /** |
|
| 30 | 30 | * Set User Data on Session. |
| 31 | 31 | * |
| 32 | 32 | * @param UserModel $user |
| 33 | 33 | * |
| 34 | 34 | * @return UserModel |
| 35 | 35 | */ |
| 36 | - public function setSession(UserModel $user) |
|
| 37 | - { |
|
| 38 | - return Session::set(Config::get('chocolatey.security.session'), $user); |
|
| 39 | - } |
|
| 36 | + public function setSession(UserModel $user) |
|
| 37 | + { |
|
| 38 | + return Session::set(Config::get('chocolatey.security.session'), $user); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 41 | + /** |
|
| 42 | 42 | * Update User Data by User Model. |
| 43 | 43 | * |
| 44 | 44 | * @param UserModel $user |
@@ -46,25 +46,25 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return UserModel |
| 48 | 48 | */ |
| 49 | - public function updateUser($user, array $parameters) |
|
| 50 | - { |
|
| 51 | - $user->update($parameters); |
|
| 49 | + public function updateUser($user, array $parameters) |
|
| 50 | + { |
|
| 51 | + $user->update($parameters); |
|
| 52 | 52 | |
| 53 | - return $user; |
|
| 54 | - } |
|
| 53 | + return $user; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - /** |
|
| 56 | + /** |
|
| 57 | 57 | * Get User Data from Session |
| 58 | 58 | * If User Session doesn't exists, return null. |
| 59 | 59 | * |
| 60 | 60 | * @return UserModel|null |
| 61 | 61 | */ |
| 62 | - public function getUser() |
|
| 63 | - { |
|
| 64 | - return Session::get(Config::get('chocolatey.security.session')) ?? null; |
|
| 65 | - } |
|
| 62 | + public function getUser() |
|
| 63 | + { |
|
| 64 | + return Session::get(Config::get('chocolatey.security.session')) ?? null; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 67 | + /** |
|
| 68 | 68 | * Retrieve Non Banned Users (If all Users are Banned, return the Banned user Also). |
| 69 | 69 | * |
| 70 | 70 | * @param Request $request |
@@ -72,20 +72,20 @@ discard block |
||
| 72 | 72 | * |
| 73 | 73 | * @return UserModel |
| 74 | 74 | */ |
| 75 | - private function checkForBanAlternative(Request $request, ChocolateyId $chocolateyId) |
|
| 76 | - { |
|
| 77 | - $temporaryUsers = UserModel::where('mail', $request->json()->get('email'))->get(); |
|
| 75 | + private function checkForBanAlternative(Request $request, ChocolateyId $chocolateyId) |
|
| 76 | + { |
|
| 77 | + $temporaryUsers = UserModel::where('mail', $request->json()->get('email'))->get(); |
|
| 78 | 78 | |
| 79 | - foreach ($temporaryUsers as $forUser) { |
|
| 80 | - if (!$forUser->isBanned) { |
|
| 81 | - return $forUser; |
|
| 82 | - } |
|
| 83 | - } |
|
| 79 | + foreach ($temporaryUsers as $forUser) { |
|
| 80 | + if (!$forUser->isBanned) { |
|
| 81 | + return $forUser; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - return $temporaryUsers->get(0); |
|
| 86 | - } |
|
| 85 | + return $temporaryUsers->get(0); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 88 | + /** |
|
| 89 | 89 | * Get Users. |
| 90 | 90 | * |
| 91 | 91 | * @param Request $request |
@@ -93,65 +93,65 @@ discard block |
||
| 93 | 93 | * |
| 94 | 94 | * @return UserModel |
| 95 | 95 | */ |
| 96 | - private function retrieveUser(Request $request, ChocolateyId $chocolateyId) |
|
| 97 | - { |
|
| 98 | - if ($chocolateyId->last_logged_id != 0) { |
|
| 99 | - $temporaryUser = UserModel::find($chocolateyId->last_logged_id); |
|
| 96 | + private function retrieveUser(Request $request, ChocolateyId $chocolateyId) |
|
| 97 | + { |
|
| 98 | + if ($chocolateyId->last_logged_id != 0) { |
|
| 99 | + $temporaryUser = UserModel::find($chocolateyId->last_logged_id); |
|
| 100 | 100 | |
| 101 | - if ($temporaryUser->isBanned) { |
|
| 102 | - return $this->checkForBanAlternative($request, $chocolateyId); |
|
| 103 | - } |
|
| 101 | + if ($temporaryUser->isBanned) { |
|
| 102 | + return $this->checkForBanAlternative($request, $chocolateyId); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - return $temporaryUser; |
|
| 106 | - } |
|
| 105 | + return $temporaryUser; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - $temporaryUser = UserModel::where('mail', $request->json()->get('email'))->first(); |
|
| 108 | + $temporaryUser = UserModel::where('mail', $request->json()->get('email'))->first(); |
|
| 109 | 109 | |
| 110 | - if ($temporaryUser->isBanned) { |
|
| 111 | - return $this->checkForBanAlternative($request, $chocolateyId); |
|
| 112 | - } |
|
| 110 | + if ($temporaryUser->isBanned) { |
|
| 111 | + return $this->checkForBanAlternative($request, $chocolateyId); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - return $temporaryUser; |
|
| 115 | - } |
|
| 114 | + return $temporaryUser; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 117 | + /** |
|
| 118 | 118 | * Set Session From Login Credentials. |
| 119 | 119 | * |
| 120 | 120 | * @param Request $request |
| 121 | 121 | * |
| 122 | 122 | * @return UserModel |
| 123 | 123 | */ |
| 124 | - public function loginUser(Request $request) |
|
| 125 | - { |
|
| 126 | - $chocolateyId = ChocolateyId::find($request->json()->get('email')); |
|
| 124 | + public function loginUser(Request $request) |
|
| 125 | + { |
|
| 126 | + $chocolateyId = ChocolateyId::find($request->json()->get('email')); |
|
| 127 | 127 | |
| 128 | - if ($chocolateyId == null) { |
|
| 129 | - return; |
|
| 130 | - } |
|
| 128 | + if ($chocolateyId == null) { |
|
| 129 | + return; |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - $user = $this->retrieveUser($request, $chocolateyId); |
|
| 132 | + $user = $this->retrieveUser($request, $chocolateyId); |
|
| 133 | 133 | |
| 134 | - $chocolateyId->last_logged_id = $user->uniqueId; |
|
| 134 | + $chocolateyId->last_logged_id = $user->uniqueId; |
|
| 135 | 135 | |
| 136 | - return $chocolateyId->password == hash(Config::get('chocolatey.security.hash'), $request->json()->get('password')) |
|
| 137 | - ? $this->setSession($user) : null; |
|
| 138 | - } |
|
| 136 | + return $chocolateyId->password == hash(Config::get('chocolatey.security.hash'), $request->json()->get('password')) |
|
| 137 | + ? $this->setSession($user) : null; |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 140 | + /** |
|
| 141 | 141 | * Return if USer Session Exists. |
| 142 | 142 | * |
| 143 | 143 | * @return bool |
| 144 | 144 | */ |
| 145 | - public function hasSession() |
|
| 146 | - { |
|
| 147 | - return (bool) Session::get(Config::get('chocolatey.security.session')); |
|
| 148 | - } |
|
| 145 | + public function hasSession() |
|
| 146 | + { |
|
| 147 | + return (bool) Session::get(Config::get('chocolatey.security.session')); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /** |
|
| 150 | + /** |
|
| 151 | 151 | * Erase User Session. |
| 152 | 152 | */ |
| 153 | - public function eraseSession() |
|
| 154 | - { |
|
| 155 | - Session::erase(Config::get('chocolatey.security.session')); |
|
| 156 | - } |
|
| 153 | + public function eraseSession() |
|
| 154 | + { |
|
| 155 | + Session::erase(Config::get('chocolatey.security.session')); |
|
| 156 | + } |
|
| 157 | 157 | } |