Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
"require": {
"php": "^7.4",
"ext-json": "*",
"doctrine/dbal": "^2.10",
"illuminate/support": "^6.0|^7.0",
"doctrine/dbal": "^2.10"
"laravel/ui": "^2.0"
},
"require-dev": {
"mockery/mockery": "^1.3",
Expand Down
18 changes: 16 additions & 2 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,24 @@
| this will be used for the verification of the authenticatable model and provide the
| authorizable functionality
|
| Supported: "passport", "airlock"
| Supported: "passport", "sanctum"
*/

'provider' => 'airlock',
'provider' => 'sanctum',

/*
|--------------------------------------------------------------------------
| Auth frontend app url
|--------------------------------------------------------------------------
|
|URL used for reset password URL generating.
|
|
*/

'frontend_app_url' => env('FRONTEND_APP_URL', env('APP_URL')),

'password_reset_url' => env('FRONTEND_APP_URL').'/password/reset?token={token}&email={email}',
],

/*
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/CheckPassport.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function hasPassportClient(): bool
} catch (\RuntimeException $e) {
$this->warn($e->getMessage());
$this->warn('Hint: php artisan passport:client --personal');
$this->warn('See: https://laravel.com/docs/6.x/passport#creating-a-personal-access-client');
$this->warn('See: https://laravel.com/docs/7.x/passport#creating-a-personal-access-client');

return false;
}
Expand Down
7 changes: 7 additions & 0 deletions src/Contracts/Sanctumable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php

namespace Binaryk\LaravelRestify\Contracts;

interface Sanctumable
{
}
41 changes: 41 additions & 0 deletions src/Controllers/AuthController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Binaryk\LaravelRestify\Controllers;

use Binaryk\LaravelRestify\Services\AuthService;
use Illuminate\Http\Request;

class AuthController extends RestController
{
private AuthService $authService;

public function __construct(AuthService $authService)
{
$this->authService = $authService;
}

public function login(Request $request)
{
return $this->authService->login($request);
}

public function register(Request $request)
{
return $this->authService->register($request);
}

public function verify(Request $request)
{
return $this->authService->verify($request);
}

public function forgotPassword(Request $request)
{
return $this->authService->forgotPassword($request);
}

public function resetPassword(Request $request)
{
return $this->authService->resetPassword($request);
}
}
12 changes: 0 additions & 12 deletions src/Exceptions/AirlockUserException.php

This file was deleted.

6 changes: 6 additions & 0 deletions src/Exceptions/AuthenticatableUserException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
*/
class AuthenticatableUserException extends Exception
{
public static function wrongInstance(): self
{
$message = __("Repository model should be an instance of \Illuminate\Contracts\Auth\Authenticatable");

return new static($message);
}
}
16 changes: 16 additions & 0 deletions src/Exceptions/SanctumUserException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Binaryk\LaravelRestify\Exceptions;

use Exception;

/**
* @author Eduard Lupacescu <eduard.lupacescu@binarcode.com>
*/
class SanctumUserException extends Exception
{
public static function wrongConfiguration()
{
return new static('Auth provider should be [sanctum] in the configuration [restify.auth.provider].');
}
}
58 changes: 58 additions & 0 deletions src/Notifications/VerifyEmail.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Binaryk\LaravelRestify\Notifications;

use Illuminate\Auth\Notifications\VerifyEmail as VerifyEmailLaravel;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Lang;
use Illuminate\Support\Facades\URL;

class VerifyEmail extends VerifyEmailLaravel
{
public function toMail($notifiable)
{
$verificationUrl = $this->verificationUrl($notifiable);

if (static::$toMailCallback) {
return call_user_func(static::$toMailCallback, $notifiable, $verificationUrl);
}

return (new MailMessage)
->subject(Lang::get('Verify Email Address'))
->line(Lang::get('Please click the button below to verify your email address.'))
->action(Lang::get('Verify Email Address'), $verificationUrl)
->line(Lang::get('If you did not create an account, no further action is required.'));
}

/**
* Get the verification URL for the given notifiable.
*
* @param mixed $notifiable
* @return string
*/
protected function verificationUrl($notifiable)
{
return URL::temporarySignedRoute(
'restify.verification.verify',
Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
[
'id' => $notifiable->getKey(),
'hash' => sha1($notifiable->getEmailForVerification()),
]
);
}

/**
* Set a callback that should be used when building the notification mail message.
*
* @param \Closure $callback
* @return void
*/
public static function toMailUsing($callback)
{
static::$toMailCallback = $callback;
}
}
Loading