diff options
author | Camil Staps | 2015-05-24 17:17:52 +0200 |
---|---|---|
committer | Camil Staps | 2015-05-24 17:17:52 +0200 |
commit | ab31980b116ecd497d5d4610c212ae7b1f61fada (patch) | |
tree | e1708d0790c40eb13dbcb238280a0a32be3d9c2b /src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php | |
parent | Route caching (diff) |
Password reminders
Diffstat (limited to 'src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php')
-rw-r--r-- | src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php b/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php index 65c4773..012d140 100644 --- a/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php +++ b/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php @@ -8,6 +8,7 @@ namespace CamilStaps\BotleaguesApi\Database; +use Illuminate\Events\Dispatcher; use Illuminate\Support\Facades\Mail; class PasswordReminder extends Model { @@ -15,24 +16,35 @@ class PasswordReminder extends Model { protected $table = 'password_reminders'; protected $hidden = ['token']; protected $fillable = ['userId', 'token', 'valid_till']; + protected $primaryKey = 'token'; - /** - * Override the parent's save() function to automatically update the valid_till timestamp, and send an email - */ - public function save(array $options = array()) { - $this->valid_till = date("Y-m-d H:i:s", time() + 3600); + public static function boot() { + parent::boot(); - $user = User::findOrFail($this->userId); - Mail::send('botleagues-api::emails.auth.reminder', ['token' => $this->token], function($message) use ($user) { - $message->to($user->email, "User " . $user->id); + PasswordReminder::creating(function($passwordReminder) { + $passwordReminder->valid_till = date("Y-m-d H:i:s", time() + 3600); + + $user = User::findOrFail($passwordReminder->userId); + Mail::send('botleagues-api::emails.auth.reminder', ['token' => $passwordReminder->token], function($message) use ($user) { + $message->to($user->email, "User " . $user->id); + }); }); + } + + public function useToken() { + $this->used_at = date('Y-m-d H:i:s'); + $this->save(); + } - return parent::save($options); + public function getDates() { + return ['created_at']; } - /** - * Disable updated_at timestamp - */ - public function setUpdatedAtAttribute($value) {} + public function getUpdatedAtColumn() { + return null; + } + + public function setUpdatedAtAttribute() { + } }
\ No newline at end of file |