Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jrean committed Oct 26, 2018
1 parent 5f3ce72 commit cd0e939
Showing 1 changed file with 8 additions and 34 deletions.
42 changes: 8 additions & 34 deletions src/UserVerification.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public function __construct(Mailer $mailer, Builder $schema)
{
$this->mailer = $mailer;
$this->schema = $schema;

if (! $this->isCompliant()) {
throw new ModelNotCompliantException();
}
}

/**
Expand Down Expand Up @@ -85,10 +89,6 @@ protected function generateToken()
*/
protected function saveToken(AuthenticatableContract $user, $token)
{
if (! $this->isCompliant($user)) {
throw new ModelNotCompliantException();
}

$user->verified = false;

$user->verification_token = $token;
Expand All @@ -114,10 +114,6 @@ public function send(
$name = null
)
{
if (! $this->isCompliant($user)) {
throw new ModelNotCompliantException();
}

$this->emailVerificationLink($user, $subject, $from, $name);

event(new VerificationEmailSent($user));
Expand All @@ -141,10 +137,6 @@ public function sendQueue(
$name = null
)
{
if (! $this->isCompliant($user)) {
throw new ModelNotCompliantException();
}

$this->emailQueueVerificationLink($user, $subject, $from, $name);

event(new VerificationEmailSent($user));
Expand All @@ -170,10 +162,6 @@ public function sendLater(
$name = null
)
{
if (! $this->isCompliant($user)) {
throw new ModelNotCompliantException();
}

$this->emailLaterVerificationLink($delay, $user, $subject, $from, $name);

event(new VerificationEmailSent($user));
Expand Down Expand Up @@ -259,7 +247,7 @@ public function process($email, $token, $userTable)
unset($user->{"password"});

// Check if the given user is already verified.
// If he is, we stop here.
// If it is, we stop here.
$this->isVerified($user);

$this->verifyToken($user->verification_token, $token);
Expand Down Expand Up @@ -361,26 +349,12 @@ protected function updateUser($user)
* Determine if the given model table has the verified and verification_token
* columns.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return bool
*/
protected function isCompliant(AuthenticatableContract $user)
protected function isCompliant()
{
return $this->hasColumn($user, 'verified')
&& $this->hasColumn($user, 'verification_token')
? true
: false;
}
$user = config('auth.providers.users.model', App\User::class);

/**
* Check if the given model talbe has the given column.
*
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param string $column
* @return bool
*/
protected function hasColumn(AuthenticatableContract $user, $column)
{
return $this->schema->hasColumn($user->getTable(), $column);
return $this->schema->hasColumns((new $user())->getTable(), ['verified', 'verification_token'])? true : false;
}
}

0 comments on commit cd0e939

Please sign in to comment.