This repository has been archived by the owner on Feb 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into #22-countries
# Conflicts: # database/seeders/DatabaseSeeder.php
- Loading branch information
Showing
40 changed files
with
986 additions
and
1,047 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,4 @@ QUEUE_CONNECTION=sync | |
SESSION_DRIVER=file | ||
SESSION_LIFETIME=120 | ||
|
||
TELESCOPE_ENABLED=false | ||
TELESCOPE_ENABLED=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brewmap\Eloquent; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
|
||
/** | ||
* @property string $userId | ||
* @property User $user | ||
* @property string $providerName | ||
* @property string $providerId | ||
* @property Carbon $createdAt | ||
* @property Carbon $updatedAt | ||
*/ | ||
class SocialProfile extends Model | ||
{ | ||
protected $primaryKey = "user_id"; | ||
|
||
public function user(): BelongsTo | ||
{ | ||
return $this->belongsTo(User::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brewmap\Exceptions; | ||
|
||
use Exception; | ||
use Illuminate\Http\Response; | ||
|
||
abstract class ApiException extends Exception | ||
{ | ||
protected $code = Response::HTTP_INTERNAL_SERVER_ERROR; | ||
} |
14 changes: 14 additions & 0 deletions
14
app/Exceptions/Auth/SocialProviderConfigurationException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brewmap\Exceptions\Auth; | ||
|
||
use Exception; | ||
use Illuminate\Http\Response; | ||
|
||
class SocialProviderConfigurationException extends Exception | ||
{ | ||
protected $message = "Attempted social service provider is not configured properly."; | ||
protected $code = Response::HTTP_NOT_IMPLEMENTED; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brewmap\Exceptions\Auth; | ||
|
||
use Brewmap\Exceptions\ApiException; | ||
use Illuminate\Http\Response; | ||
|
||
class UnauthorizedException extends ApiException | ||
{ | ||
protected $code = Response::HTTP_UNAUTHORIZED; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brewmap\Http\Controllers\API; | ||
|
||
use Brewmap\Exceptions\Auth\SocialProviderConfigurationException; | ||
use Brewmap\Exceptions\Auth\UnauthorizedException; | ||
use Brewmap\Http\Controllers\Controller; | ||
use Brewmap\Http\Requests\User\LoginUserRequest; | ||
use Brewmap\Http\Requests\User\RegisterUserRequest; | ||
use Brewmap\Services\AuthenticationService; | ||
use Illuminate\Http\JsonResponse; | ||
use Illuminate\Http\RedirectResponse; | ||
use Laravel\Socialite\Facades\Socialite; | ||
|
||
class AuthenticationController extends Controller | ||
{ | ||
/** | ||
* @throws UnauthorizedException | ||
*/ | ||
public function login(LoginUserRequest $request, AuthenticationService $authenticationService): JsonResponse | ||
{ | ||
$token = $authenticationService->login($request); | ||
return response()->json(["token" => $token]); | ||
} | ||
|
||
public function register(RegisterUserRequest $request, AuthenticationService $authenticationService): JsonResponse | ||
{ | ||
$authenticationService->register($request->validated()); | ||
return response()->json(["message" => __("auth.register_success")]); | ||
} | ||
|
||
public function redirectToFacebook(): RedirectResponse | ||
{ | ||
return Socialite::driver("facebook")->redirect(); | ||
} | ||
|
||
/** | ||
* @throws SocialProviderConfigurationException | ||
*/ | ||
public function handleFacebookCallback(AuthenticationService $authenticationService): JsonResponse | ||
{ | ||
$facebookUser = Socialite::driver("facebook")->user(); | ||
$token = $authenticationService->getTokenBySocialLogin($facebookUser, "facebook"); | ||
return response()->json(["token" => $token]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brewmap\Http\Requests; | ||
|
||
use Illuminate\Contracts\Validation\Validator; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Http\Exceptions\HttpResponseException; | ||
use Illuminate\Http\Response; | ||
|
||
abstract class BaseRequest extends FormRequest | ||
{ | ||
public function authorize(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @throws HttpResponseException | ||
*/ | ||
protected function failedValidation(Validator $validator): void | ||
{ | ||
throw new HttpResponseException(response()->json($validator->errors(), Response::HTTP_UNPROCESSABLE_ENTITY)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brewmap\Http\Requests; | ||
|
||
class BaseRules | ||
{ | ||
protected static array $rules; | ||
|
||
public static function rules(array $additionalRules = []): array | ||
{ | ||
return array_merge(static::$rules, $additionalRules); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brewmap\Http\Requests\User; | ||
|
||
use Brewmap\Http\Requests\BaseRequest; | ||
use Brewmap\Http\Requests\User\Rules\EmailRules; | ||
use Brewmap\Http\Requests\User\Rules\PasswordRules; | ||
|
||
class LoginUserRequest extends BaseRequest | ||
{ | ||
public function rules(): array | ||
{ | ||
return [ | ||
"email" => EmailRules::rules(), | ||
"password" => PasswordRules::rules(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brewmap\Http\Requests\User; | ||
|
||
use Brewmap\Http\Requests\BaseRequest; | ||
use Brewmap\Http\Requests\User\Rules\EmailRules; | ||
use Brewmap\Http\Requests\User\Rules\NameRules; | ||
use Brewmap\Http\Requests\User\Rules\PasswordRules; | ||
|
||
class RegisterUserRequest extends BaseRequest | ||
{ | ||
public function rules(): array | ||
{ | ||
return [ | ||
"email" => EmailRules::rules([ | ||
"unique:users", | ||
]), | ||
"password" => PasswordRules::rules([ | ||
"confirmed", | ||
]), | ||
"name" => NameRules::rules(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brewmap\Http\Requests\User\Rules; | ||
|
||
use Brewmap\Http\Requests\BaseRules; | ||
|
||
class EmailRules extends BaseRules | ||
{ | ||
protected static array $rules = [ | ||
"required", | ||
"email", | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brewmap\Http\Requests\User\Rules; | ||
|
||
use Brewmap\Http\Requests\BaseRules; | ||
|
||
class NameRules extends BaseRules | ||
{ | ||
protected static array $rules = [ | ||
"required", | ||
"min:4", | ||
"max:20", | ||
"alpha_dash", | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Brewmap\Http\Requests\User\Rules; | ||
|
||
use Brewmap\Http\Requests\BaseRules; | ||
|
||
class PasswordRules extends BaseRules | ||
{ | ||
protected static array $rules = [ | ||
"required", | ||
"string", | ||
"min:8", | ||
]; | ||
} |
Oops, something went wrong.