diff options
Diffstat (limited to 'src/CamilStaps/BotleaguesApi/Database')
-rw-r--r-- | src/CamilStaps/BotleaguesApi/Database/Bot.php | 9 | ||||
-rw-r--r-- | src/CamilStaps/BotleaguesApi/Database/Competition.php | 10 | ||||
-rw-r--r-- | src/CamilStaps/BotleaguesApi/Database/CompetitionType.php | 11 | ||||
-rw-r--r-- | src/CamilStaps/BotleaguesApi/Database/Game.php | 9 | ||||
-rw-r--r-- | src/CamilStaps/BotleaguesApi/Database/Model.php | 30 | ||||
-rw-r--r-- | src/CamilStaps/BotleaguesApi/Database/Participant.php | 10 | ||||
-rw-r--r-- | src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php | 38 | ||||
-rw-r--r-- | src/CamilStaps/BotleaguesApi/Database/User.php | 75 | ||||
-rw-r--r-- | src/CamilStaps/BotleaguesApi/Database/UserToken.php | 24 |
9 files changed, 216 insertions, 0 deletions
diff --git a/src/CamilStaps/BotleaguesApi/Database/Bot.php b/src/CamilStaps/BotleaguesApi/Database/Bot.php new file mode 100644 index 0000000..f0be0fc --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/Database/Bot.php @@ -0,0 +1,9 @@ +<?php +namespace CamilStaps\BotleaguesApi\Database; + +class Bot extends Model { + + protected $table = 'bots'; + protected $fillable = ['userId', 'gameId', 'title']; + +}
\ No newline at end of file diff --git a/src/CamilStaps/BotleaguesApi/Database/Competition.php b/src/CamilStaps/BotleaguesApi/Database/Competition.php new file mode 100644 index 0000000..c355c08 --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/Database/Competition.php @@ -0,0 +1,10 @@ +<?php +namespace CamilStaps\BotleaguesApi\Database; + +class Competition extends Model { + + protected $table = 'competitions'; + protected $hidden = []; + protected $fillable = ['gameId', 'title', 'description', 'competition_type', 'start', 'end', 'max_players']; + +}
\ No newline at end of file diff --git a/src/CamilStaps/BotleaguesApi/Database/CompetitionType.php b/src/CamilStaps/BotleaguesApi/Database/CompetitionType.php new file mode 100644 index 0000000..0107ffe --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/Database/CompetitionType.php @@ -0,0 +1,11 @@ +<?php +namespace CamilStaps\BotleaguesApi\Database; + +class CompetitionType extends Model { + + protected $table = 'competition_types'; + protected $primaryKey = 'type'; + protected $hidden = []; + protected $fillable = ['description', 'explanation']; + +}
\ No newline at end of file diff --git a/src/CamilStaps/BotleaguesApi/Database/Game.php b/src/CamilStaps/BotleaguesApi/Database/Game.php new file mode 100644 index 0000000..a8b0649 --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/Database/Game.php @@ -0,0 +1,9 @@ +<?php +namespace CamilStaps\BotleaguesApi\Database; + +class Game extends Model { + + protected $table = 'games'; + protected $fillable = ['title']; + +}
\ No newline at end of file diff --git a/src/CamilStaps/BotleaguesApi/Database/Model.php b/src/CamilStaps/BotleaguesApi/Database/Model.php new file mode 100644 index 0000000..27bd1fc --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/Database/Model.php @@ -0,0 +1,30 @@ +<?php +/** + * Created by PhpStorm. + * User: camilstaps + * Date: 14-5-15 + * Time: 10:47 + */ + +namespace CamilStaps\BotleaguesApi\Database; + +use Carbon\Carbon; + + +class Model extends \Illuminate\Database\Eloquent\Model { + + protected $date_format = Carbon::RFC2822; + + protected function formatDate($date) { + return Carbon::parse($date)->format($this->date_format); + } + + public function getCreatedAtAttribute($attr) { + return $this->formatDate($attr); + } + + public function getUpdatedAtAttribute($attr) { + return $this->formatDate($attr); + } + +}
\ No newline at end of file diff --git a/src/CamilStaps/BotleaguesApi/Database/Participant.php b/src/CamilStaps/BotleaguesApi/Database/Participant.php new file mode 100644 index 0000000..584d00c --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/Database/Participant.php @@ -0,0 +1,10 @@ +<?php +namespace CamilStaps\BotleaguesApi\Database; + +class Participant extends Model { + + protected $table = 'competition_types'; + protected $hidden = []; + protected $fillable = ['botId', 'competitionId']; + +}
\ No newline at end of file diff --git a/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php b/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php new file mode 100644 index 0000000..40bc578 --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/Database/PasswordReminder.php @@ -0,0 +1,38 @@ +<?php +/** + * Created by PhpStorm. + * User: camilstaps + * Date: 13-5-15 + * Time: 13:12 + */ + +namespace CamilStaps\BotleaguesApi\Database; + +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/Database/User.php b/src/CamilStaps/BotleaguesApi/Database/User.php new file mode 100644 index 0000000..383cc38 --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/Database/User.php @@ -0,0 +1,75 @@ +<?php +namespace CamilStaps\BotleaguesApi\Database; + +use Illuminate\Auth\Reminders\RemindableInterface; +use Illuminate\Auth\UserInterface; + +class User extends Model implements UserInterface, RemindableInterface { + + protected $table = 'users'; + protected $hidden = ['password', 'remember_token', 'api_key']; + protected $fillable = ['email', 'password']; + + public function isAdministrator() { + return (bool) $this->isAdministrator; + } + + 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; + } + + /** + * Get the unique identifier for the user. + * + * @return mixed + */ + public function getAuthIdentifier() { + return $this->getKey(); + } + + /** + * Get the password for the user. + * @todo not implemented yet + * @return string + */ + public function getAuthPassword() { + return $this->password; + } + + /** + * Get the token value for the "remember me" session. + * @todo not implemented yet + * @return string + */ + public function getRememberToken() { + return null; + } + + /** + * Set the token value for the "remember me" session. + * @todo not implemented yet + * @param string $value + * @return void + */ + public function setRememberToken($value) { + return null; + } + + /** + * Get the column name for the "remember me" token. + * @todo not implemented yet + * @return string + */ + 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 diff --git a/src/CamilStaps/BotleaguesApi/Database/UserToken.php b/src/CamilStaps/BotleaguesApi/Database/UserToken.php new file mode 100644 index 0000000..92b03b8 --- /dev/null +++ b/src/CamilStaps/BotleaguesApi/Database/UserToken.php @@ -0,0 +1,24 @@ +<?php +namespace CamilStaps\BotleaguesApi\Database; + +class UserToken extends Model { + + protected $table = 'user_tokens'; + protected $hidden = ['token']; + protected $fillable = ['userId', 'token', 'valid_till']; + protected $dates = ['created_at', 'updated_at', 'valid_till']; + + /** + * Override the parent's save() function to automatically update the valid_till timestamp + */ + public function save(array $options = array()) { + $this->valid_till = date("Y-m-d H:i:s", time() + 3600); + + return parent::save($options); + } + + public function getValidTillAttribute($attr) { + return $this->formatDate($attr); + } + +}
\ No newline at end of file |