diff options
author | Camil Staps | 2015-05-24 22:42:26 +0200 |
---|---|---|
committer | Camil Staps | 2015-05-24 22:42:26 +0200 |
commit | ea7966cc6823ddaa349740e438c4f0cb588f5b32 (patch) | |
tree | ab5e2bb9de2b64ee3cdc7d5c0bfbca61ce742335 /src/CamilStaps/BotleaguesApi/Database | |
parent | Using email as id; User & PasswordReminder (diff) |
User id -> email in other classes
Diffstat (limited to 'src/CamilStaps/BotleaguesApi/Database')
4 files changed, 15 insertions, 6 deletions
diff --git a/src/CamilStaps/BotleaguesApi/Database/Bot.php b/src/CamilStaps/BotleaguesApi/Database/Bot.php index f0be0fc..abdd78a 100644 --- a/src/CamilStaps/BotleaguesApi/Database/Bot.php +++ b/src/CamilStaps/BotleaguesApi/Database/Bot.php @@ -4,6 +4,6 @@ namespace CamilStaps\BotleaguesApi\Database; class Bot extends Model { protected $table = 'bots'; - protected $fillable = ['userId', 'gameId', 'title']; + protected $fillable = ['userEmail', 'gameId', 'title']; }
\ No newline at end of file diff --git a/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php b/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php index 696a0a1..18c60d0 100644 --- a/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php +++ b/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php @@ -14,7 +14,7 @@ class PasswordReminder extends Model { protected $table = 'password_reminders'; protected $hidden = ['token']; - protected $fillable = ['userId', 'token', 'valid_till']; + protected $fillable = ['userEmail', 'token', 'valid_till']; protected $primaryKey = 'token'; public static function boot() { @@ -25,7 +25,7 @@ class PasswordReminder extends Model { $user = User::findOrFail($passwordReminder->userEmail); Mail::send('botleagues-api::emails.auth.reminder', ['token' => $passwordReminder->token], function($message) use ($user) { - $message->to($user->email, "User " . $user->id); + $message->to($user->email, "User " . $user->email); }); }); } diff --git a/src/CamilStaps/BotleaguesApi/Database/User.php b/src/CamilStaps/BotleaguesApi/Database/User.php index 6b0d863..cabd126 100644 --- a/src/CamilStaps/BotleaguesApi/Database/User.php +++ b/src/CamilStaps/BotleaguesApi/Database/User.php @@ -23,12 +23,17 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon } public function validToken($token) { - return UserToken::where('userId', $this->id)->where('token', $token)->where('valid_till', '>', date("Y-m-d H:i:s"))->count() > 0; + $token = UserToken::where('userEmail', $this->email)->where('token', $token)->where('valid_till', '>', date("Y-m-d H:i:s"))->first(); + if (empty($token)) { + return false; + } + $token->refresh(); + return true; } public function findPasswordReminders($token = null) { $base = PasswordReminder - ::where('userId', $this->id) + ::where('userEmail', $this->email) ->where('used_at', null) ->where('valid_till', '>', date('Y-m-d H:i:s')); if ($token == null) { diff --git a/src/CamilStaps/BotleaguesApi/Database/UserToken.php b/src/CamilStaps/BotleaguesApi/Database/UserToken.php index 92b03b8..f328f59 100644 --- a/src/CamilStaps/BotleaguesApi/Database/UserToken.php +++ b/src/CamilStaps/BotleaguesApi/Database/UserToken.php @@ -5,7 +5,7 @@ class UserToken extends Model { protected $table = 'user_tokens'; protected $hidden = ['token']; - protected $fillable = ['userId', 'token', 'valid_till']; + protected $fillable = ['userEmail', 'token', 'valid_till']; protected $dates = ['created_at', 'updated_at', 'valid_till']; /** @@ -21,4 +21,8 @@ class UserToken extends Model { return $this->formatDate($attr); } + public function refresh() { + $this->save(); + } + }
\ No newline at end of file |