Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
athphane committed Mar 7, 2024
2 parents 27e429d + cf15c6b commit dad381d
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 37 deletions.
16 changes: 2 additions & 14 deletions config/config.php
Expand Up @@ -14,7 +14,7 @@

'defaults' => [
'guard' => env('AUTH_GUARD', 'web_admin'),
'passwords' => 'users',
'passwords' => env('AUTH_PASSWORD_BROKER', 'users'),
],

/*
Expand Down Expand Up @@ -98,7 +98,7 @@
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_reset_tokens',
'table' => env('AUTH_PASSWORD_RESET_TOKEN_TABLE', 'password_reset_tokens'),
'expire' => 60,
'throttle' => 60,
],
Expand All @@ -117,18 +117,6 @@

'password_timeout' => env('AUTH_PASSWORD_TIMEOUT', 10800),

/*
|--------------------------------------------------------------------------
| Max login attempts
|--------------------------------------------------------------------------
|
| The maximum login attempts allowed before a user gets locked out.
| This is a custom configuration.
|
*/

'default_guard' => 'web_admin',

/*
|--------------------------------------------------------------------------
| Max login attempts
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Requests/UsersRequest.php
Expand Up @@ -31,9 +31,9 @@ protected function morphClass(): string

abstract protected function editingCurrentUser(): bool;

abstract protected function getRouteUser(): User;
abstract protected function getRouteUser(): ?User;

protected function getUserBeingEdited(): User
protected function getUserBeingEdited(): ?User
{
if ($this->editingCurrentUser()) {
return $this->user();
Expand Down
50 changes: 50 additions & 0 deletions src/Mail/EmailUpdated.php
@@ -0,0 +1,50 @@
<?php

namespace Javaabu\Auth\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Notifications\Messages\MailMessage;

class EmailUpdated extends Mailable
{
use Queueable;
use SerializesModels;

protected $user;

/**
* The new email
*
* @var string
*/
public $new_email;

/**
* Create a new message instance.
* @param $user
* @param $new_email
*/
public function __construct($user, $new_email)
{
$this->user = $user;
$this->new_email = $new_email;
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
$message = (new MailMessage())
->greeting("Hi {$this->user->name},")
->line("We have updated your email address to {$this->new_email}.")
->line('You can no longer login using your old email address.')
->line('If you did not make this request, contact us immediately.');

return $this->markdown('vendor.notifications.email')->with($message->data());
}
}
72 changes: 72 additions & 0 deletions src/Mail/NewEmailVerification.php
@@ -0,0 +1,72 @@
<?php

namespace Javaabu\Auth\Mail;

use Javaabu\Auth\User;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Facades\Lang;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Config;
use Illuminate\Notifications\Messages\MailMessage;

class NewEmailVerification extends Mailable
{
use Queueable;
use SerializesModels;

/**
* @var User $user
*/
protected $user;

/**
* Create a new message instance.
*
* @param User $user
*/
public function __construct(User $user)
{
$this->user = $user;
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
$verificationUrl = $this->verificationUrl($this->user);

$message = (new MailMessage())
->subject(Lang::get('Verify New Email Address'))
->greeting(Lang::get('Hi :user,', ['user' => $this->user->name]))
->line(Lang::get('You are receiving this email since you have requested to update your email address to this new email.'))
->line(Lang::get('Please click the button below to verify your new email address.'))
->action(Lang::get('Verify New Email Address'), $verificationUrl)
->line(Lang::get('If you did not request to update your email, no further action is required.'));

return $this->markdown('vendor.notifications.email')->with($message->data());
}

/**
* Get the verification URL for the given user.
*
* @param User $user
* @return string
*/
protected function verificationUrl(User $user)
{
return URL::temporarySignedRoute(
$user->getRouteForEmailVerification(),
Carbon::now()->addMinutes(Config::get('auth.verification.expire', 60)),
[
'id' => $user->getKey(),
'hash' => sha1($user->getEmailForVerification()),
]
);
}
}
24 changes: 3 additions & 21 deletions src/User.php
Expand Up @@ -11,6 +11,8 @@
use Illuminate\Support\Facades\Mail;
use Javaabu\Activitylog\Traits\LogsActivity;
use Javaabu\Auth\Enums\UserStatuses;
use Javaabu\Auth\Mail\EmailUpdated;
use Javaabu\Auth\Mail\NewEmailVerification;
use Javaabu\Auth\Notifications\EmailUpdateRequest;
use Javaabu\Auth\Notifications\ResetPassword;
use Javaabu\Auth\Notifications\VerifyEmail;
Expand Down Expand Up @@ -241,7 +243,7 @@ public function findForPassport($username): mixed
/**
* Get pending key
*/
public function getPendingKey(): int
public function getPendingKey(): UserStatuses
{
return UserStatuses::PENDING;
}
Expand Down Expand Up @@ -442,26 +444,6 @@ public function getIsPendingAttribute(): bool
return $this->status == UserStatuses::PENDING;
}

/**
* Check if the user has any of the following permissions
*
* @param array|string $permissions
*/
public function anyPermission($permissions): bool
{
if (! is_array($permissions)) {
$permissions = [$permissions];
}

foreach ($permissions as $permission) {
if ($this->can($permission)) {
return true;
}
}

return false;
}

/**
* User visible
*/
Expand Down

0 comments on commit dad381d

Please sign in to comment.