PHP code example of abolaradev / authora
1. Go to this page and download the library: Download abolaradev/authora library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
abolaradev / authora example snippets
use Abolaradev\Authora\Facades\Authora;
Authora::credentials([
'email' => '[email protected] ',
'password' => 'secret-password',
]);
Authora::credentials([
'name' => 'John Doe',
'email' => '[email protected] ',
'password' => 'secret-password',
])->register();
Authora::credentials([
'email' => '[email protected] ',
'password' => 'secret-password',
])->login();
Authora::logout();
Authora::credentials([
'phone' => '09123456789',
])->otp()->dispatch();
Authora::credentials([
'phone' => '09123456789',
'token' => '123456',
])->otp()->verify();
Authora::oauth('google');
'oauth' => [
'providers' => [
// 'google' => \App\Actions\Authentication\OAuth\Google::class,
],
'routes' => [
'redirect' => '/auth/{provider}/redirect',
'callback' => '/auth/{provider}/callback',
],
],
'providers' => [
'google' => \App\Actions\OAuth\Google::class,
'github' => \App\Actions\OAuth\GitHub::class,
],
use Illuminate\Contracts\Auth\MustVerifyEmail;
class User extends Authenticatable implements MustVerifyEmail
{
// ...
}
Authora::sendEmailVerificationNotification();
'email_verification' => [
'notice_view' => null,
'routes' => [
'notice' => '/email/verify',
'verify' => '/email/verify/{id}/{hash}',
],
],
use Illuminate\Auth\Notifications\VerifyEmail;
use Illuminate\Notifications\Messages\MailMessage;
public function boot(): void
{
// ...
VerifyEmail::toMailUsing(function (object $notifiable, string $url) {
return (new MailMessage)
->subject('Verify Email Address')
->line('Click the button below to verify your email address.')
->action('Verify Email Address', $url);
});
}
use Illuminate\Auth\Passwords\CanResetPassword as CanResetPasswordTrait;
use Illuminate\Contracts\Auth\CanResetPassword;
class User extends Model implements CanResetPassword
{
use CanResetPasswordTrait;
// ...
}
Authora::credentials([
'email' => '[email protected] ',
])
->passwordReset()
->sendResetLink();
Authora::credentials([
'token' => $token,
'email' => '[email protected] ',
'password' => 'new-secure-password',
'password_confirmation' => 'new-secure-password',
])
->passwordReset()
->saveNewPassword();
use Illuminate\Support\Facades\Route;
Route::get('/reset-password/{token}', function (string $token) {
return view('auth.reset-password', ['token' => $token]);
})->name('password.reset');
use App\Notifications\ResetPasswordNotification;
/**
* Send a password reset notification to the user.
*
* @param string $token
*/
public function sendPasswordResetNotification($token): void
{
$url = 'https://example.com/reset-password?token='.$token;
$this->notify(new ResetPasswordNotification($url));
}
class Login implements ShouldAuthenticate
{
use WithValidation, HandlesAuthRedirects;
/**
* Get the validation rules for password authentication.
*
* @return array
*/
protected function rules(): array
{
return [
'email' => Email::rules(),
'password' => '$execute) {
$validated = $this->getValidatedData();
$user = User::where('email', '=', $validated['email'])->first();
if (! $user || ! Hash::check($validated['password'], $user->password)) {
throw ValidationException::withMessages([
'email' => __('auth.failed'),
]);
}
Auth::login($user, $validated['remember'] ?? false);
Session::regenerate();
return $this->redirectToDashboard();
}
}
}
protected function rules(): array
{
return [
'email' => Email::rules(),
'password' => '
use Abolaradev\Authora\Enums\AuthenticationAction;
Authora::rateLimiter(AuthenticationAction::Login)
->key('Your-key')
->decaySeconds(1800)
->maxAttempts(3)
->execute();
'rate_limiter' => [
'max_attempts' => 50,
'decay_seconds' => 3600,
],
'redirect_to' => [
'login' => '/login',
'dashboard' => '/dashboard',
],
bash
php artisan vendor:publish --tag='authora-config'
bash
php artisan vendor:publish --tag='authora-lang'
bash
php artisan vendor:publish --tag='authora-migrations'
php artisan migrate
bash
php artisan authora:install
text
app/Actions/OAuth/Google.php
bash
php artisan authora:install