aboutsummaryrefslogtreecommitdiff
path: root/app/User.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/User.php')
-rw-r--r--app/User.php82
1 files changed, 82 insertions, 0 deletions
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 @@
+<?php
+/**
+ * HebrewParseTrainer - practice Hebrew verbs
+ * Copyright (C) 2015 Camil Staps <info@camilstaps.nl>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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;
+ }
+
+}