@@ -1,53 +1,53 @@ |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | |
| 3 | -namespace App\Http\Controllers; |
|
| 3 | + namespace App\Http\Controllers; |
|
| 4 | 4 | |
| 5 | -use App\Facades\User; |
|
| 6 | -use Illuminate\Http\Request; |
|
| 7 | -use Illuminate\Http\Response; |
|
| 8 | -use Illuminate\Support\Facades\Config; |
|
| 9 | -use Laravel\Lumen\Routing\Controller as BaseController; |
|
| 5 | + use App\Facades\User; |
|
| 6 | + use Illuminate\Http\Request; |
|
| 7 | + use Illuminate\Http\Response; |
|
| 8 | + use Illuminate\Support\Facades\Config; |
|
| 9 | + use Laravel\Lumen\Routing\Controller as BaseController; |
|
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * Class ClientController. |
| 13 | 13 | */ |
| 14 | -class ClientController extends BaseController |
|
| 15 | -{ |
|
| 16 | - /** |
|
| 14 | + class ClientController extends BaseController |
|
| 15 | + { |
|
| 16 | + /** |
|
| 17 | 17 | * Returns the Client URL. |
| 18 | 18 | * |
| 19 | 19 | * @param Request $request |
| 20 | 20 | * |
| 21 | 21 | * @return Response |
| 22 | 22 | */ |
| 23 | - public function getUrl(Request $request) |
|
| 24 | - { |
|
| 25 | - $hotelUrl = Config::get('chocolatey.hotelUrl'); |
|
| 23 | + public function getUrl(Request $request) |
|
| 24 | + { |
|
| 25 | + $hotelUrl = Config::get('chocolatey.hotelUrl'); |
|
| 26 | 26 | |
| 27 | - return response()->json(['clienturl' => "{$hotelUrl}/client/habbo-client"], 200, [], JSON_UNESCAPED_SLASHES); |
|
| 28 | - } |
|
| 27 | + return response()->json(['clienturl' => "{$hotelUrl}/client/habbo-client"], 200, [], JSON_UNESCAPED_SLASHES); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 30 | + /** |
|
| 31 | 31 | * Get Client View. |
| 32 | 32 | * |
| 33 | 33 | * @return Response |
| 34 | 34 | */ |
| 35 | - public function showClient(): Response |
|
| 36 | - { |
|
| 37 | - User::updateSession(['auth_ticket' => ($userToken = uniqid('HabboWEB', true))]); |
|
| 35 | + public function showClient(): Response |
|
| 36 | + { |
|
| 37 | + User::updateSession(['auth_ticket' => ($userToken = uniqid('HabboWEB', true))]); |
|
| 38 | 38 | |
| 39 | - return response(view('habbo-web-pages.habbo-client', ['token' => $userToken, 'newUser' => in_array('NEW_USER', User::getUser()->traits)])); |
|
| 40 | - } |
|
| 39 | + return response(view('habbo-web-pages.habbo-client', ['token' => $userToken, 'newUser' => in_array('NEW_USER', User::getUser()->traits)])); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - /** |
|
| 42 | + /** |
|
| 43 | 43 | * Get HabboWEB Ads Interstitial. |
| 44 | 44 | * |
| 45 | 45 | * @param string $interstitialType |
| 46 | 46 | * |
| 47 | 47 | * @return Response |
| 48 | 48 | */ |
| 49 | - public function getInterstitial(string $interstitialType): Response |
|
| 50 | - { |
|
| 51 | - return response(view('habbo-web-ads.interstitial')); |
|
| 52 | - } |
|
| 49 | + public function getInterstitial(string $interstitialType): Response |
|
| 50 | + { |
|
| 51 | + return response(view('habbo-web-ads.interstitial')); |
|
| 52 | + } |
|
| 53 | 53 | } |
@@ -1,18 +1,18 @@ discard block |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | |
| 3 | -namespace App\Http\Controllers; |
|
| 3 | + namespace App\Http\Controllers; |
|
| 4 | 4 | |
| 5 | -use App\Models\Article; |
|
| 6 | -use App\Models\ArticleCategory; |
|
| 7 | -use Illuminate\Http\Response; |
|
| 8 | -use Laravel\Lumen\Routing\Controller as BaseController; |
|
| 5 | + use App\Models\Article; |
|
| 6 | + use App\Models\ArticleCategory; |
|
| 7 | + use Illuminate\Http\Response; |
|
| 8 | + use Laravel\Lumen\Routing\Controller as BaseController; |
|
| 9 | 9 | |
| 10 | 10 | /** |
| 11 | 11 | * Class ArticleController. |
| 12 | 12 | */ |
| 13 | -class ArticleController extends BaseController |
|
| 14 | -{ |
|
| 15 | - /** |
|
| 13 | + class ArticleController extends BaseController |
|
| 14 | + { |
|
| 15 | + /** |
|
| 16 | 16 | * Render a specific view of Article set. |
| 17 | 17 | * |
| 18 | 18 | * @param string $countryId |
@@ -20,28 +20,28 @@ discard block |
||
| 20 | 20 | * |
| 21 | 21 | * @return Response |
| 22 | 22 | */ |
| 23 | - public function many(string $countryId, string $articleCategory): Response |
|
| 24 | - { |
|
| 25 | - $category = ArticleCategory::find(strstr(($articleCategory = |
|
| 26 | - str_replace('.html', '', $articleCategory)), '_', true)); |
|
| 23 | + public function many(string $countryId, string $articleCategory): Response |
|
| 24 | + { |
|
| 25 | + $category = ArticleCategory::find(strstr(($articleCategory = |
|
| 26 | + str_replace('.html', '', $articleCategory)), '_', true)); |
|
| 27 | 27 | |
| 28 | - $categoryPage = strstr(strrev($articleCategory), '_', true); |
|
| 28 | + $categoryPage = strstr(strrev($articleCategory), '_', true); |
|
| 29 | 29 | |
| 30 | - return $articleCategory == 'front' ? $this->front() : $this->category($countryId, $category, $categoryPage, |
|
| 31 | - $categoryPage == 1 ? 0 : (10 * ($categoryPage - 1))); |
|
| 32 | - } |
|
| 30 | + return $articleCategory == 'front' ? $this->front() : $this->category($countryId, $category, $categoryPage, |
|
| 31 | + $categoryPage == 1 ? 0 : (10 * ($categoryPage - 1))); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - /** |
|
| 34 | + /** |
|
| 35 | 35 | * Render the Front Page of the Articles Page. |
| 36 | 36 | * |
| 37 | 37 | * @return Response |
| 38 | 38 | */ |
| 39 | - protected function front(): Response |
|
| 40 | - { |
|
| 41 | - return response(view('habbo-web-news.articles-front', ['set' => Article::orderBy('id', 'DESC')->limit(10)->get()])); |
|
| 42 | - } |
|
| 39 | + protected function front(): Response |
|
| 40 | + { |
|
| 41 | + return response(view('habbo-web-news.articles-front', ['set' => Article::orderBy('id', 'DESC')->limit(10)->get()])); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | + /** |
|
| 45 | 45 | * Render a specific Category Articles Page. |
| 46 | 46 | * |
| 47 | 47 | * @TODO: Proper Way to use Country ID |
@@ -53,18 +53,18 @@ discard block |
||
| 53 | 53 | * |
| 54 | 54 | * @return Response |
| 55 | 55 | */ |
| 56 | - protected function category(string $countryId, ArticleCategory $category, int $categoryPage, int $start): Response |
|
| 57 | - { |
|
| 58 | - $articles = Article::where('id', '>=', $start)->limit(10)->orderBy('id', 'DESC')->get()->filter(function ($item) use ($category) { |
|
| 59 | - return $category->name == 'all' || in_array($category, $item->categories); |
|
| 60 | - }); |
|
| 56 | + protected function category(string $countryId, ArticleCategory $category, int $categoryPage, int $start): Response |
|
| 57 | + { |
|
| 58 | + $articles = Article::where('id', '>=', $start)->limit(10)->orderBy('id', 'DESC')->get()->filter(function ($item) use ($category) { |
|
| 59 | + return $category->name == 'all' || in_array($category, $item->categories); |
|
| 60 | + }); |
|
| 61 | 61 | |
| 62 | - return response(view('habbo-web-news.articles-category', [ |
|
| 63 | - 'category' => $category, 'page' => $categoryPage, 'categories' => ArticleCategory::all(), 'articles' => $articles, |
|
| 64 | - ])); |
|
| 65 | - } |
|
| 62 | + return response(view('habbo-web-news.articles-category', [ |
|
| 63 | + 'category' => $category, 'page' => $categoryPage, 'categories' => ArticleCategory::all(), 'articles' => $articles, |
|
| 64 | + ])); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 67 | + /** |
|
| 68 | 68 | * Render a specific view of a specific Article. |
| 69 | 69 | * |
| 70 | 70 | * @TODO: Proper Way to use Country ID |
@@ -74,28 +74,28 @@ discard block |
||
| 74 | 74 | * |
| 75 | 75 | * @return Response |
| 76 | 76 | */ |
| 77 | - public function one(string $countryId, string $articleName): Response |
|
| 78 | - { |
|
| 79 | - if (($article = Article::find(strstr($articleName, '_', true))) == null) { |
|
| 80 | - return response()->json(null, 404); |
|
| 81 | - } |
|
| 77 | + public function one(string $countryId, string $articleName): Response |
|
| 78 | + { |
|
| 79 | + if (($article = Article::find(strstr($articleName, '_', true))) == null) { |
|
| 80 | + return response()->json(null, 404); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - $related = ($latest = Article::all())->filter(function ($item) use ($article) { |
|
| 84 | - return in_array($article->categories[0], $item->categories); |
|
| 85 | - }); |
|
| 83 | + $related = ($latest = Article::all())->filter(function ($item) use ($article) { |
|
| 84 | + return in_array($article->categories[0], $item->categories); |
|
| 85 | + }); |
|
| 86 | 86 | |
| 87 | - return response(view('habbo-web-news.articles-view', |
|
| 88 | - ['article' => $article, 'latest' => $latest->slice(0, 5), 'related' => $related->slice(0, 5)] |
|
| 89 | - )); |
|
| 90 | - } |
|
| 87 | + return response(view('habbo-web-news.articles-view', |
|
| 88 | + ['article' => $article, 'latest' => $latest->slice(0, 5), 'related' => $related->slice(0, 5)] |
|
| 89 | + )); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 92 | + /** |
|
| 93 | 93 | * Get All Habbo Articles as XML/RSS. |
| 94 | 94 | * |
| 95 | 95 | * @return Response |
| 96 | 96 | */ |
| 97 | - public function getRss() |
|
| 98 | - { |
|
| 99 | - return response(view('habbo-web-pages.habbo-rss', ['articles' => Article::limit(20)->get()]))->header('Content-Type', 'text/xml'); |
|
| 100 | - } |
|
| 97 | + public function getRss() |
|
| 98 | + { |
|
| 99 | + return response(view('habbo-web-pages.habbo-rss', ['articles' => Article::limit(20)->get()]))->header('Content-Type', 'text/xml'); |
|
| 100 | + } |
|
| 101 | 101 | } |
@@ -1,33 +1,33 @@ discard block |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | |
| 3 | -namespace App\Exceptions; |
|
| 3 | + namespace App\Exceptions; |
|
| 4 | 4 | |
| 5 | -use Exception; |
|
| 6 | -use Illuminate\Auth\Access\AuthorizationException; |
|
| 7 | -use Illuminate\Database\Eloquent\ModelNotFoundException; |
|
| 8 | -use Illuminate\Validation\ValidationException; |
|
| 9 | -use Laravel\Lumen\Exceptions\Handler as ExceptionHandler; |
|
| 10 | -use Symfony\Component\HttpKernel\Exception\HttpException; |
|
| 11 | -use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
| 5 | + use Exception; |
|
| 6 | + use Illuminate\Auth\Access\AuthorizationException; |
|
| 7 | + use Illuminate\Database\Eloquent\ModelNotFoundException; |
|
| 8 | + use Illuminate\Validation\ValidationException; |
|
| 9 | + use Laravel\Lumen\Exceptions\Handler as ExceptionHandler; |
|
| 10 | + use Symfony\Component\HttpKernel\Exception\HttpException; |
|
| 11 | + use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
|
| 12 | 12 | |
| 13 | 13 | /** |
| 14 | 14 | * Class Handler. |
| 15 | 15 | */ |
| 16 | -class Handler extends ExceptionHandler |
|
| 17 | -{ |
|
| 18 | - /** |
|
| 16 | + class Handler extends ExceptionHandler |
|
| 17 | + { |
|
| 18 | + /** |
|
| 19 | 19 | * A list of the exception types that should not be reported. |
| 20 | 20 | * |
| 21 | 21 | * @var array |
| 22 | 22 | */ |
| 23 | - protected $dontReport = [ |
|
| 24 | - AuthorizationException::class, |
|
| 25 | - HttpException::class, |
|
| 26 | - ModelNotFoundException::class, |
|
| 27 | - ValidationException::class, |
|
| 28 | - ]; |
|
| 23 | + protected $dontReport = [ |
|
| 24 | + AuthorizationException::class, |
|
| 25 | + HttpException::class, |
|
| 26 | + ModelNotFoundException::class, |
|
| 27 | + ValidationException::class, |
|
| 28 | + ]; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 30 | + /** |
|
| 31 | 31 | * Report or log an exception. |
| 32 | 32 | * |
| 33 | 33 | * This is a great spot to send exceptions to Sentry, Bugsnag, etc. |
@@ -36,12 +36,12 @@ discard block |
||
| 36 | 36 | * |
| 37 | 37 | * @return void |
| 38 | 38 | */ |
| 39 | - public function report(Exception $e) |
|
| 40 | - { |
|
| 41 | - parent::report($e); |
|
| 42 | - } |
|
| 39 | + public function report(Exception $e) |
|
| 40 | + { |
|
| 41 | + parent::report($e); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 44 | + /** |
|
| 45 | 45 | * Render an exception into an HTTP response. |
| 46 | 46 | * |
| 47 | 47 | * @param \Illuminate\Http\Request $request |
@@ -49,12 +49,12 @@ discard block |
||
| 49 | 49 | * |
| 50 | 50 | * @return \Illuminate\Http\Response |
| 51 | 51 | */ |
| 52 | - public function render($request, Exception $e) |
|
| 53 | - { |
|
| 54 | - if ($e instanceof NotFoundHttpException) { |
|
| 55 | - return response(view('habbo-web-pages.habbo-web')); |
|
| 56 | - } |
|
| 52 | + public function render($request, Exception $e) |
|
| 53 | + { |
|
| 54 | + if ($e instanceof NotFoundHttpException) { |
|
| 55 | + return response(view('habbo-web-pages.habbo-web')); |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - return parent::render($request, $e); |
|
| 59 | - } |
|
| 58 | + return parent::render($request, $e); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -1,17 +1,17 @@ discard block |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | |
| 3 | -namespace App\Http\Controllers; |
|
| 3 | + namespace App\Http\Controllers; |
|
| 4 | 4 | |
| 5 | -use App\Models\Room; |
|
| 6 | -use Illuminate\Http\JsonResponse; |
|
| 7 | -use Laravel\Lumen\Routing\Controller as BaseController; |
|
| 5 | + use App\Models\Room; |
|
| 6 | + use Illuminate\Http\JsonResponse; |
|
| 7 | + use Laravel\Lumen\Routing\Controller as BaseController; |
|
| 8 | 8 | |
| 9 | 9 | /** |
| 10 | 10 | * Class RoomsController. |
| 11 | 11 | */ |
| 12 | -class RoomsController extends BaseController |
|
| 13 | -{ |
|
| 14 | - /** |
|
| 12 | + class RoomsController extends BaseController |
|
| 13 | + { |
|
| 14 | + /** |
|
| 15 | 15 | * Get LeaderBoard Data. |
| 16 | 16 | * |
| 17 | 17 | * @TODO: Make Possible Filter with all the Possible Criteria |
@@ -22,26 +22,26 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @return JsonResponse |
| 24 | 24 | */ |
| 25 | - public function getLeader($countryId, $roomRange, $roomInterval): JsonResponse |
|
| 26 | - { |
|
| 27 | - $leaderRank = 1; |
|
| 25 | + public function getLeader($countryId, $roomRange, $roomInterval): JsonResponse |
|
| 26 | + { |
|
| 27 | + $leaderRank = 1; |
|
| 28 | 28 | |
| 29 | - foreach (($leaderBoard = Room::where('state', '!=', 'invisible')->orderBy('score', 'DESC')->orderBy('users', 'DESC')->limit(50)->get()) as $room) { |
|
| 30 | - $room->leaderboardRank = $leaderRank++; |
|
| 31 | - } |
|
| 29 | + foreach (($leaderBoard = Room::where('state', '!=', 'invisible')->orderBy('score', 'DESC')->orderBy('users', 'DESC')->limit(50)->get()) as $room) { |
|
| 30 | + $room->leaderboardRank = $leaderRank++; |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - return response()->json($leaderBoard, 200, [], JSON_UNESCAPED_SLASHES); |
|
| 34 | - } |
|
| 33 | + return response()->json($leaderBoard, 200, [], JSON_UNESCAPED_SLASHES); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 36 | + /** |
|
| 37 | 37 | * Get a specific Room Data. |
| 38 | 38 | * |
| 39 | 39 | * @param int $roomId |
| 40 | 40 | * |
| 41 | 41 | * @return JsonResponse |
| 42 | 42 | */ |
| 43 | - public function getRoom($roomId): JsonResponse |
|
| 44 | - { |
|
| 45 | - return response()->json(Room::find($roomId) ?? ['error' => 'not-found'], 200, [], JSON_UNESCAPED_SLASHES); |
|
| 46 | - } |
|
| 43 | + public function getRoom($roomId): JsonResponse |
|
| 44 | + { |
|
| 45 | + return response()->json(Room::find($roomId) ?? ['error' => 'not-found'], 200, [], JSON_UNESCAPED_SLASHES); |
|
| 46 | + } |
|
| 47 | 47 | } |
@@ -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,68 +1,68 @@ discard block |
||
| 1 | -<?php |
|
| 1 | + <?php |
|
| 2 | 2 | |
| 3 | -namespace App\Http\Controllers; |
|
| 3 | + namespace App\Http\Controllers; |
|
| 4 | 4 | |
| 5 | -use App\Facades\User as UserFacade; |
|
| 6 | -use App\Models\ChocolateyId; |
|
| 7 | -use App\Models\User; |
|
| 8 | -use Facebook\Facebook; |
|
| 9 | -use Facebook\GraphNodes\GraphUser; |
|
| 10 | -use Illuminate\Http\JsonResponse; |
|
| 11 | -use Illuminate\Http\Request; |
|
| 12 | -use Illuminate\Support\Facades\Config; |
|
| 13 | -use Laravel\Lumen\Routing\Controller as BaseController; |
|
| 5 | + use App\Facades\User as UserFacade; |
|
| 6 | + use App\Models\ChocolateyId; |
|
| 7 | + use App\Models\User; |
|
| 8 | + use Facebook\Facebook; |
|
| 9 | + use Facebook\GraphNodes\GraphUser; |
|
| 10 | + use Illuminate\Http\JsonResponse; |
|
| 11 | + use Illuminate\Http\Request; |
|
| 12 | + use Illuminate\Support\Facades\Config; |
|
| 13 | + use Laravel\Lumen\Routing\Controller as BaseController; |
|
| 14 | 14 | |
| 15 | 15 | /** |
| 16 | 16 | * Class LoginController. |
| 17 | 17 | */ |
| 18 | -class LoginController extends BaseController |
|
| 19 | -{ |
|
| 20 | - /** |
|
| 18 | + class LoginController extends BaseController |
|
| 19 | + { |
|
| 20 | + /** |
|
| 21 | 21 | * Handles the Response of the Login Attempt. |
| 22 | 22 | * |
| 23 | 23 | * @param Request $request |
| 24 | 24 | * |
| 25 | 25 | * @return JsonResponse |
| 26 | 26 | */ |
| 27 | - public function login(Request $request): JsonResponse |
|
| 28 | - { |
|
| 29 | - if (UserFacade::loginUser($request) !== null) { |
|
| 30 | - if (UserFacade::getUser()->isBanned) { |
|
| 31 | - return $this->sendBanMessage($request); |
|
| 32 | - } |
|
| 27 | + public function login(Request $request): JsonResponse |
|
| 28 | + { |
|
| 29 | + if (UserFacade::loginUser($request) !== null) { |
|
| 30 | + if (UserFacade::getUser()->isBanned) { |
|
| 31 | + return $this->sendBanMessage($request); |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - return response()->json(UserFacade::updateSession(['last_login' => time(), 'ip_current' => $request->ip()])); |
|
| 35 | - } |
|
| 34 | + return response()->json(UserFacade::updateSession(['last_login' => time(), 'ip_current' => $request->ip()])); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - //return response()->json(['message' => 'login.staff_login_not_allowed', 'captcha' => false], 401); // Example for Non Allowance of Staffs |
|
| 38 | - return response()->json(['message' => 'login.invalid_password', 'captcha' => false], 401); |
|
| 39 | - } |
|
| 37 | + //return response()->json(['message' => 'login.staff_login_not_allowed', 'captcha' => false], 401); // Example for Non Allowance of Staffs |
|
| 38 | + return response()->json(['message' => 'login.invalid_password', 'captcha' => false], 401); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 41 | + /** |
|
| 42 | 42 | * Return the Ban Message. |
| 43 | 43 | * |
| 44 | 44 | * @return JsonResponse |
| 45 | 45 | */ |
| 46 | - protected function sendBanMessage(): JsonResponse |
|
| 47 | - { |
|
| 48 | - return response()->json(['message' => 'login.user_banned', |
|
| 49 | - 'expiryTime' => UserFacade::getUser()->banDetails->ban_expire, |
|
| 50 | - 'reason' => UserFacade::getUser()->banDetails->ban_reason, ], 401); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 46 | + protected function sendBanMessage(): JsonResponse |
|
| 47 | + { |
|
| 48 | + return response()->json(['message' => 'login.user_banned', |
|
| 49 | + 'expiryTime' => UserFacade::getUser()->banDetails->ban_expire, |
|
| 50 | + 'reason' => UserFacade::getUser()->banDetails->ban_reason, ], 401); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | 54 | * Destroys the User Session. |
| 55 | 55 | * |
| 56 | 56 | * @return JsonResponse |
| 57 | 57 | */ |
| 58 | - public function logout(): JsonResponse |
|
| 59 | - { |
|
| 60 | - UserFacade::eraseSession(); |
|
| 58 | + public function logout(): JsonResponse |
|
| 59 | + { |
|
| 60 | + UserFacade::eraseSession(); |
|
| 61 | 61 | |
| 62 | - return response()->json(null); |
|
| 63 | - } |
|
| 62 | + return response()->json(null); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 65 | + /** |
|
| 66 | 66 | * Register an User on the Database |
| 67 | 67 | * and do the Login of the User. |
| 68 | 68 | * |
@@ -70,58 +70,58 @@ discard block |
||
| 70 | 70 | * |
| 71 | 71 | * @return JsonResponse |
| 72 | 72 | */ |
| 73 | - public function register(Request $request): JsonResponse |
|
| 74 | - { |
|
| 75 | - if (ChocolateyId::where('mail', $request->json()->get('email'))->count() > 0) { |
|
| 76 | - return response()->json(['error' => 'registration_email_in_use'], 409); |
|
| 77 | - } |
|
| 73 | + public function register(Request $request): JsonResponse |
|
| 74 | + { |
|
| 75 | + if (ChocolateyId::where('mail', $request->json()->get('email'))->count() > 0) { |
|
| 76 | + return response()->json(['error' => 'registration_email_in_use'], 409); |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - $dateOfBirth = strtotime("{$request->json()->get('birthdate')['day']}/{$request->json()->get('birthdate')['month']}/{$request->json()->get('birthdate')['year']}"); |
|
| 79 | + $dateOfBirth = strtotime("{$request->json()->get('birthdate')['day']}/{$request->json()->get('birthdate')['month']}/{$request->json()->get('birthdate')['year']}"); |
|
| 80 | 80 | |
| 81 | - (new AccountController())->createUser($request, $request->json()->all(), true); |
|
| 81 | + (new AccountController())->createUser($request, $request->json()->all(), true); |
|
| 82 | 82 | |
| 83 | - (new ChocolateyId())->store($request->json()->get('email'), $request->json()->get('password')); |
|
| 83 | + (new ChocolateyId())->store($request->json()->get('email'), $request->json()->get('password')); |
|
| 84 | 84 | |
| 85 | - UserFacade::updateSession(['last_login' => time(), 'ip_register' => $request->ip(), 'ip_current' => $request->ip(), 'account_day_of_birth' => $dateOfBirth]); |
|
| 85 | + UserFacade::updateSession(['last_login' => time(), 'ip_register' => $request->ip(), 'ip_current' => $request->ip(), 'account_day_of_birth' => $dateOfBirth]); |
|
| 86 | 86 | |
| 87 | - return response()->json(UserFacade::getUser()); |
|
| 88 | - } |
|
| 87 | + return response()->json(UserFacade::getUser()); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 90 | + /** |
|
| 91 | 91 | * Create or Login a Facebook User. |
| 92 | 92 | * |
| 93 | 93 | * @param Request $request |
| 94 | 94 | * |
| 95 | 95 | * @return JsonResponse |
| 96 | 96 | */ |
| 97 | - public function facebook(Request $request): JsonResponse |
|
| 98 | - { |
|
| 99 | - $fbUser = $this->fbAuth($request); |
|
| 97 | + public function facebook(Request $request): JsonResponse |
|
| 98 | + { |
|
| 99 | + $fbUser = $this->fbAuth($request); |
|
| 100 | 100 | |
| 101 | - if (User::query()->where('real_name', $fbUser->getId())->count() > 0) { |
|
| 102 | - return response()->json(UserFacade::setSession(User::where('real_name', $fbUser->getId())->first())); |
|
| 103 | - } |
|
| 101 | + if (User::query()->where('real_name', $fbUser->getId())->count() > 0) { |
|
| 102 | + return response()->json(UserFacade::setSession(User::where('real_name', $fbUser->getId())->first())); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - (new AccountController())->createUser($request, ['email' => $fbUser->getEmail()], true); |
|
| 105 | + (new AccountController())->createUser($request, ['email' => $fbUser->getEmail()], true); |
|
| 106 | 106 | |
| 107 | - UserFacade::updateSession(['last_login' => time(), 'ip_register' => $request->ip(), 'ip_current' => $request->ip(), 'real_name' => $fbUser->getId()]); |
|
| 107 | + UserFacade::updateSession(['last_login' => time(), 'ip_register' => $request->ip(), 'ip_current' => $request->ip(), 'real_name' => $fbUser->getId()]); |
|
| 108 | 108 | |
| 109 | - return response()->json(UserFacade::getUser()); |
|
| 110 | - } |
|
| 109 | + return response()->json(UserFacade::getUser()); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 112 | + /** |
|
| 113 | 113 | * Do Facebook Authentication. |
| 114 | 114 | * |
| 115 | 115 | * @param Request $request |
| 116 | 116 | * |
| 117 | 117 | * @return GraphUser |
| 118 | 118 | */ |
| 119 | - protected function fbAuth(Request $request): GraphUser |
|
| 120 | - { |
|
| 121 | - $facebook = new Facebook(['app_id' => Config::get('chocolatey.facebook.app.key'), 'app_secret' => Config::get('chocolatey.facebook.app.secret')]); |
|
| 119 | + protected function fbAuth(Request $request): GraphUser |
|
| 120 | + { |
|
| 121 | + $facebook = new Facebook(['app_id' => Config::get('chocolatey.facebook.app.key'), 'app_secret' => Config::get('chocolatey.facebook.app.secret')]); |
|
| 122 | 122 | |
| 123 | - $facebook->setDefaultAccessToken($request->json()->get('accessToken')); |
|
| 123 | + $facebook->setDefaultAccessToken($request->json()->get('accessToken')); |
|
| 124 | 124 | |
| 125 | - return $facebook->get('/me?fields=id,name,email')->getGraphUser(); |
|
| 126 | - } |
|
| 125 | + return $facebook->get('/me?fields=id,name,email')->getGraphUser(); |
|
| 126 | + } |
|
| 127 | 127 | } |
@@ -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 | } |
@@ -1,41 +1,41 @@ discard block |
||
| 1 | -<?php |
|
| 2 | - |
|
| 3 | -namespace App\Http\Controllers; |
|
| 4 | - |
|
| 5 | -use App\Facades\Mail; |
|
| 6 | -use App\Facades\User as UserFacade; |
|
| 7 | -use App\Facades\Validation; |
|
| 8 | -use App\Models\ChocolateyId; |
|
| 9 | -use App\Models\User; |
|
| 10 | -use App\Models\UserPreferences; |
|
| 11 | -use App\Models\UserSettings; |
|
| 12 | -use Illuminate\Http\JsonResponse; |
|
| 13 | -use Illuminate\Http\Request; |
|
| 14 | -use Illuminate\Http\Response; |
|
| 15 | -use Illuminate\Support\Facades\Config; |
|
| 16 | -use Laravel\Lumen\Routing\Controller as BaseController; |
|
| 17 | -use Nubs\RandomNameGenerator\Alliteration; |
|
| 1 | + <?php |
|
| 2 | + |
|
| 3 | + namespace App\Http\Controllers; |
|
| 4 | + |
|
| 5 | + use App\Facades\Mail; |
|
| 6 | + use App\Facades\User as UserFacade; |
|
| 7 | + use App\Facades\Validation; |
|
| 8 | + use App\Models\ChocolateyId; |
|
| 9 | + use App\Models\User; |
|
| 10 | + use App\Models\UserPreferences; |
|
| 11 | + use App\Models\UserSettings; |
|
| 12 | + use Illuminate\Http\JsonResponse; |
|
| 13 | + use Illuminate\Http\Request; |
|
| 14 | + use Illuminate\Http\Response; |
|
| 15 | + use Illuminate\Support\Facades\Config; |
|
| 16 | + use Laravel\Lumen\Routing\Controller as BaseController; |
|
| 17 | + use Nubs\RandomNameGenerator\Alliteration; |
|
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Class AccountController. |
| 21 | 21 | */ |
| 22 | -class AccountController extends BaseController |
|
| 23 | -{ |
|
| 24 | - /** |
|
| 22 | + class AccountController extends BaseController |
|
| 23 | + { |
|
| 24 | + /** |
|
| 25 | 25 | * Save User Look. |
| 26 | 26 | * |
| 27 | 27 | * @param Request $request |
| 28 | 28 | * |
| 29 | 29 | * @return JsonResponse |
| 30 | 30 | */ |
| 31 | - public function saveLook(Request $request): JsonResponse |
|
| 32 | - { |
|
| 33 | - UserFacade::updateSession(['look' => $request->json()->get('figure'), 'gender' => $request->json()->get('gender')]); |
|
| 31 | + public function saveLook(Request $request): JsonResponse |
|
| 32 | + { |
|
| 33 | + UserFacade::updateSession(['look' => $request->json()->get('figure'), 'gender' => $request->json()->get('gender')]); |
|
| 34 | 34 | |
| 35 | - return response()->json(UserFacade::getUser()); |
|
| 36 | - } |
|
| 35 | + return response()->json(UserFacade::getUser()); |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - /** |
|
| 38 | + /** |
|
| 39 | 39 | * Get User Non Read Messenger Discussions. |
| 40 | 40 | * |
| 41 | 41 | * @TODO: Code Integration with HabboMessenger |
@@ -43,59 +43,59 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return JsonResponse |
| 45 | 45 | */ |
| 46 | - public function getDiscussions(): JsonResponse |
|
| 47 | - { |
|
| 48 | - return response()->json([]); |
|
| 49 | - } |
|
| 46 | + public function getDiscussions(): JsonResponse |
|
| 47 | + { |
|
| 48 | + return response()->json([]); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - /** |
|
| 51 | + /** |
|
| 52 | 52 | * Get User Preferences. |
| 53 | 53 | * |
| 54 | 54 | * @return JsonResponse |
| 55 | 55 | */ |
| 56 | - public function getPreferences(): JsonResponse |
|
| 57 | - { |
|
| 58 | - $userPreferences = UserPreferences::firstOrCreate(['user_id' => UserFacade::getUser()->uniqueId]); |
|
| 56 | + public function getPreferences(): JsonResponse |
|
| 57 | + { |
|
| 58 | + $userPreferences = UserPreferences::firstOrCreate(['user_id' => UserFacade::getUser()->uniqueId]); |
|
| 59 | 59 | |
| 60 | - foreach ($userPreferences->getAttributes() as $attributeName => $attributeValue) { |
|
| 61 | - $userPreferences->{$attributeName} = $attributeValue == 1; |
|
| 62 | - } |
|
| 60 | + foreach ($userPreferences->getAttributes() as $attributeName => $attributeValue) { |
|
| 61 | + $userPreferences->{$attributeName} = $attributeValue == 1; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return response()->json($userPreferences); |
|
| 65 | - } |
|
| 64 | + return response()->json($userPreferences); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 67 | + /** |
|
| 68 | 68 | * Save New User Preferences. |
| 69 | 69 | * |
| 70 | 70 | * @param Request $request |
| 71 | 71 | * |
| 72 | 72 | * @return Response |
| 73 | 73 | */ |
| 74 | - public function savePreferences(Request $request): Response |
|
| 75 | - { |
|
| 76 | - UserSettings::updateOrCreate(['user_id' => UserFacade::getUser()->uniqueId], [ |
|
| 77 | - 'block_following' => $request->json()->get('friendCanFollow') == false ? '1' : '0', |
|
| 78 | - 'block_friendrequests' => $request->json()->get('friendRequestEnabled') == false ? '1' : '0', |
|
| 79 | - ]); |
|
| 74 | + public function savePreferences(Request $request): Response |
|
| 75 | + { |
|
| 76 | + UserSettings::updateOrCreate(['user_id' => UserFacade::getUser()->uniqueId], [ |
|
| 77 | + 'block_following' => $request->json()->get('friendCanFollow') == false ? '1' : '0', |
|
| 78 | + 'block_friendrequests' => $request->json()->get('friendRequestEnabled') == false ? '1' : '0', |
|
| 79 | + ]); |
|
| 80 | 80 | |
| 81 | - foreach ((array) $request->json()->all() as $setting => $value) { |
|
| 82 | - UserPreferences::find(UserFacade::getUser()->uniqueId)->update([$setting => $value == true ? '1' : '0']); |
|
| 83 | - } |
|
| 81 | + foreach ((array) $request->json()->all() as $setting => $value) { |
|
| 82 | + UserPreferences::find(UserFacade::getUser()->uniqueId)->update([$setting => $value == true ? '1' : '0']); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - return response(null); |
|
| 86 | - } |
|
| 85 | + return response(null); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 88 | + /** |
|
| 89 | 89 | * Get All E-Mail Accounts. |
| 90 | 90 | * |
| 91 | 91 | * @return JsonResponse |
| 92 | 92 | */ |
| 93 | - public function getAvatars(): JsonResponse |
|
| 94 | - { |
|
| 95 | - return response()->json(UserFacade::getUser()->getChocolateyId()->relatedAccounts); |
|
| 96 | - } |
|
| 93 | + public function getAvatars(): JsonResponse |
|
| 94 | + { |
|
| 95 | + return response()->json(UserFacade::getUser()->getChocolateyId()->relatedAccounts); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 98 | + /** |
|
| 99 | 99 | * Check if an Username is available |
| 100 | 100 | * for a new Avatar Account. |
| 101 | 101 | * |
@@ -103,33 +103,33 @@ discard block |
||
| 103 | 103 | * |
| 104 | 104 | * @return JsonResponse |
| 105 | 105 | */ |
| 106 | - public function checkName(Request $request): JsonResponse |
|
| 107 | - { |
|
| 108 | - return response()->json(['isAvailable' => (User::where('username', $request->input('name'))->count() == 0 |
|
| 109 | - && Validation::filterUserName($request->input('name')) && !UserFacade::getUser()->isStaff)]); |
|
| 110 | - } |
|
| 106 | + public function checkName(Request $request): JsonResponse |
|
| 107 | + { |
|
| 108 | + return response()->json(['isAvailable' => (User::where('username', $request->input('name'))->count() == 0 |
|
| 109 | + && Validation::filterUserName($request->input('name')) && !UserFacade::getUser()->isStaff)]); |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - /** |
|
| 112 | + /** |
|
| 113 | 113 | * Create a New User Avatar. |
| 114 | 114 | * |
| 115 | 115 | * @param Request $request |
| 116 | 116 | * |
| 117 | 117 | * @return JsonResponse |
| 118 | 118 | */ |
| 119 | - public function createAvatar(Request $request): JsonResponse |
|
| 120 | - { |
|
| 121 | - if (User::where('username', $request->json()->get('name'))->count() == 0 && Validation::filterUserName($request->json()->get('name'))) { |
|
| 122 | - $user = $this->createUser($request, ['username' => $request->json()->get('name'), 'email' => UserFacade::getUser()->email]); |
|
| 119 | + public function createAvatar(Request $request): JsonResponse |
|
| 120 | + { |
|
| 121 | + if (User::where('username', $request->json()->get('name'))->count() == 0 && Validation::filterUserName($request->json()->get('name'))) { |
|
| 122 | + $user = $this->createUser($request, ['username' => $request->json()->get('name'), 'email' => UserFacade::getUser()->email]); |
|
| 123 | 123 | |
| 124 | - ChocolateyId::find(UserFacade::getUser()->email)->update(['last_logged_id' => $user->uniqueId]); |
|
| 124 | + ChocolateyId::find(UserFacade::getUser()->email)->update(['last_logged_id' => $user->uniqueId]); |
|
| 125 | 125 | |
| 126 | - return response()->json(''); |
|
| 127 | - } |
|
| 126 | + return response()->json(''); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - return response()->json(''); |
|
| 130 | - } |
|
| 129 | + return response()->json(''); |
|
| 130 | + } |
|
| 131 | 131 | |
| 132 | - /** |
|
| 132 | + /** |
|
| 133 | 133 | * Create a New User. |
| 134 | 134 | * |
| 135 | 135 | * @param Request $request |
@@ -138,18 +138,18 @@ discard block |
||
| 138 | 138 | * |
| 139 | 139 | * @return User |
| 140 | 140 | */ |
| 141 | - public function createUser(Request $request, array $userInfo, bool $newUser = false): User |
|
| 142 | - { |
|
| 143 | - $userName = $newUser ? $this->uniqueName($userInfo['email']) : $userInfo['username']; |
|
| 141 | + public function createUser(Request $request, array $userInfo, bool $newUser = false): User |
|
| 142 | + { |
|
| 143 | + $userName = $newUser ? $this->uniqueName($userInfo['email']) : $userInfo['username']; |
|
| 144 | 144 | |
| 145 | - $token = Mail::store($userInfo['email'], 'public/registration/activate'); |
|
| 145 | + $token = Mail::store($userInfo['email'], 'public/registration/activate'); |
|
| 146 | 146 | |
| 147 | - Mail::send(['email' => $userInfo['email'], 'name' => $userName, 'url' => "/activate/{$token}", 'subject' => 'Welcome to '.Config::get('chocolatey.hotelName')]); |
|
| 147 | + Mail::send(['email' => $userInfo['email'], 'name' => $userName, 'url' => "/activate/{$token}", 'subject' => 'Welcome to '.Config::get('chocolatey.hotelName')]); |
|
| 148 | 148 | |
| 149 | - return UserFacade::setSession((new User())->store($userName, $userInfo['email'], $request->ip(), $newUser)); |
|
| 150 | - } |
|
| 149 | + return UserFacade::setSession((new User())->store($userName, $userInfo['email'], $request->ip(), $newUser)); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - /** |
|
| 152 | + /** |
|
| 153 | 153 | * Create Random Unique Username. |
| 154 | 154 | * |
| 155 | 155 | * @WARNING: Doesn't create Like Habbo Way |
@@ -158,62 +158,62 @@ discard block |
||
| 158 | 158 | * |
| 159 | 159 | * @return string |
| 160 | 160 | */ |
| 161 | - protected function uniqueName(string $userMail): string |
|
| 162 | - { |
|
| 163 | - $partialName = explode(' ', (new Alliteration())->getName()); |
|
| 161 | + protected function uniqueName(string $userMail): string |
|
| 162 | + { |
|
| 163 | + $partialName = explode(' ', (new Alliteration())->getName()); |
|
| 164 | 164 | |
| 165 | - return strtolower($partialName[0].strstr($userMail, '@', true).$partialName[1]); |
|
| 166 | - } |
|
| 165 | + return strtolower($partialName[0].strstr($userMail, '@', true).$partialName[1]); |
|
| 166 | + } |
|
| 167 | 167 | |
| 168 | - /** |
|
| 168 | + /** |
|
| 169 | 169 | * Change Logged In User. |
| 170 | 170 | * |
| 171 | 171 | * @param Request $request |
| 172 | 172 | */ |
| 173 | - public function selectAvatar(Request $request) |
|
| 174 | - { |
|
| 175 | - UserFacade::getUser()->getChocolateyId()->update(['last_logged_id' => $request->json()->get('uniqueId')]); |
|
| 173 | + public function selectAvatar(Request $request) |
|
| 174 | + { |
|
| 175 | + UserFacade::getUser()->getChocolateyId()->update(['last_logged_id' => $request->json()->get('uniqueId')]); |
|
| 176 | 176 | |
| 177 | - UserFacade::setSession(User::find($request->json()->get('uniqueId'))); |
|
| 178 | - } |
|
| 177 | + UserFacade::setSession(User::find($request->json()->get('uniqueId'))); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - /** |
|
| 180 | + /** |
|
| 181 | 181 | * Send User Forgot E-Mail. |
| 182 | 182 | * |
| 183 | 183 | * @param Request $request |
| 184 | 184 | * |
| 185 | 185 | * @return JsonResponse |
| 186 | 186 | */ |
| 187 | - public function forgotPassword(Request $request): JsonResponse |
|
| 188 | - { |
|
| 189 | - if (($user = User::where('mail', $request->json()->get('email'))->first()) == null) { |
|
| 190 | - return response()->json(['email' => $request->json()->get('email')]); |
|
| 191 | - } |
|
| 187 | + public function forgotPassword(Request $request): JsonResponse |
|
| 188 | + { |
|
| 189 | + if (($user = User::where('mail', $request->json()->get('email'))->first()) == null) { |
|
| 190 | + return response()->json(['email' => $request->json()->get('email')]); |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - $token = Mail::store($user->email, 'public/forgotPassword'); |
|
| 193 | + $token = Mail::store($user->email, 'public/forgotPassword'); |
|
| 194 | 194 | |
| 195 | - Mail::send(['name' => $user->name, 'email' => $user->email, 'subject' => 'Password reset confirmation', |
|
| 196 | - 'url' => "/reset-password/{$token}", |
|
| 197 | - ], 'habbo-web-mail.password-reset'); |
|
| 195 | + Mail::send(['name' => $user->name, 'email' => $user->email, 'subject' => 'Password reset confirmation', |
|
| 196 | + 'url' => "/reset-password/{$token}", |
|
| 197 | + ], 'habbo-web-mail.password-reset'); |
|
| 198 | 198 | |
| 199 | - return response()->json(['email' => $user->email]); |
|
| 200 | - } |
|
| 199 | + return response()->json(['email' => $user->email]); |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - /** |
|
| 202 | + /** |
|
| 203 | 203 | * Send an Account Confirmation E-Mail. |
| 204 | 204 | * |
| 205 | 205 | * @param Request $request |
| 206 | 206 | * |
| 207 | 207 | * @return Response |
| 208 | 208 | */ |
| 209 | - public function verifyAccount(Request $request): Response |
|
| 210 | - { |
|
| 211 | - $token = Mail::store(UserFacade::getUser()->email, 'public/registration/activate'); |
|
| 209 | + public function verifyAccount(Request $request): Response |
|
| 210 | + { |
|
| 211 | + $token = Mail::store(UserFacade::getUser()->email, 'public/registration/activate'); |
|
| 212 | 212 | |
| 213 | - Mail::send(['name' => UserFacade::getUser()->name, 'email' => $request->user()->email, |
|
| 214 | - 'url' => "/activate/{$token}", 'subject' => 'Welcome to '.Config::get('chocolatey.hotelName'), |
|
| 215 | - ]); |
|
| 213 | + Mail::send(['name' => UserFacade::getUser()->name, 'email' => $request->user()->email, |
|
| 214 | + 'url' => "/activate/{$token}", 'subject' => 'Welcome to '.Config::get('chocolatey.hotelName'), |
|
| 215 | + ]); |
|
| 216 | 216 | |
| 217 | - return response(null); |
|
| 218 | - } |
|
| 217 | + return response(null); |
|
| 218 | + } |
|
| 219 | 219 | } |
@@ -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); |
|
| 46 | + public function store(string $email, string $url): string |
|
| 47 | + { |
|
| 48 | + (new MailModel())->store($token = uniqid('HabboMail', true), $url, $email); |
|
| 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 | } |