From c61b156f1bd93ec4aadd8adc78523b42b0232918 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sun, 4 Sep 2016 23:30:15 +0200 Subject: User creation and authentication --- app/User.php | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 app/User.php (limited to 'app/User.php') diff --git a/app/User.php b/app/User.php new file mode 100644 index 0000000..3c1799d --- /dev/null +++ b/app/User.php @@ -0,0 +1,82 @@ + + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +namespace HebrewParseTrainer; + +use Illuminate\Contracts\Auth\Authenticatable; +use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Facades\Hash; + +class User extends Model implements Authenticatable { + + protected $table = 'users'; + public $timestamps = false; + protected $fillable = ['email', 'name']; + + public function changePoints($kind, $change, $verb = null) { + $change = new PointChange; + $change->user = $this->id; + $change->change = $change; + $change->kind = $kind; + $change->verb = is_null($verb) ? null : $verb->id; + $change->save(); + + $this->points += $change; + $this->save(); + } + + public function setPasswordAttribute($pass) { + $this->attributes['password'] = Hash::make($pass); + } + + public function verifyPassword($pass) { + if (!Hash::check($pass, $this->password)) + return false; + + if (Hash::needsRehash($this->password)) { + $this->password = $pass; + $this->save(); + } + + return true; + } + + public function getAuthIdentifierName() { + return $this->email; + } + + public function getAuthIdentifier() { + return $this->id; + } + + public function getAuthPassword() { + return $this->password; + } + + public function getRememberToken() { + return null; + } + + public function setRememberToken($token) { + } + + public function getRememberTokenName() { + return null; + } + +} -- cgit v1.2.3