Implemented e-mail confirmations
This commit is contained in:
@@ -5,6 +5,8 @@ namespace App\Models;
|
||||
use AdamWathan\EloquentOAuth\OAuthIdentity;
|
||||
use App\Models\Concerns\InstanceCache;
|
||||
use App\Models\Concerns\Reportable;
|
||||
use App\Notifications\ConfirmEmail;
|
||||
use Hash;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
@@ -16,6 +18,7 @@ use Illuminate\Foundation\Auth\Access\Authorizable;
|
||||
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
|
||||
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
|
||||
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
|
||||
use MightyPork\Utils\Str;
|
||||
|
||||
/**
|
||||
* A user in the application
|
||||
@@ -36,6 +39,7 @@ use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
|
||||
* @property-read TableComment[]|Collection $tableComments
|
||||
* @property-read Table[]|Collection $favouriteTables
|
||||
* @property-read Table[]|Collection $followedDiscussions
|
||||
* @property-read EmailConfirmation[]|Collection $emailConfirmations
|
||||
* @property-read ContentReport[]|Collection $authoredReports
|
||||
* @property-read Notification[]|Collection $notifications
|
||||
* @property-read Notification[]|Collection $readNotifications
|
||||
@@ -132,6 +136,12 @@ class User extends BaseModel implements
|
||||
return $this->hasMany(ContentReport::class, 'author_id');
|
||||
}
|
||||
|
||||
/** User's e-mail confirmations */
|
||||
public function emailConfirmations()
|
||||
{
|
||||
return $this->hasMany(EmailConfirmation::class);
|
||||
}
|
||||
|
||||
// --------- Relation Helpers ---------
|
||||
|
||||
public function addFavourite(Table $table)
|
||||
@@ -198,4 +208,18 @@ class User extends BaseModel implements
|
||||
->where('user_id', $this->id)
|
||||
->where('table_id', $table->id)->exists();
|
||||
}
|
||||
|
||||
public function sendEmailConfirmationLink($newEmail)
|
||||
{
|
||||
// delete old confirmation tokens
|
||||
$this->emailConfirmations()->delete();
|
||||
|
||||
$confirmation = EmailConfirmation::create([
|
||||
'user_id' => $this->id,
|
||||
'email' => $newEmail,
|
||||
'token' => Hash::make(Str::random(40)),
|
||||
]);
|
||||
|
||||
$this->notify(new ConfirmEmail($newEmail, $confirmation->token));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user