From ab31980b116ecd497d5d4610c212ae7b1f61fada Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sun, 24 May 2015 17:17:52 +0200 Subject: Password reminders --- .../BotleaguesApi/Database/PasswordReminder.php | 38 ++++++++++++++-------- 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php') 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 -- cgit v1.2.3