-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Paul Vidal
committed
Feb 10, 2017
0 parents
commit 9d261d7
Showing
98 changed files
with
7,802 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"name": "tecactus/skeleton", | ||
"description": "The Laravel Framework Skeleton Application.", | ||
"keywords": ["framework", "laravel", "skeleton", "application", "demo", "tecactus"], | ||
"license": "MIT", | ||
"type": "library", | ||
"require": { | ||
"barryvdh/laravel-snappy": "^0.3.1", | ||
"dompdf/dompdf": "^0.6.0", | ||
"h4cc/wkhtmltoimage-amd64": "0.12.x", | ||
"h4cc/wkhtmltopdf-amd64": "0.12.x", | ||
"laravelcollective/html": "^5.4.0", | ||
"overtrue/laravel-lang": "~3.0", | ||
"yajra/laravel-datatables-buttons": "^1.0", | ||
"yajra/laravel-datatables-oracle": "^7.0" | ||
}, | ||
"autoload": { | ||
"files": [ | ||
"src/Support/helpers.php" | ||
], | ||
"psr-4": { | ||
"Tecactus\\Skeleton\\": "src/" | ||
} | ||
} | ||
} |
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 @@ | ||
# Skeleton |
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,183 @@ | ||
<?php | ||
|
||
namespace Tecactus\Skeleton\Auth\Activation; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Support\Str; | ||
use Illuminate\Database\ConnectionInterface; | ||
use Tecactus\Skeleton\Contracts\CanActivateAccount as CanActivateAccountContract; | ||
|
||
class ActivationTokenRepository | ||
{ | ||
/** | ||
* The database connection instance. | ||
* | ||
* @var \Illuminate\Database\ConnectionInterface | ||
*/ | ||
protected $connection; | ||
|
||
/** | ||
* The token database table. | ||
* | ||
* @var string | ||
*/ | ||
protected $table; | ||
|
||
/** | ||
* The hashing key. | ||
* | ||
* @var string | ||
*/ | ||
protected $hashKey; | ||
|
||
/** | ||
* The number of seconds a token should last. | ||
* | ||
* @var int | ||
*/ | ||
protected $expires; | ||
|
||
/** | ||
* Create a new token repository instance. | ||
* | ||
* @param \Illuminate\Database\ConnectionInterface $connection | ||
* @param string $table | ||
* @param string $hashKey | ||
* @param int $expires | ||
* @return void | ||
*/ | ||
public function __construct(ConnectionInterface $connection, $table, $hashKey, $expires = 7) | ||
{ | ||
$this->table = $table; | ||
$this->hashKey = $hashKey; | ||
$this->expires = $expires; | ||
$this->connection = $connection; | ||
} | ||
|
||
/** | ||
* Create a new token record. | ||
* | ||
* @param \Tecactus\Skeleton\Contracts\CanActivateAccount $user | ||
* @return string | ||
*/ | ||
public function create(CanActivateAccountContract $user) | ||
{ | ||
$email = $user->getEmailForAccountActivation(); | ||
|
||
$this->deleteExisting($user); | ||
|
||
// We will create a new, random token for the user so that we can e-mail them | ||
// a safe link to the account activation method. Then we will insert a record in | ||
// the database so that we can verify the token within the actual activation. | ||
$token = $this->createNewToken(); | ||
|
||
$this->getTable()->insert($this->getPayload($email, $token)); | ||
|
||
return $token; | ||
} | ||
|
||
/** | ||
* Delete all existing activation tokens from the database. | ||
* | ||
* @param \Tecactus\Skeleton\Contracts\CanActivateAccount $user | ||
* @return int | ||
*/ | ||
protected function deleteExisting(CanActivateAccountContract $user) | ||
{ | ||
$email = $user->getEmailForAccountActivation(); | ||
|
||
return $this->getTable()->where('email', $email)->delete(); | ||
} | ||
|
||
/** | ||
* Build the record payload for the table. | ||
* | ||
* @param string $email | ||
* @param string $token | ||
* @return array | ||
*/ | ||
protected function getPayload($email, $token) | ||
{ | ||
return ['email' => $email, 'token' => $token, 'created_at' => new Carbon]; | ||
} | ||
|
||
/** | ||
* Determine if a token record exists and is valid. | ||
* | ||
* @param \Tecactus\Skeleton\Contracts\CanActivateAccount $user | ||
* @param string $token | ||
* @return bool | ||
*/ | ||
public function exists($token, $email) | ||
{ | ||
$token = (array) $this->getTable()->where('email', $email)->where('token', $token)->first(); | ||
|
||
return $token && ! $this->tokenExpired($token); | ||
} | ||
|
||
/** | ||
* Determine if the token has expired. | ||
* | ||
* @param array $token | ||
* @return bool | ||
*/ | ||
protected function tokenExpired($token) | ||
{ | ||
$expiresAt = Carbon::parse($token['created_at'])->addDays($this->expires); | ||
|
||
return $expiresAt->isPast(); | ||
} | ||
|
||
/** | ||
* Delete a token record by token. | ||
* | ||
* @param string $token | ||
* @return void | ||
*/ | ||
public function delete($token) | ||
{ | ||
$this->getTable()->where('token', $token)->delete(); | ||
} | ||
|
||
/** | ||
* Delete expired tokens. | ||
* | ||
* @return void | ||
*/ | ||
public function deleteExpired() | ||
{ | ||
$expiredAt = Carbon::now()->subDays($this->expires); | ||
|
||
$this->getTable()->where('created_at', '<', $expiredAt)->delete(); | ||
} | ||
|
||
/** | ||
* Create a new token for the user. | ||
* | ||
* @return string | ||
*/ | ||
public function createNewToken() | ||
{ | ||
return hash_hmac('sha256', Str::random(40), $this->hashKey); | ||
} | ||
|
||
/** | ||
* Begin a new database query against the table. | ||
* | ||
* @return \Illuminate\Database\Query\Builder | ||
*/ | ||
protected function getTable() | ||
{ | ||
return $this->connection->table($this->table); | ||
} | ||
|
||
/** | ||
* Get the database connection instance. | ||
* | ||
* @return \Illuminate\Database\ConnectionInterface | ||
*/ | ||
public function getConnection() | ||
{ | ||
return $this->connection; | ||
} | ||
} |
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 Tecactus\Skeleton\Auth\Activation; | ||
|
||
use Tecactus\Skeleton\Auth\Notifications\AccountActivation as AccountActivationNotification; | ||
|
||
trait CanActivateAccount | ||
{ | ||
/** | ||
* Get the e-mail address where account activation links are sent. | ||
* | ||
* @return string | ||
*/ | ||
public function getEmailForAccountActivation() | ||
{ | ||
return $this->email; | ||
} | ||
|
||
/** | ||
* Send the account activation notification. | ||
* | ||
* @param string $token | ||
* @return void | ||
*/ | ||
public function sendAccountActivationNotification($token) | ||
{ | ||
$this->notify(new AccountActivationNotification($token, $this->email)); | ||
} | ||
} |
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,79 @@ | ||
<?php | ||
|
||
namespace Tecactus\Skeleton\Auth\Notifications; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Notifications\Notification; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
|
||
class AccountActivation extends Notification | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* The password activation token. | ||
* | ||
* @var string | ||
*/ | ||
public $token; | ||
|
||
/** | ||
* The user email address. | ||
* | ||
* @var string | ||
*/ | ||
public $email; | ||
|
||
/** | ||
* Create a notification instance. | ||
* | ||
* @param string $token | ||
* @return void | ||
*/ | ||
public function __construct($token, $email) | ||
{ | ||
$this->token = $token; | ||
$this->email = $email; | ||
} | ||
|
||
/** | ||
* Get the notification's channels. | ||
* | ||
* @param mixed $notifiable | ||
* @return array|string | ||
*/ | ||
public function via($notifiable) | ||
{ | ||
return ['mail']; | ||
} | ||
|
||
/** | ||
* Build the mail representation of the notification. | ||
* | ||
* @return \Illuminate\Notifications\Messages\MailMessage | ||
*/ | ||
public function toMail() | ||
{ | ||
return (new MailMessage) | ||
->subject('Activa tu Cuenta - ' . config('app.name')) | ||
->line([ | ||
'Estas recibiendo este email porque necesitas activar tu cuenta para poder usar por completo nuestro servicio.', | ||
'Has click en el botón de abajo para activar tu cuenta:', | ||
]) | ||
->action('Activar mi Cuenta', route('activation', ['token' => $this->token ,'email' => $this->email])); | ||
} | ||
|
||
/** | ||
* Get the array representation of the notification. | ||
* | ||
* @param mixed $notifiable | ||
* @return array | ||
*/ | ||
public function toArray($notifiable) | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
} |
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,72 @@ | ||
<?php | ||
|
||
namespace Tecactus\Skeleton\Auth\Notifications; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Notifications\Notification; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
|
||
class ResetPassword extends Notification | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* The password reset token. | ||
* | ||
* @var string | ||
*/ | ||
public $token; | ||
|
||
/** | ||
* Create a notification instance. | ||
* | ||
* @param string $token | ||
* @return void | ||
*/ | ||
public function __construct($token) | ||
{ | ||
$this->token = $token; | ||
} | ||
|
||
/** | ||
* Get the notification's channels. | ||
* | ||
* @param mixed $notifiable | ||
* @return array|string | ||
*/ | ||
public function via($notifiable) | ||
{ | ||
return ['mail']; | ||
} | ||
|
||
/** | ||
* Build the mail representation of the notification. | ||
* | ||
* @return \Illuminate\Notifications\Messages\MailMessage | ||
*/ | ||
public function toMail() | ||
{ | ||
return (new MailMessage) | ||
->subject('Solicitud de Cambio de Contraseña - ' . config('app.name')) | ||
->line([ | ||
'Estas recibiendo este mensaje porque hemos recibido una solicitud de cambio de contraseña para tu cuenta.', | ||
'Has click en el siguiente botón para cambiar tu contraseña:', | ||
]) | ||
->action('Cambiar mi Contraseña', route('password-reset', ['token' => $this->token])) | ||
->line('Si no has solicitado un cambio de contraseña, ignora este mensaje.'); | ||
} | ||
|
||
/** | ||
* Get the array representation of the notification. | ||
* | ||
* @param mixed $notifiable | ||
* @return array | ||
*/ | ||
public function toArray($notifiable) | ||
{ | ||
return [ | ||
// | ||
]; | ||
} | ||
} |
Oops, something went wrong.