summaryrefslogtreecommitdiff
path: root/protected/models/User.php
diff options
context:
space:
mode:
Diffstat (limited to 'protected/models/User.php')
-rw-r--r--protected/models/User.php36
1 files changed, 32 insertions, 4 deletions
diff --git a/protected/models/User.php b/protected/models/User.php
index e0a5eeb..c432afe 100644
--- a/protected/models/User.php
+++ b/protected/models/User.php
@@ -1,9 +1,9 @@
<?php
/**
- * This is the model class for table "astaf_user".
+ * This is the model class for table "benutzer".
*
- * The followings are the available columns in table 'astaf_user':
+ * The followings are the available columns in table 'benutzer':
* @property integer $id
* @property string $username
* @property string $algorithm
@@ -13,6 +13,11 @@
* @property string $last_login
* @property integer $is_active
* @property integer $is_super_admin
+ * @property integer $admin_pw_reset
+ * @property integer $user_pw_reset
+ *
+ * The followings are the available model relations:
+ * @property Vereine[] $vereine
*/
class User extends CActiveRecord
{
@@ -43,9 +48,9 @@ class User extends CActiveRecord
// will receive user inputs.
return array(
array('username, password', 'required'),
- array('is_active, is_super_admin', 'numerical', 'integerOnly'=>true),
+ array('is_active, is_super_admin, admin_pw_reset, user_pw_reset', 'numerical', 'integerOnly'=>true),
array('username, password', 'length', 'max'=>128),
- array('created_at', 'safe'),
+ array('created_at, last_login', 'safe'),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, username, created_at, last_login, is_active, is_super_admin', 'safe', 'on'=>'search'),
@@ -60,6 +65,7 @@ class User extends CActiveRecord
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
+ 'vereine' => array(self::HAS_MANY, 'Vereine', 'slug'),
);
}
@@ -83,6 +89,7 @@ class User extends CActiveRecord
if ($this->isNewRecord) {
$this->created_at = new CDbExpression("NOW()");
$this->salt = $this->generateRandomKey();
+ $this->admin_pw_reset = true;
}
if (!$this->checkPassword($this->password)) {
@@ -120,6 +127,27 @@ class User extends CActiveRecord
return $this->encryptPassword($password) == $this->password;
}
+ public function generateNewPassword() {
+ $hashes = array();
+ $hashes[0] = hash("sha256", "aSTaF2012");
+ $hashes[1] = hash("sha256", $this->username);
+ $hashes[2] = hash("sha256", $this->id);
+
+ $r1 = mt_rand();
+ $r1 = $r1 % 3;
+
+ $r2 = mt_rand();
+ $r2 = $r2 % 3;
+
+ $r3 = mt_rand();
+ $r3 = $r3 % 3;
+
+ $hash = hash("sha256", $hashes[$r2].$hashes[$r1].$hashes[$r3]);
+ $pw = substr($hash, mt_rand(0, 58), mt_rand(7, 10));
+
+ return $pw;
+ }
+
protected function encryptPassword($password) {
return sha1($this->salt.$password);
}