Skip to content

Commit

Permalink
Email verification is now configurable through a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ramoncrisante committed Aug 28, 2021
1 parent 0a64920 commit 1c66ffd
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 93 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

MUST_VERIFY_EMAIL=
2 changes: 1 addition & 1 deletion app/Http/Controllers/Api/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function login(LoginRequest $request)
$user = Auth::user();
$token = $user->createToken('API Token')->accessToken;

if (!$user->hasVerifiedEmail()) {
if (config('auth.must_verify_email') && !$user->hasVerifiedEmail()) {
return response([
'message' => 'Email must be verified.'
], 401);
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/Api/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public function register(RegisterRequest $request)
'password' => Hash::make($request->input('password')),
]);

event(new Registered($user));
if (config('auth.must_verify_email')) {
event(new Registered($user));
}

return response()->json($user);
} catch (\Exception $e) {
Expand Down
11 changes: 11 additions & 0 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class User extends Authenticatable implements MustVerifyEmail
{
use HasFactory, Notifiable, HasApiTokens;

protected $appends = ['must_verify_email'];
/**
* The attributes that are mass assignable.
*
Expand Down Expand Up @@ -42,4 +43,14 @@ class User extends Authenticatable implements MustVerifyEmail
protected $casts = [
'email_verified_at' => 'datetime',
];

/**
* Determine if the user is an administrator.
*
* @return bool
*/
public function getMustVerifyEmailAttribute()
{
return config('auth.must_verify_email');
}
}
2 changes: 2 additions & 0 deletions config/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,6 @@

'password_timeout' => 10800,

'must_verify_email' => env('MUST_VERIFY_EMAIL', false),

];
Loading

0 comments on commit 1c66ffd

Please sign in to comment.