-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#247 email validation
- Loading branch information
Showing
10 changed files
with
148 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace HMS\Traits\Entities; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Auth\Notifications\VerifyEmail; | ||
use LaravelDoctrine\ORM\Facades\EntityManager; | ||
|
||
trait DoctrineMustVerifyEmail | ||
{ | ||
/** | ||
* @var null|Carbon Has the email address be verified | ||
*/ | ||
protected $emailVerifiedAt; | ||
|
||
/** | ||
* Determine if the user has verified their email address. | ||
* | ||
* @return bool | ||
*/ | ||
public function hasVerifiedEmail() | ||
{ | ||
return ! is_null($this->emailVerifiedAt); | ||
} | ||
|
||
/** | ||
* Mark the given user's email as verified. | ||
* | ||
* @return bool | ||
*/ | ||
public function markEmailAsVerified() | ||
{ | ||
$repository = EntityManager::getRepository(get_class($this)); | ||
$this->emailVerifiedAt = new Carbon; | ||
$repository->save($this); | ||
|
||
return true; | ||
} | ||
|
||
/** | ||
* Send the email verification notification. | ||
* | ||
* @return void | ||
*/ | ||
public function sendEmailVerificationNotification() | ||
{ | ||
$this->notify(new VerifyEmail); | ||
} | ||
|
||
/** | ||
* @return null|Carbon Has the email address be verified | ||
*/ | ||
public function getEmailVerifiedAt() | ||
{ | ||
return $this->emailVerifiedAt; | ||
} | ||
|
||
/** | ||
* @param null|Carbon Has the email address be verified $emailVerifiedAt | ||
* | ||
* @return self | ||
*/ | ||
public function setEmailVerifiedAt($emailVerifiedAt) | ||
{ | ||
$this->emailVerifiedAt = $emailVerifiedAt; | ||
|
||
return $this; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
database/migrations_doctrine/Version20181223163238_user_table_email_verified.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Database\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema as Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
class Version20181223163238_user_table_email_verified extends AbstractMigration | ||
{ | ||
/** | ||
* @param Schema $schema | ||
*/ | ||
public function up(Schema $schema) | ||
{ | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('ALTER TABLE user ADD email_verified_at DATETIME DEFAULT NULL'); | ||
} | ||
|
||
/** | ||
* @param Schema $schema | ||
*/ | ||
public function down(Schema $schema) | ||
{ | ||
$this->abortIf($this->connection->getDatabasePlatform()->getName() != 'mysql', 'Migration can only be executed safely on \'mysql\'.'); | ||
|
||
$this->addSql('ALTER TABLE user DROP email_verified_at'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
<?php | ||
|
||
use Carbon\Carbon; | ||
use HMS\Entities\Role; | ||
use HMS\Entities\User; | ||
use HMS\Auth\PasswordStore; | ||
|
@@ -92,6 +93,7 @@ public function run() | |
if ($this->createAdmin === true) { | ||
$admin = new User('Admin', 'Admin', 'admin', '[email protected]'); | ||
$admin->getRoles()->add($this->roleRepository->findOneByName(Role::SUPERUSER)); | ||
$admin->setEmailVerifiedAt(new Carbon); | ||
$this->passwordStore->add($admin->getUsername(), 'admin'); | ||
EntityManager::persist($admin); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
@extends('layouts.app') | ||
|
||
@section('pageTitle', 'Verify email') | ||
|
||
@section('content') | ||
<div class="container"> | ||
<div class="row justify-content-center"> | ||
<div class="col-md-8"> | ||
<div class="card"> | ||
<div class="card-header">{{ __('Verify Your Email Address') }}</div> | ||
|
||
<div class="card-body"> | ||
@if (session('resent')) | ||
<div class="alert alert-success" role="alert"> | ||
{{ __('A fresh verification link has been sent to your email address.') }} | ||
</div> | ||
@endif | ||
|
||
{{ __('Before proceeding, please check your email for a verification link.') }} | ||
{{ __('If you did not receive the email') }}, <a href="{{ route('verification.resend') }}">{{ __('click here to request another') }}</a>. | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters