diff options
Diffstat (limited to 'src/CamilStaps')
-rw-r--r-- | src/CamilStaps/BotleaguesApi/PasswordReminder.php | 40 | ||||
-rw-r--r-- | src/CamilStaps/BotleaguesApi/User.php | 16 |
2 files changed, 53 insertions, 3 deletions
diff --git a/src/CamilStaps/BotleaguesApi/PasswordReminder.php b/src/CamilStaps/BotleaguesApi/PasswordReminder.php new file mode 100644 index 0000000..a129dc8 --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/PasswordReminder.php @@ -0,0 +1,40 @@ +<?php +/** + * Created by PhpStorm. + * User: camilstaps + * Date: 13-5-15 + * Time: 13:12 + */ + +namespace CamilStaps\BotleaguesApi; + + +use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Mail; + +class PasswordReminder extends Model { + + protected $table = 'password_reminders'; + protected $hidden = ['token']; + protected $fillable = ['userId', 'token', 'valid_till']; + + /** + * 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); + + $user = User::find($this->userId); + Mail::send('packages.camil-staps.botleagues-api.emails.auth.reminder', ['token' => $this->token], function($message) use ($user) { + $message->to($user->email, "User " . $user->id); + }); + + return parent::save($options); + } + + /** + * Disable updated_at timestamp + */ + public function setUpdatedAtAttribute($value) {} + +}
\ No newline at end of file diff --git a/src/CamilStaps/BotleaguesApi/User.php b/src/CamilStaps/BotleaguesApi/User.php index 220db36..560f737 100644 --- a/src/CamilStaps/BotleaguesApi/User.php +++ b/src/CamilStaps/BotleaguesApi/User.php @@ -1,10 +1,11 @@ <?php namespace CamilStaps\BotleaguesApi; +use Illuminate\Auth\Reminders\RemindableInterface; use Illuminate\Auth\UserInterface; use Illuminate\Database\Eloquent\Model; -class User extends Model implements UserInterface { +class User extends Model implements UserInterface, RemindableInterface { protected $table = 'users'; protected $hidden = ['password', 'remember_token', 'api_key']; @@ -24,7 +25,7 @@ class User extends Model implements UserInterface { * @return mixed */ public function getAuthIdentifier() { - return $this->email; + return $this->getKey(); } /** @@ -33,7 +34,7 @@ class User extends Model implements UserInterface { * @return string */ public function getAuthPassword() { - return null; + return $this->password; } /** @@ -63,4 +64,13 @@ class User extends Model implements UserInterface { public function getRememberTokenName() { return null; } + + /** + * Get the e-mail address where password reminders are sent. + * + * @return string + */ + public function getReminderEmail() { + return $this->email; + } }
\ No newline at end of file |