Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Vidal committed Feb 10, 2017
0 parents commit 9d261d7
Show file tree
Hide file tree
Showing 98 changed files with 7,802 additions and 0 deletions.
25 changes: 25 additions & 0 deletions composer.json
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/"
}
}
}
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Skeleton
183 changes: 183 additions & 0 deletions src/Auth/Activation/ActivationTokenRepository.php
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;
}
}
29 changes: 29 additions & 0 deletions src/Auth/Activation/CanActivateAccount.php
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));
}
}
79 changes: 79 additions & 0 deletions src/Auth/Notifications/AccountActivation.php
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 [
//
];
}
}
72 changes: 72 additions & 0 deletions src/Auth/Notifications/ResetPassword.php
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 [
//
];
}
}
Loading

0 comments on commit 9d261d7

Please sign in to comment.