@@ -12,121 +12,121 @@ |
||
12 | 12 | */ |
13 | 13 | class Events extends CiiModel |
14 | 14 | { |
15 | - /** |
|
16 | - * Adds the CTimestampBehavior to this class |
|
17 | - * @return array |
|
18 | - */ |
|
19 | - public function behaviors() |
|
20 | - { |
|
21 | - return array( |
|
22 | - 'CTimestampBehavior' => array( |
|
23 | - 'class' => 'zii.behaviors.CTimestampBehavior', |
|
24 | - 'createAttribute' => 'created', |
|
25 | - 'updateAttribute' => 'created', |
|
26 | - 'timestampExpression' => time(), |
|
27 | - 'setUpdateOnCreate' => false |
|
28 | - ) |
|
29 | - ); |
|
30 | - } |
|
15 | + /** |
|
16 | + * Adds the CTimestampBehavior to this class |
|
17 | + * @return array |
|
18 | + */ |
|
19 | + public function behaviors() |
|
20 | + { |
|
21 | + return array( |
|
22 | + 'CTimestampBehavior' => array( |
|
23 | + 'class' => 'zii.behaviors.CTimestampBehavior', |
|
24 | + 'createAttribute' => 'created', |
|
25 | + 'updateAttribute' => 'created', |
|
26 | + 'timestampExpression' => time(), |
|
27 | + 'setUpdateOnCreate' => false |
|
28 | + ) |
|
29 | + ); |
|
30 | + } |
|
31 | 31 | |
32 | - /** |
|
33 | - * Query Scoping |
|
34 | - */ |
|
35 | - public function scopes() |
|
36 | - { |
|
37 | - return array( |
|
38 | - 'groupByUrl' => array( |
|
39 | - 'group' => 't.uri', |
|
40 | - 'select' => 't.uri, COUNT(*) as id', |
|
41 | - 'order' => 't.id ASC', |
|
42 | - 'condition' => 't.event = "_trackPageView" AND t.created >= ' . strtotime("24 hours ago") |
|
43 | - ), |
|
44 | - ); |
|
45 | - } |
|
32 | + /** |
|
33 | + * Query Scoping |
|
34 | + */ |
|
35 | + public function scopes() |
|
36 | + { |
|
37 | + return array( |
|
38 | + 'groupByUrl' => array( |
|
39 | + 'group' => 't.uri', |
|
40 | + 'select' => 't.uri, COUNT(*) as id', |
|
41 | + 'order' => 't.id ASC', |
|
42 | + 'condition' => 't.event = "_trackPageView" AND t.created >= ' . strtotime("24 hours ago") |
|
43 | + ), |
|
44 | + ); |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @return string the associated database table name |
|
49 | - */ |
|
50 | - public function tableName() |
|
51 | - { |
|
52 | - return 'events'; |
|
53 | - } |
|
47 | + /** |
|
48 | + * @return string the associated database table name |
|
49 | + */ |
|
50 | + public function tableName() |
|
51 | + { |
|
52 | + return 'events'; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return array validation rules for model attributes. |
|
57 | - */ |
|
58 | - public function rules() |
|
59 | - { |
|
60 | - // NOTE: you should only define rules for those attributes that |
|
61 | - // will receive user inputs. |
|
62 | - return array( |
|
63 | - array('event, uri', 'required'), |
|
64 | - array('id', 'numerical', 'integerOnly'=>true), |
|
65 | - array('event, uri, ', 'length', 'max'=>255), |
|
66 | - array('event_data, created', 'safe'), |
|
67 | - array('id, content_id, page_title, event, event_data, uri, created', 'safe', 'on'=>'search'), |
|
68 | - ); |
|
69 | - } |
|
55 | + /** |
|
56 | + * @return array validation rules for model attributes. |
|
57 | + */ |
|
58 | + public function rules() |
|
59 | + { |
|
60 | + // NOTE: you should only define rules for those attributes that |
|
61 | + // will receive user inputs. |
|
62 | + return array( |
|
63 | + array('event, uri', 'required'), |
|
64 | + array('id', 'numerical', 'integerOnly'=>true), |
|
65 | + array('event, uri, ', 'length', 'max'=>255), |
|
66 | + array('event_data, created', 'safe'), |
|
67 | + array('id, content_id, page_title, event, event_data, uri, created', 'safe', 'on'=>'search'), |
|
68 | + ); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * @return array customized attribute labels (name=>label) |
|
73 | - */ |
|
74 | - public function attributeLabels() |
|
75 | - { |
|
76 | - return array( |
|
77 | - 'id' => 'ID', |
|
78 | - 'event' => 'Event', |
|
79 | - 'event_data' => 'Event Data', |
|
80 | - 'uri' => 'URI', |
|
81 | - 'content_id' => 'Content ID', |
|
82 | - 'created' => 'Created', |
|
83 | - ); |
|
84 | - } |
|
71 | + /** |
|
72 | + * @return array customized attribute labels (name=>label) |
|
73 | + */ |
|
74 | + public function attributeLabels() |
|
75 | + { |
|
76 | + return array( |
|
77 | + 'id' => 'ID', |
|
78 | + 'event' => 'Event', |
|
79 | + 'event_data' => 'Event Data', |
|
80 | + 'uri' => 'URI', |
|
81 | + 'content_id' => 'Content ID', |
|
82 | + 'created' => 'Created', |
|
83 | + ); |
|
84 | + } |
|
85 | 85 | |
86 | - public function beforeValidate() |
|
87 | - { |
|
88 | - $this->event_data = CJSON::encode($this->event_data); |
|
89 | - return parent::beforeValidate(); |
|
90 | - } |
|
86 | + public function beforeValidate() |
|
87 | + { |
|
88 | + $this->event_data = CJSON::encode($this->event_data); |
|
89 | + return parent::beforeValidate(); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Retrieves a list of models based on the current search/filter conditions. |
|
94 | - * |
|
95 | - * Typical usecase: |
|
96 | - * - Initialize the model fields with values from filter form. |
|
97 | - * - Execute this method to get CActiveDataProvider instance which will filter |
|
98 | - * models according to data in model fields. |
|
99 | - * - Pass data provider to CGridView, CListView or any similar widget. |
|
100 | - * |
|
101 | - * @return CActiveDataProvider the data provider that can return the models |
|
102 | - * based on the search/filter conditions. |
|
103 | - */ |
|
104 | - public function search() |
|
105 | - { |
|
106 | - // @todo Please modify the following code to remove attributes that should not be searched. |
|
92 | + /** |
|
93 | + * Retrieves a list of models based on the current search/filter conditions. |
|
94 | + * |
|
95 | + * Typical usecase: |
|
96 | + * - Initialize the model fields with values from filter form. |
|
97 | + * - Execute this method to get CActiveDataProvider instance which will filter |
|
98 | + * models according to data in model fields. |
|
99 | + * - Pass data provider to CGridView, CListView or any similar widget. |
|
100 | + * |
|
101 | + * @return CActiveDataProvider the data provider that can return the models |
|
102 | + * based on the search/filter conditions. |
|
103 | + */ |
|
104 | + public function search() |
|
105 | + { |
|
106 | + // @todo Please modify the following code to remove attributes that should not be searched. |
|
107 | 107 | |
108 | - $criteria=new CDbCriteria; |
|
108 | + $criteria=new CDbCriteria; |
|
109 | 109 | |
110 | - $criteria->compare('id',$this->id); |
|
111 | - $criteria->compare('event',$this->event,true); |
|
112 | - $criteria->compare('event_data',$this->event_data,true); |
|
113 | - $criteria->compare('uri',$this->uri,true); |
|
114 | - $criteria->compare('content_id',$this->content_id,true); |
|
115 | - $criteria->compare('created',$this->created,true); |
|
110 | + $criteria->compare('id',$this->id); |
|
111 | + $criteria->compare('event',$this->event,true); |
|
112 | + $criteria->compare('event_data',$this->event_data,true); |
|
113 | + $criteria->compare('uri',$this->uri,true); |
|
114 | + $criteria->compare('content_id',$this->content_id,true); |
|
115 | + $criteria->compare('created',$this->created,true); |
|
116 | 116 | |
117 | - return new CActiveDataProvider($this, array( |
|
118 | - 'criteria'=>$criteria, |
|
119 | - )); |
|
120 | - } |
|
117 | + return new CActiveDataProvider($this, array( |
|
118 | + 'criteria'=>$criteria, |
|
119 | + )); |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Returns the static model of the specified AR class. |
|
124 | - * Please note that you should have this exact method in all your CActiveRecord descendants! |
|
125 | - * @param string $className active record class name. |
|
126 | - * @return Events the static model class |
|
127 | - */ |
|
128 | - public static function model($className=__CLASS__) |
|
129 | - { |
|
130 | - return parent::model($className); |
|
131 | - } |
|
122 | + /** |
|
123 | + * Returns the static model of the specified AR class. |
|
124 | + * Please note that you should have this exact method in all your CActiveRecord descendants! |
|
125 | + * @param string $className active record class name. |
|
126 | + * @return Events the static model class |
|
127 | + */ |
|
128 | + public static function model($className=__CLASS__) |
|
129 | + { |
|
130 | + return parent::model($className); |
|
131 | + } |
|
132 | 132 | } |
@@ -16,14 +16,14 @@ discard block |
||
16 | 16 | * Adds the CTimestampBehavior to this class |
17 | 17 | * @return array |
18 | 18 | */ |
19 | - public function behaviors() |
|
19 | + public function behaviors () |
|
20 | 20 | { |
21 | 21 | return array( |
22 | 22 | 'CTimestampBehavior' => array( |
23 | 23 | 'class' => 'zii.behaviors.CTimestampBehavior', |
24 | 24 | 'createAttribute' => 'created', |
25 | 25 | 'updateAttribute' => 'created', |
26 | - 'timestampExpression' => time(), |
|
26 | + 'timestampExpression' => time (), |
|
27 | 27 | 'setUpdateOnCreate' => false |
28 | 28 | ) |
29 | 29 | ); |
@@ -32,14 +32,14 @@ discard block |
||
32 | 32 | /** |
33 | 33 | * Query Scoping |
34 | 34 | */ |
35 | - public function scopes() |
|
35 | + public function scopes () |
|
36 | 36 | { |
37 | 37 | return array( |
38 | 38 | 'groupByUrl' => array( |
39 | 39 | 'group' => 't.uri', |
40 | 40 | 'select' => 't.uri, COUNT(*) as id', |
41 | 41 | 'order' => 't.id ASC', |
42 | - 'condition' => 't.event = "_trackPageView" AND t.created >= ' . strtotime("24 hours ago") |
|
42 | + 'condition' => 't.event = "_trackPageView" AND t.created >= '.strtotime ("24 hours ago") |
|
43 | 43 | ), |
44 | 44 | ); |
45 | 45 | } |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | /** |
48 | 48 | * @return string the associated database table name |
49 | 49 | */ |
50 | - public function tableName() |
|
50 | + public function tableName () |
|
51 | 51 | { |
52 | 52 | return 'events'; |
53 | 53 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | /** |
56 | 56 | * @return array validation rules for model attributes. |
57 | 57 | */ |
58 | - public function rules() |
|
58 | + public function rules () |
|
59 | 59 | { |
60 | 60 | // NOTE: you should only define rules for those attributes that |
61 | 61 | // will receive user inputs. |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | /** |
72 | 72 | * @return array customized attribute labels (name=>label) |
73 | 73 | */ |
74 | - public function attributeLabels() |
|
74 | + public function attributeLabels () |
|
75 | 75 | { |
76 | 76 | return array( |
77 | 77 | 'id' => 'ID', |
@@ -83,10 +83,10 @@ discard block |
||
83 | 83 | ); |
84 | 84 | } |
85 | 85 | |
86 | - public function beforeValidate() |
|
86 | + public function beforeValidate () |
|
87 | 87 | { |
88 | - $this->event_data = CJSON::encode($this->event_data); |
|
89 | - return parent::beforeValidate(); |
|
88 | + $this->event_data = CJSON::encode ($this->event_data); |
|
89 | + return parent::beforeValidate (); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -101,20 +101,20 @@ discard block |
||
101 | 101 | * @return CActiveDataProvider the data provider that can return the models |
102 | 102 | * based on the search/filter conditions. |
103 | 103 | */ |
104 | - public function search() |
|
104 | + public function search () |
|
105 | 105 | { |
106 | 106 | // @todo Please modify the following code to remove attributes that should not be searched. |
107 | 107 | |
108 | - $criteria=new CDbCriteria; |
|
108 | + $criteria = new CDbCriteria; |
|
109 | 109 | |
110 | - $criteria->compare('id',$this->id); |
|
111 | - $criteria->compare('event',$this->event,true); |
|
112 | - $criteria->compare('event_data',$this->event_data,true); |
|
113 | - $criteria->compare('uri',$this->uri,true); |
|
114 | - $criteria->compare('content_id',$this->content_id,true); |
|
115 | - $criteria->compare('created',$this->created,true); |
|
110 | + $criteria->compare ('id', $this->id); |
|
111 | + $criteria->compare ('event', $this->event, true); |
|
112 | + $criteria->compare ('event_data', $this->event_data, true); |
|
113 | + $criteria->compare ('uri', $this->uri, true); |
|
114 | + $criteria->compare ('content_id', $this->content_id, true); |
|
115 | + $criteria->compare ('created', $this->created, true); |
|
116 | 116 | |
117 | - return new CActiveDataProvider($this, array( |
|
117 | + return new CActiveDataProvider ($this, array( |
|
118 | 118 | 'criteria'=>$criteria, |
119 | 119 | )); |
120 | 120 | } |
@@ -125,8 +125,8 @@ discard block |
||
125 | 125 | * @param string $className active record class name. |
126 | 126 | * @return Events the static model class |
127 | 127 | */ |
128 | - public static function model($className=__CLASS__) |
|
128 | + public static function model ($className = __CLASS__) |
|
129 | 129 | { |
130 | - return parent::model($className); |
|
130 | + return parent::model ($className); |
|
131 | 131 | } |
132 | 132 | } |
@@ -16,86 +16,86 @@ |
||
16 | 16 | */ |
17 | 17 | class UserMetadata extends CiiModel |
18 | 18 | { |
19 | - /** |
|
20 | - * Returns the static model of the specified AR class. |
|
21 | - * @param string $className active record class name. |
|
22 | - * @return UserMetadata the static model class |
|
23 | - */ |
|
24 | - public static function model($className=__CLASS__) |
|
25 | - { |
|
26 | - return parent::model($className); |
|
27 | - } |
|
19 | + /** |
|
20 | + * Returns the static model of the specified AR class. |
|
21 | + * @param string $className active record class name. |
|
22 | + * @return UserMetadata the static model class |
|
23 | + */ |
|
24 | + public static function model($className=__CLASS__) |
|
25 | + { |
|
26 | + return parent::model($className); |
|
27 | + } |
|
28 | 28 | |
29 | - /** |
|
30 | - * @return string the associated database table name |
|
31 | - */ |
|
32 | - public function tableName() |
|
33 | - { |
|
34 | - return 'user_metadata'; |
|
35 | - } |
|
29 | + /** |
|
30 | + * @return string the associated database table name |
|
31 | + */ |
|
32 | + public function tableName() |
|
33 | + { |
|
34 | + return 'user_metadata'; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @return array validation rules for model attributes. |
|
39 | - */ |
|
40 | - public function rules() |
|
41 | - { |
|
42 | - // NOTE: you should only define rules for those attributes that |
|
43 | - // will receive user inputs. |
|
44 | - return array( |
|
45 | - array('user_id, key, value', 'required'), |
|
46 | - array('user_id, entity_type', 'numerical', 'integerOnly'=>true), |
|
47 | - array('key', 'length', 'max'=>50), |
|
48 | - // The following rule is used by search(). |
|
49 | - array('id, user_id, key, value, entity_type, created, updated', 'safe', 'on'=>'search'), |
|
50 | - ); |
|
51 | - } |
|
37 | + /** |
|
38 | + * @return array validation rules for model attributes. |
|
39 | + */ |
|
40 | + public function rules() |
|
41 | + { |
|
42 | + // NOTE: you should only define rules for those attributes that |
|
43 | + // will receive user inputs. |
|
44 | + return array( |
|
45 | + array('user_id, key, value', 'required'), |
|
46 | + array('user_id, entity_type', 'numerical', 'integerOnly'=>true), |
|
47 | + array('key', 'length', 'max'=>50), |
|
48 | + // The following rule is used by search(). |
|
49 | + array('id, user_id, key, value, entity_type, created, updated', 'safe', 'on'=>'search'), |
|
50 | + ); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return array relational rules. |
|
55 | - */ |
|
56 | - public function relations() |
|
57 | - { |
|
58 | - // NOTE: you may need to adjust the relation name and the related |
|
59 | - // class name for the relations automatically generated below. |
|
60 | - return array( |
|
61 | - 'user' => array(self::BELONGS_TO, 'Users', 'user_id'), |
|
62 | - ); |
|
63 | - } |
|
53 | + /** |
|
54 | + * @return array relational rules. |
|
55 | + */ |
|
56 | + public function relations() |
|
57 | + { |
|
58 | + // NOTE: you may need to adjust the relation name and the related |
|
59 | + // class name for the relations automatically generated below. |
|
60 | + return array( |
|
61 | + 'user' => array(self::BELONGS_TO, 'Users', 'user_id'), |
|
62 | + ); |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return array customized attribute labels (name=>label) |
|
67 | - */ |
|
68 | - public function attributeLabels() |
|
69 | - { |
|
70 | - return array( |
|
71 | - 'id' => Yii::t('ciims.models.UserMetadata', 'ID'), |
|
72 | - 'user_id' => Yii::t('ciims.models.UserMetadata', 'User'), |
|
73 | - 'key' => Yii::t('ciims.models.UserMetadata', 'Key'), |
|
74 | - 'value' => Yii::t('ciims.models.UserMetadata', 'Value'), |
|
75 | - 'entity_type' => Yii::t('ciims.models.UserMetadata', 'Entity Type'), |
|
76 | - 'created' => Yii::t('ciims.models.UserMetadata', 'Created'), |
|
77 | - 'updated' => Yii::t('ciims.models.UserMetadata', 'Updated'), |
|
78 | - ); |
|
79 | - } |
|
65 | + /** |
|
66 | + * @return array customized attribute labels (name=>label) |
|
67 | + */ |
|
68 | + public function attributeLabels() |
|
69 | + { |
|
70 | + return array( |
|
71 | + 'id' => Yii::t('ciims.models.UserMetadata', 'ID'), |
|
72 | + 'user_id' => Yii::t('ciims.models.UserMetadata', 'User'), |
|
73 | + 'key' => Yii::t('ciims.models.UserMetadata', 'Key'), |
|
74 | + 'value' => Yii::t('ciims.models.UserMetadata', 'Value'), |
|
75 | + 'entity_type' => Yii::t('ciims.models.UserMetadata', 'Entity Type'), |
|
76 | + 'created' => Yii::t('ciims.models.UserMetadata', 'Created'), |
|
77 | + 'updated' => Yii::t('ciims.models.UserMetadata', 'Updated'), |
|
78 | + ); |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * Retrieves a list of models based on the current search/filter conditions. |
|
83 | - * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
|
84 | - */ |
|
85 | - public function search() |
|
86 | - { |
|
87 | - $criteria=new CDbCriteria; |
|
81 | + /** |
|
82 | + * Retrieves a list of models based on the current search/filter conditions. |
|
83 | + * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
|
84 | + */ |
|
85 | + public function search() |
|
86 | + { |
|
87 | + $criteria=new CDbCriteria; |
|
88 | 88 | |
89 | - $criteria->compare('id',$this->id); |
|
90 | - $criteria->compare('user_id',$this->user_id); |
|
91 | - $criteria->compare('key',$this->key,true); |
|
92 | - $criteria->compare('value',$this->value,true); |
|
93 | - $criteria->compare('entity_type',$this->entity_type,true); |
|
94 | - $criteria->compare('created',$this->created,true); |
|
95 | - $criteria->compare('updated',$this->updated,true); |
|
89 | + $criteria->compare('id',$this->id); |
|
90 | + $criteria->compare('user_id',$this->user_id); |
|
91 | + $criteria->compare('key',$this->key,true); |
|
92 | + $criteria->compare('value',$this->value,true); |
|
93 | + $criteria->compare('entity_type',$this->entity_type,true); |
|
94 | + $criteria->compare('created',$this->created,true); |
|
95 | + $criteria->compare('updated',$this->updated,true); |
|
96 | 96 | |
97 | - return new CActiveDataProvider($this, array( |
|
98 | - 'criteria'=>$criteria, |
|
99 | - )); |
|
100 | - } |
|
97 | + return new CActiveDataProvider($this, array( |
|
98 | + 'criteria'=>$criteria, |
|
99 | + )); |
|
100 | + } |
|
101 | 101 | } |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | * @param string $className active record class name. |
22 | 22 | * @return UserMetadata the static model class |
23 | 23 | */ |
24 | - public static function model($className=__CLASS__) |
|
24 | + public static function model ($className = __CLASS__) |
|
25 | 25 | { |
26 | - return parent::model($className); |
|
26 | + return parent::model ($className); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
30 | 30 | * @return string the associated database table name |
31 | 31 | */ |
32 | - public function tableName() |
|
32 | + public function tableName () |
|
33 | 33 | { |
34 | 34 | return 'user_metadata'; |
35 | 35 | } |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | /** |
38 | 38 | * @return array validation rules for model attributes. |
39 | 39 | */ |
40 | - public function rules() |
|
40 | + public function rules () |
|
41 | 41 | { |
42 | 42 | // NOTE: you should only define rules for those attributes that |
43 | 43 | // will receive user inputs. |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @return array relational rules. |
55 | 55 | */ |
56 | - public function relations() |
|
56 | + public function relations () |
|
57 | 57 | { |
58 | 58 | // NOTE: you may need to adjust the relation name and the related |
59 | 59 | // class name for the relations automatically generated below. |
@@ -65,16 +65,16 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * @return array customized attribute labels (name=>label) |
67 | 67 | */ |
68 | - public function attributeLabels() |
|
68 | + public function attributeLabels () |
|
69 | 69 | { |
70 | 70 | return array( |
71 | - 'id' => Yii::t('ciims.models.UserMetadata', 'ID'), |
|
72 | - 'user_id' => Yii::t('ciims.models.UserMetadata', 'User'), |
|
73 | - 'key' => Yii::t('ciims.models.UserMetadata', 'Key'), |
|
74 | - 'value' => Yii::t('ciims.models.UserMetadata', 'Value'), |
|
75 | - 'entity_type' => Yii::t('ciims.models.UserMetadata', 'Entity Type'), |
|
76 | - 'created' => Yii::t('ciims.models.UserMetadata', 'Created'), |
|
77 | - 'updated' => Yii::t('ciims.models.UserMetadata', 'Updated'), |
|
71 | + 'id' => Yii::t ('ciims.models.UserMetadata', 'ID'), |
|
72 | + 'user_id' => Yii::t ('ciims.models.UserMetadata', 'User'), |
|
73 | + 'key' => Yii::t ('ciims.models.UserMetadata', 'Key'), |
|
74 | + 'value' => Yii::t ('ciims.models.UserMetadata', 'Value'), |
|
75 | + 'entity_type' => Yii::t ('ciims.models.UserMetadata', 'Entity Type'), |
|
76 | + 'created' => Yii::t ('ciims.models.UserMetadata', 'Created'), |
|
77 | + 'updated' => Yii::t ('ciims.models.UserMetadata', 'Updated'), |
|
78 | 78 | ); |
79 | 79 | } |
80 | 80 | |
@@ -82,19 +82,19 @@ discard block |
||
82 | 82 | * Retrieves a list of models based on the current search/filter conditions. |
83 | 83 | * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
84 | 84 | */ |
85 | - public function search() |
|
85 | + public function search () |
|
86 | 86 | { |
87 | - $criteria=new CDbCriteria; |
|
87 | + $criteria = new CDbCriteria; |
|
88 | 88 | |
89 | - $criteria->compare('id',$this->id); |
|
90 | - $criteria->compare('user_id',$this->user_id); |
|
91 | - $criteria->compare('key',$this->key,true); |
|
92 | - $criteria->compare('value',$this->value,true); |
|
93 | - $criteria->compare('entity_type',$this->entity_type,true); |
|
94 | - $criteria->compare('created',$this->created,true); |
|
95 | - $criteria->compare('updated',$this->updated,true); |
|
89 | + $criteria->compare ('id', $this->id); |
|
90 | + $criteria->compare ('user_id', $this->user_id); |
|
91 | + $criteria->compare ('key', $this->key, true); |
|
92 | + $criteria->compare ('value', $this->value, true); |
|
93 | + $criteria->compare ('entity_type', $this->entity_type, true); |
|
94 | + $criteria->compare ('created', $this->created, true); |
|
95 | + $criteria->compare ('updated', $this->updated, true); |
|
96 | 96 | |
97 | - return new CActiveDataProvider($this, array( |
|
97 | + return new CActiveDataProvider ($this, array( |
|
98 | 98 | 'criteria'=>$criteria, |
99 | 99 | )); |
100 | 100 | } |
@@ -14,31 +14,31 @@ discard block |
||
14 | 14 | * The followings are the available model relations: |
15 | 15 | * @property Users $user |
16 | 16 | */ |
17 | -class UserMetadata extends CiiModel |
|
18 | -{ |
|
17 | +class UserMetadata extends CiiModel |
|
18 | +{ |
|
19 | 19 | /** |
20 | 20 | * Returns the static model of the specified AR class. |
21 | 21 | * @param string $className active record class name. |
22 | 22 | * @return UserMetadata the static model class |
23 | 23 | */ |
24 | - public static function model($className=__CLASS__) |
|
25 | - { |
|
24 | + public static function model($className=__CLASS__) |
|
25 | + { |
|
26 | 26 | return parent::model($className); |
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
30 | 30 | * @return string the associated database table name |
31 | 31 | */ |
32 | - public function tableName() |
|
33 | - { |
|
32 | + public function tableName() |
|
33 | + { |
|
34 | 34 | return 'user_metadata'; |
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
38 | 38 | * @return array validation rules for model attributes. |
39 | 39 | */ |
40 | - public function rules() |
|
41 | - { |
|
40 | + public function rules() |
|
41 | + { |
|
42 | 42 | // NOTE: you should only define rules for those attributes that |
43 | 43 | // will receive user inputs. |
44 | 44 | return array( |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @return array relational rules. |
55 | 55 | */ |
56 | - public function relations() |
|
57 | - { |
|
56 | + public function relations() |
|
57 | + { |
|
58 | 58 | // NOTE: you may need to adjust the relation name and the related |
59 | 59 | // class name for the relations automatically generated below. |
60 | 60 | return array( |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | /** |
66 | 66 | * @return array customized attribute labels (name=>label) |
67 | 67 | */ |
68 | - public function attributeLabels() |
|
69 | - { |
|
68 | + public function attributeLabels() |
|
69 | + { |
|
70 | 70 | return array( |
71 | 71 | 'id' => Yii::t('ciims.models.UserMetadata', 'ID'), |
72 | 72 | 'user_id' => Yii::t('ciims.models.UserMetadata', 'User'), |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | * Retrieves a list of models based on the current search/filter conditions. |
83 | 83 | * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
84 | 84 | */ |
85 | - public function search() |
|
86 | - { |
|
85 | + public function search() |
|
86 | + { |
|
87 | 87 | $criteria=new CDbCriteria; |
88 | 88 | |
89 | 89 | $criteria->compare('id',$this->id); |
@@ -15,184 +15,184 @@ |
||
15 | 15 | class UserRoles extends CiiModel |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * Returns a key => value array of userRole => bitwise permissions |
|
20 | - * |
|
21 | - * Permissions apply per role, with the exception of publisher and admin, whose permissions apply to everything |
|
22 | - * Note that these permissions only apply to content, and management of CiiMS' settings |
|
23 | - * |
|
24 | - * -------------------------------------------------------------------------------- |
|
25 | - * | role/id | manage | publish other | publish | delete | update | create | read | |
|
26 | - * -------------------------------------------------------------------------------- |
|
27 | - * | user/1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | |
|
28 | - * -------------------------------------------------------------------------------- |
|
29 | - * | clb/5 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | |
|
30 | - * -------------------------------------------------------------------------------- |
|
31 | - * | auth/7 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | |
|
32 | - * -------------------------------------------------------------------------------- |
|
33 | - * | pub/8 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | |
|
34 | - * -------------------------------------------------------------------------------- |
|
35 | - * | admin/9 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |
|
36 | - * -------------------------------------------------------------------------------- |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public function getPermissions() |
|
40 | - { |
|
41 | - return array( |
|
42 | - '1' => 1, // User |
|
43 | - '2' => 0, // Pending |
|
44 | - '3' => 0, // Suspended |
|
45 | - '5' => 7, // Collaborator |
|
46 | - '7' => 16, // Author |
|
47 | - '8' => 32, // Publisher |
|
48 | - '9' => 64 // Admin |
|
49 | - ); |
|
50 | - } |
|
51 | - |
|
52 | - public function isA($roleName, $role=false) |
|
53 | - { |
|
54 | - if ($role === false) |
|
55 | - $role = Yii::app()->user->role; |
|
56 | - |
|
57 | - $roleName = strtolower($roleName); |
|
58 | - |
|
59 | - switch ($roleName) |
|
60 | - { |
|
61 | - case 'user': |
|
62 | - return $role <= 1; |
|
63 | - case 'collaborator': |
|
64 | - return $role == 5; |
|
65 | - case 'author': |
|
66 | - return $role == 7; |
|
67 | - case 'publisher': |
|
68 | - return $role == 8; |
|
69 | - case 'admin': |
|
70 | - return $role == 9; |
|
71 | - } |
|
72 | - |
|
73 | - return false; |
|
74 | - } |
|
75 | - |
|
76 | - /** |
|
77 | - * Returns the bitwise permissions associated to each activity |
|
78 | - * @return array |
|
79 | - */ |
|
80 | - public function getActivities() |
|
81 | - { |
|
82 | - return array( |
|
83 | - 'read' => 1, |
|
84 | - 'comment' => 1, |
|
85 | - 'create' => 3, |
|
86 | - 'update' => 4, |
|
87 | - 'modify' => 7, |
|
88 | - 'delete' => 8, |
|
89 | - 'publish' => 16, |
|
90 | - 'publishOther' => 32, |
|
91 | - 'manage' => 64 |
|
92 | - ); |
|
93 | - } |
|
94 | - |
|
95 | - /** |
|
96 | - * Determines if a user with a given role has permission to perform a given activity |
|
97 | - * @param string $permission The permissions we want to lookup |
|
98 | - * @param int $role The user role. If not provided, will be applied to the current user |
|
99 | - * @return boolean |
|
100 | - */ |
|
101 | - public function hasPermission($permission, $role=NULL) |
|
102 | - { |
|
103 | - if ($role === NULL) |
|
104 | - { |
|
105 | - if (isset($this->id)) |
|
106 | - $role = $this->id; |
|
107 | - else if (Yii::app()->user->isGuest) |
|
108 | - $role = 1; |
|
109 | - else |
|
110 | - $role = Yii::app()->user->role; |
|
111 | - } |
|
112 | - |
|
113 | - $permissions = $this->getPermissions(); |
|
114 | - $activities = $this->getActivities(); |
|
115 | - |
|
116 | - // If the permission doesn't exist for that role, return false; |
|
117 | - if (!isset($permissions[$role])) |
|
118 | - return false; |
|
119 | - |
|
120 | - return $activities[$permission] <= $permissions[$role]; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Returns the static model of the specified AR class. |
|
125 | - * @param string $className active record class name. |
|
126 | - * @return UserRoles the static model class |
|
127 | - */ |
|
128 | - public static function model($className=__CLASS__) |
|
129 | - { |
|
130 | - return parent::model($className); |
|
131 | - } |
|
132 | - |
|
133 | - /** |
|
134 | - * @return string the associated database table name |
|
135 | - */ |
|
136 | - public function tableName() |
|
137 | - { |
|
138 | - return 'user_roles'; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @return array validation rules for model attributes. |
|
143 | - */ |
|
144 | - public function rules() |
|
145 | - { |
|
146 | - // NOTE: you should only define rules for those attributes that |
|
147 | - // will receive user inputs. |
|
148 | - return array( |
|
149 | - array('name', 'required'), |
|
150 | - array('name', 'length', 'max'=>100), |
|
151 | - // The following rule is used by search(). |
|
152 | - array('id, name, created, updated', 'safe', 'on'=>'search'), |
|
153 | - ); |
|
154 | - } |
|
155 | - |
|
156 | - /** |
|
157 | - * @return array relational rules. |
|
158 | - */ |
|
159 | - public function relations() |
|
160 | - { |
|
161 | - // NOTE: you may need to adjust the relation name and the related |
|
162 | - // class name for the relations automatically generated below. |
|
163 | - return array( |
|
164 | - 'users' => array(self::HAS_MANY, 'Users', 'user_role'), |
|
165 | - ); |
|
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * @return array customized attribute labels (name=>label) |
|
170 | - */ |
|
171 | - public function attributeLabels() |
|
172 | - { |
|
173 | - return array( |
|
174 | - 'id' => Yii::t('ciims.models.UserRoles', 'ID'), |
|
175 | - 'name' => Yii::t('ciims.models.UserRoles', 'Name'), |
|
176 | - 'created' => Yii::t('ciims.models.UserRoles', 'Created'), |
|
177 | - 'updated' => Yii::t('ciims.models.UserRoles', 'Updated'), |
|
178 | - ); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * Retrieves a list of models based on the current search/filter conditions. |
|
183 | - * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
|
184 | - */ |
|
185 | - public function search() |
|
186 | - { |
|
187 | - $criteria=new CDbCriteria; |
|
188 | - |
|
189 | - $criteria->compare('id',$this->id); |
|
190 | - $criteria->compare('name',$this->name,true); |
|
191 | - $criteria->compare('created',$this->created,true); |
|
192 | - $criteria->compare('updated',$this->updated,true); |
|
193 | - |
|
194 | - return new CActiveDataProvider($this, array( |
|
195 | - 'criteria'=>$criteria, |
|
196 | - )); |
|
197 | - } |
|
18 | + /** |
|
19 | + * Returns a key => value array of userRole => bitwise permissions |
|
20 | + * |
|
21 | + * Permissions apply per role, with the exception of publisher and admin, whose permissions apply to everything |
|
22 | + * Note that these permissions only apply to content, and management of CiiMS' settings |
|
23 | + * |
|
24 | + * -------------------------------------------------------------------------------- |
|
25 | + * | role/id | manage | publish other | publish | delete | update | create | read | |
|
26 | + * -------------------------------------------------------------------------------- |
|
27 | + * | user/1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | |
|
28 | + * -------------------------------------------------------------------------------- |
|
29 | + * | clb/5 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | |
|
30 | + * -------------------------------------------------------------------------------- |
|
31 | + * | auth/7 | 0 | 0 | 1 | 1 | 1 | 1 | 1 | |
|
32 | + * -------------------------------------------------------------------------------- |
|
33 | + * | pub/8 | 0 | 1 | 1 | 1 | 1 | 1 | 1 | |
|
34 | + * -------------------------------------------------------------------------------- |
|
35 | + * | admin/9 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |
|
36 | + * -------------------------------------------------------------------------------- |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public function getPermissions() |
|
40 | + { |
|
41 | + return array( |
|
42 | + '1' => 1, // User |
|
43 | + '2' => 0, // Pending |
|
44 | + '3' => 0, // Suspended |
|
45 | + '5' => 7, // Collaborator |
|
46 | + '7' => 16, // Author |
|
47 | + '8' => 32, // Publisher |
|
48 | + '9' => 64 // Admin |
|
49 | + ); |
|
50 | + } |
|
51 | + |
|
52 | + public function isA($roleName, $role=false) |
|
53 | + { |
|
54 | + if ($role === false) |
|
55 | + $role = Yii::app()->user->role; |
|
56 | + |
|
57 | + $roleName = strtolower($roleName); |
|
58 | + |
|
59 | + switch ($roleName) |
|
60 | + { |
|
61 | + case 'user': |
|
62 | + return $role <= 1; |
|
63 | + case 'collaborator': |
|
64 | + return $role == 5; |
|
65 | + case 'author': |
|
66 | + return $role == 7; |
|
67 | + case 'publisher': |
|
68 | + return $role == 8; |
|
69 | + case 'admin': |
|
70 | + return $role == 9; |
|
71 | + } |
|
72 | + |
|
73 | + return false; |
|
74 | + } |
|
75 | + |
|
76 | + /** |
|
77 | + * Returns the bitwise permissions associated to each activity |
|
78 | + * @return array |
|
79 | + */ |
|
80 | + public function getActivities() |
|
81 | + { |
|
82 | + return array( |
|
83 | + 'read' => 1, |
|
84 | + 'comment' => 1, |
|
85 | + 'create' => 3, |
|
86 | + 'update' => 4, |
|
87 | + 'modify' => 7, |
|
88 | + 'delete' => 8, |
|
89 | + 'publish' => 16, |
|
90 | + 'publishOther' => 32, |
|
91 | + 'manage' => 64 |
|
92 | + ); |
|
93 | + } |
|
94 | + |
|
95 | + /** |
|
96 | + * Determines if a user with a given role has permission to perform a given activity |
|
97 | + * @param string $permission The permissions we want to lookup |
|
98 | + * @param int $role The user role. If not provided, will be applied to the current user |
|
99 | + * @return boolean |
|
100 | + */ |
|
101 | + public function hasPermission($permission, $role=NULL) |
|
102 | + { |
|
103 | + if ($role === NULL) |
|
104 | + { |
|
105 | + if (isset($this->id)) |
|
106 | + $role = $this->id; |
|
107 | + else if (Yii::app()->user->isGuest) |
|
108 | + $role = 1; |
|
109 | + else |
|
110 | + $role = Yii::app()->user->role; |
|
111 | + } |
|
112 | + |
|
113 | + $permissions = $this->getPermissions(); |
|
114 | + $activities = $this->getActivities(); |
|
115 | + |
|
116 | + // If the permission doesn't exist for that role, return false; |
|
117 | + if (!isset($permissions[$role])) |
|
118 | + return false; |
|
119 | + |
|
120 | + return $activities[$permission] <= $permissions[$role]; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Returns the static model of the specified AR class. |
|
125 | + * @param string $className active record class name. |
|
126 | + * @return UserRoles the static model class |
|
127 | + */ |
|
128 | + public static function model($className=__CLASS__) |
|
129 | + { |
|
130 | + return parent::model($className); |
|
131 | + } |
|
132 | + |
|
133 | + /** |
|
134 | + * @return string the associated database table name |
|
135 | + */ |
|
136 | + public function tableName() |
|
137 | + { |
|
138 | + return 'user_roles'; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @return array validation rules for model attributes. |
|
143 | + */ |
|
144 | + public function rules() |
|
145 | + { |
|
146 | + // NOTE: you should only define rules for those attributes that |
|
147 | + // will receive user inputs. |
|
148 | + return array( |
|
149 | + array('name', 'required'), |
|
150 | + array('name', 'length', 'max'=>100), |
|
151 | + // The following rule is used by search(). |
|
152 | + array('id, name, created, updated', 'safe', 'on'=>'search'), |
|
153 | + ); |
|
154 | + } |
|
155 | + |
|
156 | + /** |
|
157 | + * @return array relational rules. |
|
158 | + */ |
|
159 | + public function relations() |
|
160 | + { |
|
161 | + // NOTE: you may need to adjust the relation name and the related |
|
162 | + // class name for the relations automatically generated below. |
|
163 | + return array( |
|
164 | + 'users' => array(self::HAS_MANY, 'Users', 'user_role'), |
|
165 | + ); |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * @return array customized attribute labels (name=>label) |
|
170 | + */ |
|
171 | + public function attributeLabels() |
|
172 | + { |
|
173 | + return array( |
|
174 | + 'id' => Yii::t('ciims.models.UserRoles', 'ID'), |
|
175 | + 'name' => Yii::t('ciims.models.UserRoles', 'Name'), |
|
176 | + 'created' => Yii::t('ciims.models.UserRoles', 'Created'), |
|
177 | + 'updated' => Yii::t('ciims.models.UserRoles', 'Updated'), |
|
178 | + ); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * Retrieves a list of models based on the current search/filter conditions. |
|
183 | + * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
|
184 | + */ |
|
185 | + public function search() |
|
186 | + { |
|
187 | + $criteria=new CDbCriteria; |
|
188 | + |
|
189 | + $criteria->compare('id',$this->id); |
|
190 | + $criteria->compare('name',$this->name,true); |
|
191 | + $criteria->compare('created',$this->created,true); |
|
192 | + $criteria->compare('updated',$this->updated,true); |
|
193 | + |
|
194 | + return new CActiveDataProvider($this, array( |
|
195 | + 'criteria'=>$criteria, |
|
196 | + )); |
|
197 | + } |
|
198 | 198 | } |
@@ -36,25 +36,25 @@ discard block |
||
36 | 36 | * -------------------------------------------------------------------------------- |
37 | 37 | * @return array |
38 | 38 | */ |
39 | - public function getPermissions() |
|
39 | + public function getPermissions () |
|
40 | 40 | { |
41 | 41 | return array( |
42 | - '1' => 1, // User |
|
43 | - '2' => 0, // Pending |
|
44 | - '3' => 0, // Suspended |
|
45 | - '5' => 7, // Collaborator |
|
46 | - '7' => 16, // Author |
|
47 | - '8' => 32, // Publisher |
|
42 | + '1' => 1, // User |
|
43 | + '2' => 0, // Pending |
|
44 | + '3' => 0, // Suspended |
|
45 | + '5' => 7, // Collaborator |
|
46 | + '7' => 16, // Author |
|
47 | + '8' => 32, // Publisher |
|
48 | 48 | '9' => 64 // Admin |
49 | 49 | ); |
50 | 50 | } |
51 | 51 | |
52 | - public function isA($roleName, $role=false) |
|
52 | + public function isA ($roleName, $role = false) |
|
53 | 53 | { |
54 | 54 | if ($role === false) |
55 | - $role = Yii::app()->user->role; |
|
55 | + $role = Yii::app ()->user->role; |
|
56 | 56 | |
57 | - $roleName = strtolower($roleName); |
|
57 | + $roleName = strtolower ($roleName); |
|
58 | 58 | |
59 | 59 | switch ($roleName) |
60 | 60 | { |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * Returns the bitwise permissions associated to each activity |
78 | 78 | * @return array |
79 | 79 | */ |
80 | - public function getActivities() |
|
80 | + public function getActivities () |
|
81 | 81 | { |
82 | 82 | return array( |
83 | 83 | 'read' => 1, |
@@ -98,20 +98,20 @@ discard block |
||
98 | 98 | * @param int $role The user role. If not provided, will be applied to the current user |
99 | 99 | * @return boolean |
100 | 100 | */ |
101 | - public function hasPermission($permission, $role=NULL) |
|
101 | + public function hasPermission ($permission, $role = NULL) |
|
102 | 102 | { |
103 | 103 | if ($role === NULL) |
104 | 104 | { |
105 | 105 | if (isset($this->id)) |
106 | 106 | $role = $this->id; |
107 | - else if (Yii::app()->user->isGuest) |
|
107 | + else if (Yii::app ()->user->isGuest) |
|
108 | 108 | $role = 1; |
109 | 109 | else |
110 | - $role = Yii::app()->user->role; |
|
110 | + $role = Yii::app ()->user->role; |
|
111 | 111 | } |
112 | 112 | |
113 | - $permissions = $this->getPermissions(); |
|
114 | - $activities = $this->getActivities(); |
|
113 | + $permissions = $this->getPermissions (); |
|
114 | + $activities = $this->getActivities (); |
|
115 | 115 | |
116 | 116 | // If the permission doesn't exist for that role, return false; |
117 | 117 | if (!isset($permissions[$role])) |
@@ -125,15 +125,15 @@ discard block |
||
125 | 125 | * @param string $className active record class name. |
126 | 126 | * @return UserRoles the static model class |
127 | 127 | */ |
128 | - public static function model($className=__CLASS__) |
|
128 | + public static function model ($className = __CLASS__) |
|
129 | 129 | { |
130 | - return parent::model($className); |
|
130 | + return parent::model ($className); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | /** |
134 | 134 | * @return string the associated database table name |
135 | 135 | */ |
136 | - public function tableName() |
|
136 | + public function tableName () |
|
137 | 137 | { |
138 | 138 | return 'user_roles'; |
139 | 139 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | /** |
142 | 142 | * @return array validation rules for model attributes. |
143 | 143 | */ |
144 | - public function rules() |
|
144 | + public function rules () |
|
145 | 145 | { |
146 | 146 | // NOTE: you should only define rules for those attributes that |
147 | 147 | // will receive user inputs. |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | /** |
157 | 157 | * @return array relational rules. |
158 | 158 | */ |
159 | - public function relations() |
|
159 | + public function relations () |
|
160 | 160 | { |
161 | 161 | // NOTE: you may need to adjust the relation name and the related |
162 | 162 | // class name for the relations automatically generated below. |
@@ -168,13 +168,13 @@ discard block |
||
168 | 168 | /** |
169 | 169 | * @return array customized attribute labels (name=>label) |
170 | 170 | */ |
171 | - public function attributeLabels() |
|
171 | + public function attributeLabels () |
|
172 | 172 | { |
173 | 173 | return array( |
174 | - 'id' => Yii::t('ciims.models.UserRoles', 'ID'), |
|
175 | - 'name' => Yii::t('ciims.models.UserRoles', 'Name'), |
|
176 | - 'created' => Yii::t('ciims.models.UserRoles', 'Created'), |
|
177 | - 'updated' => Yii::t('ciims.models.UserRoles', 'Updated'), |
|
174 | + 'id' => Yii::t ('ciims.models.UserRoles', 'ID'), |
|
175 | + 'name' => Yii::t ('ciims.models.UserRoles', 'Name'), |
|
176 | + 'created' => Yii::t ('ciims.models.UserRoles', 'Created'), |
|
177 | + 'updated' => Yii::t ('ciims.models.UserRoles', 'Updated'), |
|
178 | 178 | ); |
179 | 179 | } |
180 | 180 | |
@@ -182,16 +182,16 @@ discard block |
||
182 | 182 | * Retrieves a list of models based on the current search/filter conditions. |
183 | 183 | * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
184 | 184 | */ |
185 | - public function search() |
|
185 | + public function search () |
|
186 | 186 | { |
187 | - $criteria=new CDbCriteria; |
|
187 | + $criteria = new CDbCriteria; |
|
188 | 188 | |
189 | - $criteria->compare('id',$this->id); |
|
190 | - $criteria->compare('name',$this->name,true); |
|
191 | - $criteria->compare('created',$this->created,true); |
|
192 | - $criteria->compare('updated',$this->updated,true); |
|
189 | + $criteria->compare ('id', $this->id); |
|
190 | + $criteria->compare ('name', $this->name, true); |
|
191 | + $criteria->compare ('created', $this->created, true); |
|
192 | + $criteria->compare ('updated', $this->updated, true); |
|
193 | 193 | |
194 | - return new CActiveDataProvider($this, array( |
|
194 | + return new CActiveDataProvider ($this, array( |
|
195 | 195 | 'criteria'=>$criteria, |
196 | 196 | )); |
197 | 197 | } |
@@ -12,8 +12,8 @@ discard block |
||
12 | 12 | * The followings are the available model relations: |
13 | 13 | * @property Users[] $users |
14 | 14 | */ |
15 | -class UserRoles extends CiiModel |
|
16 | -{ |
|
15 | +class UserRoles extends CiiModel |
|
16 | +{ |
|
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Returns a key => value array of userRole => bitwise permissions |
@@ -36,8 +36,8 @@ discard block |
||
36 | 36 | * -------------------------------------------------------------------------------- |
37 | 37 | * @return array |
38 | 38 | */ |
39 | - public function getPermissions() |
|
40 | - { |
|
39 | + public function getPermissions() |
|
40 | + { |
|
41 | 41 | return array( |
42 | 42 | '1' => 1, // User |
43 | 43 | '2' => 0, // Pending |
@@ -49,10 +49,11 @@ discard block |
||
49 | 49 | ); |
50 | 50 | } |
51 | 51 | |
52 | - public function isA($roleName, $role=false) |
|
53 | - { |
|
54 | - if ($role === false) |
|
55 | - $role = Yii::app()->user->role; |
|
52 | + public function isA($roleName, $role=false) |
|
53 | + { |
|
54 | + if ($role === false) { |
|
55 | + $role = Yii::app()->user->role; |
|
56 | + } |
|
56 | 57 | |
57 | 58 | $roleName = strtolower($roleName); |
58 | 59 | |
@@ -77,8 +78,8 @@ discard block |
||
77 | 78 | * Returns the bitwise permissions associated to each activity |
78 | 79 | * @return array |
79 | 80 | */ |
80 | - public function getActivities() |
|
81 | - { |
|
81 | + public function getActivities() |
|
82 | + { |
|
82 | 83 | return array( |
83 | 84 | 'read' => 1, |
84 | 85 | 'comment' => 1, |
@@ -98,24 +99,26 @@ discard block |
||
98 | 99 | * @param int $role The user role. If not provided, will be applied to the current user |
99 | 100 | * @return boolean |
100 | 101 | */ |
101 | - public function hasPermission($permission, $role=NULL) |
|
102 | - { |
|
102 | + public function hasPermission($permission, $role=NULL) |
|
103 | + { |
|
103 | 104 | if ($role === NULL) |
104 | 105 | { |
105 | - if (isset($this->id)) |
|
106 | - $role = $this->id; |
|
107 | - else if (Yii::app()->user->isGuest) |
|
108 | - $role = 1; |
|
109 | - else |
|
110 | - $role = Yii::app()->user->role; |
|
106 | + if (isset($this->id)) { |
|
107 | + $role = $this->id; |
|
108 | + } else if (Yii::app()->user->isGuest) { |
|
109 | + $role = 1; |
|
110 | + } else { |
|
111 | + $role = Yii::app()->user->role; |
|
112 | + } |
|
111 | 113 | } |
112 | 114 | |
113 | 115 | $permissions = $this->getPermissions(); |
114 | 116 | $activities = $this->getActivities(); |
115 | 117 | |
116 | 118 | // If the permission doesn't exist for that role, return false; |
117 | - if (!isset($permissions[$role])) |
|
118 | - return false; |
|
119 | + if (!isset($permissions[$role])) { |
|
120 | + return false; |
|
121 | + } |
|
119 | 122 | |
120 | 123 | return $activities[$permission] <= $permissions[$role]; |
121 | 124 | } |
@@ -125,24 +128,24 @@ discard block |
||
125 | 128 | * @param string $className active record class name. |
126 | 129 | * @return UserRoles the static model class |
127 | 130 | */ |
128 | - public static function model($className=__CLASS__) |
|
129 | - { |
|
131 | + public static function model($className=__CLASS__) |
|
132 | + { |
|
130 | 133 | return parent::model($className); |
131 | 134 | } |
132 | 135 | |
133 | 136 | /** |
134 | 137 | * @return string the associated database table name |
135 | 138 | */ |
136 | - public function tableName() |
|
137 | - { |
|
139 | + public function tableName() |
|
140 | + { |
|
138 | 141 | return 'user_roles'; |
139 | 142 | } |
140 | 143 | |
141 | 144 | /** |
142 | 145 | * @return array validation rules for model attributes. |
143 | 146 | */ |
144 | - public function rules() |
|
145 | - { |
|
147 | + public function rules() |
|
148 | + { |
|
146 | 149 | // NOTE: you should only define rules for those attributes that |
147 | 150 | // will receive user inputs. |
148 | 151 | return array( |
@@ -156,8 +159,8 @@ discard block |
||
156 | 159 | /** |
157 | 160 | * @return array relational rules. |
158 | 161 | */ |
159 | - public function relations() |
|
160 | - { |
|
162 | + public function relations() |
|
163 | + { |
|
161 | 164 | // NOTE: you may need to adjust the relation name and the related |
162 | 165 | // class name for the relations automatically generated below. |
163 | 166 | return array( |
@@ -168,8 +171,8 @@ discard block |
||
168 | 171 | /** |
169 | 172 | * @return array customized attribute labels (name=>label) |
170 | 173 | */ |
171 | - public function attributeLabels() |
|
172 | - { |
|
174 | + public function attributeLabels() |
|
175 | + { |
|
173 | 176 | return array( |
174 | 177 | 'id' => Yii::t('ciims.models.UserRoles', 'ID'), |
175 | 178 | 'name' => Yii::t('ciims.models.UserRoles', 'Name'), |
@@ -182,8 +185,8 @@ discard block |
||
182 | 185 | * Retrieves a list of models based on the current search/filter conditions. |
183 | 186 | * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
184 | 187 | */ |
185 | - public function search() |
|
186 | - { |
|
188 | + public function search() |
|
189 | + { |
|
187 | 190 | $criteria=new CDbCriteria; |
188 | 191 | |
189 | 192 | $criteria->compare('id',$this->id); |
@@ -25,303 +25,303 @@ |
||
25 | 25 | */ |
26 | 26 | class Users extends CiiModel |
27 | 27 | { |
28 | - const INACTIVE = 0; |
|
29 | - const ACTIVE = 1; |
|
30 | - const BANNED = 2; |
|
31 | - const PENDING_INVITATION = 3; |
|
32 | - |
|
33 | - public $pageSize = 15; |
|
34 | - |
|
35 | - /** |
|
36 | - * Returns the static model of the specified AR class. |
|
37 | - * @param string $className active record class name. |
|
38 | - * @return Users the static model class |
|
39 | - */ |
|
40 | - public static function model($className=__CLASS__) |
|
41 | - { |
|
42 | - return parent::model($className); |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @return string the associated database table name |
|
47 | - */ |
|
48 | - public function tableName() |
|
49 | - { |
|
50 | - return 'users'; |
|
51 | - } |
|
52 | - |
|
53 | - /** |
|
54 | - * @return array validation rules for model attributes. |
|
55 | - */ |
|
56 | - public function rules() |
|
57 | - { |
|
58 | - // NOTE: you should only define rules for those attributes that |
|
59 | - // will receive user inputs. |
|
60 | - return array( |
|
61 | - array('email, password, username, user_role, status', 'required'), |
|
62 | - array('email', 'email'), |
|
63 | - array('user_role, status', 'numerical', 'integerOnly'=>true), |
|
64 | - array('email, username', 'length', 'max'=>255), |
|
65 | - array('password', 'length', 'max'=>64), |
|
66 | - // The following rule is used by search(). |
|
67 | - array('id, email, password, username, about, user_role, status, created, updated', 'safe', 'on'=>'search'), |
|
68 | - ); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return array relational rules. |
|
73 | - */ |
|
74 | - public function relations() |
|
75 | - { |
|
76 | - // NOTE: you may need to adjust the relation name and the related |
|
77 | - // class name for the relations automatically generated below. |
|
78 | - return array( |
|
79 | - 'comments' => array(self::HAS_MANY, 'Comments', 'user_id'), |
|
80 | - 'content' => array(self::HAS_MANY, 'Content', 'author_id'), |
|
81 | - 'metadata' => array(self::HAS_MANY, 'UserMetadata', 'user_id', 'condition' => '`metadata`.`entity_type` = 0'), |
|
82 | - 'role' => array(self::BELONGS_TO, 'UserRoles', 'user_role'), |
|
83 | - ); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @return array customized attribute labels (name=>label) |
|
88 | - */ |
|
89 | - public function attributeLabels() |
|
90 | - { |
|
91 | - return array( |
|
92 | - 'id' => Yii::t('ciims.models.Users', 'ID'), |
|
93 | - 'email' => Yii::t('ciims.models.Users', 'Email'), |
|
94 | - 'password' => Yii::t('ciims.models.Users', 'Password'), |
|
95 | - 'username' => Yii::t('ciims.models.Users', 'User Name'), |
|
96 | - 'user_role' => Yii::t('ciims.models.Users', 'User Role'), |
|
97 | - 'status' => Yii::t('ciims.models.Users', 'Active'), |
|
98 | - 'created' => Yii::t('ciims.models.Users', 'Created'), |
|
99 | - 'updated' => Yii::t('ciims.models.Users', 'Updated'), |
|
100 | - ); |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Gets the first and last name instead of the username |
|
105 | - */ |
|
106 | - public function getName() |
|
107 | - { |
|
108 | - return $this->username; |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Retrieves the username |
|
113 | - */ |
|
114 | - public function getUsername() |
|
115 | - { |
|
116 | - return $this->username; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Retrieves the username |
|
121 | - * @todo This is technical debt. At some point this should be completely depricated |
|
122 | - */ |
|
123 | - public function getDisplayName() |
|
124 | - { |
|
125 | - Yii::log('Users::displayName has been deprecated. Use Users::username moving forward', 'warning', 'models.users'); |
|
126 | - return $this->getUsername(); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Retrieves the reputation for a given user |
|
131 | - * @param boolean $model Whether an instance of UserMetadata should be returned or not |
|
132 | - * @return mixed |
|
133 | - */ |
|
134 | - public function getReputation($model=false) |
|
135 | - { |
|
136 | - $reputation = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'reputation'), array('value' => 150)); |
|
137 | - |
|
138 | - if ($model === true) |
|
139 | - return $reputation; |
|
140 | - |
|
141 | - return $reputation->value; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Updates a user's reputation |
|
146 | - * @return boolean |
|
147 | - */ |
|
148 | - public function setReputation($rep = 10) |
|
149 | - { |
|
150 | - $reputation = $this->getReputation(true); |
|
151 | - $reputation->value += $rep; |
|
152 | - return $reputation->save(); |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * Retrieves all comments that the user has flagged |
|
157 | - * @param boolean $model Whether an instance of UserMetadata should be returned or not |
|
158 | - * @return mixed |
|
159 | - */ |
|
160 | - public function getFlaggedComments($model=false) |
|
161 | - { |
|
162 | - $flags = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'flaggedComments'), array('value' => CJSON::encode(array()))); |
|
28 | + const INACTIVE = 0; |
|
29 | + const ACTIVE = 1; |
|
30 | + const BANNED = 2; |
|
31 | + const PENDING_INVITATION = 3; |
|
32 | + |
|
33 | + public $pageSize = 15; |
|
34 | + |
|
35 | + /** |
|
36 | + * Returns the static model of the specified AR class. |
|
37 | + * @param string $className active record class name. |
|
38 | + * @return Users the static model class |
|
39 | + */ |
|
40 | + public static function model($className=__CLASS__) |
|
41 | + { |
|
42 | + return parent::model($className); |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @return string the associated database table name |
|
47 | + */ |
|
48 | + public function tableName() |
|
49 | + { |
|
50 | + return 'users'; |
|
51 | + } |
|
52 | + |
|
53 | + /** |
|
54 | + * @return array validation rules for model attributes. |
|
55 | + */ |
|
56 | + public function rules() |
|
57 | + { |
|
58 | + // NOTE: you should only define rules for those attributes that |
|
59 | + // will receive user inputs. |
|
60 | + return array( |
|
61 | + array('email, password, username, user_role, status', 'required'), |
|
62 | + array('email', 'email'), |
|
63 | + array('user_role, status', 'numerical', 'integerOnly'=>true), |
|
64 | + array('email, username', 'length', 'max'=>255), |
|
65 | + array('password', 'length', 'max'=>64), |
|
66 | + // The following rule is used by search(). |
|
67 | + array('id, email, password, username, about, user_role, status, created, updated', 'safe', 'on'=>'search'), |
|
68 | + ); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return array relational rules. |
|
73 | + */ |
|
74 | + public function relations() |
|
75 | + { |
|
76 | + // NOTE: you may need to adjust the relation name and the related |
|
77 | + // class name for the relations automatically generated below. |
|
78 | + return array( |
|
79 | + 'comments' => array(self::HAS_MANY, 'Comments', 'user_id'), |
|
80 | + 'content' => array(self::HAS_MANY, 'Content', 'author_id'), |
|
81 | + 'metadata' => array(self::HAS_MANY, 'UserMetadata', 'user_id', 'condition' => '`metadata`.`entity_type` = 0'), |
|
82 | + 'role' => array(self::BELONGS_TO, 'UserRoles', 'user_role'), |
|
83 | + ); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @return array customized attribute labels (name=>label) |
|
88 | + */ |
|
89 | + public function attributeLabels() |
|
90 | + { |
|
91 | + return array( |
|
92 | + 'id' => Yii::t('ciims.models.Users', 'ID'), |
|
93 | + 'email' => Yii::t('ciims.models.Users', 'Email'), |
|
94 | + 'password' => Yii::t('ciims.models.Users', 'Password'), |
|
95 | + 'username' => Yii::t('ciims.models.Users', 'User Name'), |
|
96 | + 'user_role' => Yii::t('ciims.models.Users', 'User Role'), |
|
97 | + 'status' => Yii::t('ciims.models.Users', 'Active'), |
|
98 | + 'created' => Yii::t('ciims.models.Users', 'Created'), |
|
99 | + 'updated' => Yii::t('ciims.models.Users', 'Updated'), |
|
100 | + ); |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Gets the first and last name instead of the username |
|
105 | + */ |
|
106 | + public function getName() |
|
107 | + { |
|
108 | + return $this->username; |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Retrieves the username |
|
113 | + */ |
|
114 | + public function getUsername() |
|
115 | + { |
|
116 | + return $this->username; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Retrieves the username |
|
121 | + * @todo This is technical debt. At some point this should be completely depricated |
|
122 | + */ |
|
123 | + public function getDisplayName() |
|
124 | + { |
|
125 | + Yii::log('Users::displayName has been deprecated. Use Users::username moving forward', 'warning', 'models.users'); |
|
126 | + return $this->getUsername(); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Retrieves the reputation for a given user |
|
131 | + * @param boolean $model Whether an instance of UserMetadata should be returned or not |
|
132 | + * @return mixed |
|
133 | + */ |
|
134 | + public function getReputation($model=false) |
|
135 | + { |
|
136 | + $reputation = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'reputation'), array('value' => 150)); |
|
137 | + |
|
138 | + if ($model === true) |
|
139 | + return $reputation; |
|
140 | + |
|
141 | + return $reputation->value; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Updates a user's reputation |
|
146 | + * @return boolean |
|
147 | + */ |
|
148 | + public function setReputation($rep = 10) |
|
149 | + { |
|
150 | + $reputation = $this->getReputation(true); |
|
151 | + $reputation->value += $rep; |
|
152 | + return $reputation->save(); |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * Retrieves all comments that the user has flagged |
|
157 | + * @param boolean $model Whether an instance of UserMetadata should be returned or not |
|
158 | + * @return mixed |
|
159 | + */ |
|
160 | + public function getFlaggedComments($model=false) |
|
161 | + { |
|
162 | + $flags = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'flaggedComments'), array('value' => CJSON::encode(array()))); |
|
163 | 163 | |
164 | - if ($model === true) |
|
165 | - return $flags; |
|
166 | - |
|
167 | - return CJSON::decode($flags->value); |
|
168 | - } |
|
169 | - |
|
170 | - /** |
|
171 | - * Flags a comment with a given ID |
|
172 | - * @return boolean |
|
173 | - */ |
|
174 | - public function flagComment($id) |
|
175 | - { |
|
176 | - $flaggedComments = $this->getFlaggedComments(true); |
|
177 | - $flags = CJSON::decode($flaggedComments->value); |
|
178 | - |
|
179 | - // If the comment has already been flagged, just return true |
|
180 | - if (in_array($id, $flags)) |
|
181 | - return true; |
|
182 | - |
|
183 | - $flags[] = $id; |
|
184 | - $flaggedComments->value = CJSON::encode($flags); |
|
185 | - |
|
186 | - return $flaggedComments->save(); |
|
187 | - } |
|
188 | - |
|
189 | - /** |
|
190 | - * Retrieves a list of models based on the current search/filter conditions. |
|
191 | - * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
|
192 | - */ |
|
193 | - public function search() |
|
194 | - { |
|
195 | - $criteria=new CDbCriteria; |
|
196 | - |
|
197 | - $criteria->compare('id',$this->id); |
|
198 | - $criteria->compare('email',$this->email,true); |
|
199 | - $criteria->compare('password',$this->password,true); |
|
200 | - $criteria->compare('username',$this->username,true); |
|
201 | - $criteria->compare('user_role',$this->user_role); |
|
202 | - $criteria->compare('status',$this->status); |
|
203 | - $criteria->compare('created',$this->created,true); |
|
204 | - $criteria->compare('updated',$this->updated,true); |
|
205 | - $criteria->order = "user_role DESC, created DESC"; |
|
206 | - |
|
207 | - return new CActiveDataProvider($this, array( |
|
208 | - 'criteria' => $criteria, |
|
209 | - 'pagination' => array( |
|
210 | - 'pageSize' => $this->pageSize |
|
211 | - ) |
|
212 | - )); |
|
213 | - } |
|
214 | - |
|
215 | - /** |
|
216 | - * Sets some default values for the user record. |
|
217 | - * @see CActiveRecord::beforeValidate() |
|
218 | - **/ |
|
219 | - public function beforeValidate() |
|
220 | - { |
|
221 | - // If the password is nulled, or unchanged |
|
222 | - if ($this->password == NULL || $this->password == Cii::get($this->_oldAttributes, 'password', false)) |
|
223 | - { |
|
224 | - if (!$this->isNewRecord) |
|
225 | - $this->password = $this->_oldAttributes['password']; |
|
226 | - } |
|
227 | - else |
|
228 | - { |
|
229 | - $this->password = password_hash($this->password, PASSWORD_BCRYPT, array('cost' => Cii::getBcryptCost())); |
|
230 | - |
|
231 | - if (!$this->isNewRecord) |
|
232 | - { |
|
233 | - $emailSettings = new EmailSettings; |
|
234 | - $emailSettings->send( |
|
235 | - $this, |
|
236 | - Yii::t('ciims.models.Users', 'CiiMS Password Change Notification'), |
|
237 | - 'base.themes.' . Cii::getConfig('theme', 'default') .'.views.email.passwordchange', |
|
238 | - array('user' => $this) |
|
239 | - ); |
|
240 | - } |
|
241 | - } |
|
242 | - |
|
243 | - return parent::beforeValidate(); |
|
244 | - } |
|
245 | - |
|
246 | - /** |
|
247 | - * Lets us know if the user likes a given content post or not |
|
248 | - * @param int $id The id of the content we want to know about |
|
249 | - * @return bool Whether or not the user likes the post |
|
250 | - */ |
|
251 | - public function likesPost($id = NULL) |
|
252 | - { |
|
253 | - if ($id === NULL) |
|
254 | - return false; |
|
255 | - |
|
256 | - $likes = UserMetadata::model()->findByAttributes(array('user_id' => $this->id, 'key' => 'likes')); |
|
257 | - |
|
258 | - if ($likes === NULL) |
|
259 | - return false; |
|
260 | - |
|
261 | - $likesArray = json_decode($likes->value, true); |
|
262 | - if (in_array($id, array_values($likesArray))) |
|
263 | - return true; |
|
264 | - |
|
265 | - return false; |
|
266 | - } |
|
267 | - |
|
268 | - /** |
|
269 | - * Helper method to get the usermetadata object rather than calling getPrototype everywhere |
|
270 | - * @param string $key |
|
271 | - * @param mixed $value |
|
272 | - * @return UserMetadata prototype object |
|
273 | - */ |
|
274 | - public function getMetadataObject($key, $value=NULL) |
|
275 | - { |
|
276 | - return UserMetadata::model()->getPrototype('UserMetadata', array( |
|
277 | - 'user_id' => $this->id, |
|
278 | - 'key' => $key |
|
279 | - ),array( |
|
280 | - 'user_id' => $this->id, |
|
281 | - 'key' => $key, |
|
282 | - 'value' => $value, |
|
283 | - )); |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Helper method to set the usermetadata object rather than calling getPrototype everywhere |
|
288 | - * @param string $key |
|
289 | - * @param mixed $value |
|
290 | - * @return UserMetadata prototype object |
|
291 | - */ |
|
292 | - public function setMetadataObject($key, $value) |
|
293 | - { |
|
294 | - $metadata = $this->getMetadataObject(); |
|
295 | - |
|
296 | - $metadata->value = $value; |
|
297 | - |
|
298 | - return $metadata->save(); |
|
299 | - } |
|
300 | - |
|
301 | - /** |
|
164 | + if ($model === true) |
|
165 | + return $flags; |
|
166 | + |
|
167 | + return CJSON::decode($flags->value); |
|
168 | + } |
|
169 | + |
|
170 | + /** |
|
171 | + * Flags a comment with a given ID |
|
172 | + * @return boolean |
|
173 | + */ |
|
174 | + public function flagComment($id) |
|
175 | + { |
|
176 | + $flaggedComments = $this->getFlaggedComments(true); |
|
177 | + $flags = CJSON::decode($flaggedComments->value); |
|
178 | + |
|
179 | + // If the comment has already been flagged, just return true |
|
180 | + if (in_array($id, $flags)) |
|
181 | + return true; |
|
182 | + |
|
183 | + $flags[] = $id; |
|
184 | + $flaggedComments->value = CJSON::encode($flags); |
|
185 | + |
|
186 | + return $flaggedComments->save(); |
|
187 | + } |
|
188 | + |
|
189 | + /** |
|
190 | + * Retrieves a list of models based on the current search/filter conditions. |
|
191 | + * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
|
192 | + */ |
|
193 | + public function search() |
|
194 | + { |
|
195 | + $criteria=new CDbCriteria; |
|
196 | + |
|
197 | + $criteria->compare('id',$this->id); |
|
198 | + $criteria->compare('email',$this->email,true); |
|
199 | + $criteria->compare('password',$this->password,true); |
|
200 | + $criteria->compare('username',$this->username,true); |
|
201 | + $criteria->compare('user_role',$this->user_role); |
|
202 | + $criteria->compare('status',$this->status); |
|
203 | + $criteria->compare('created',$this->created,true); |
|
204 | + $criteria->compare('updated',$this->updated,true); |
|
205 | + $criteria->order = "user_role DESC, created DESC"; |
|
206 | + |
|
207 | + return new CActiveDataProvider($this, array( |
|
208 | + 'criteria' => $criteria, |
|
209 | + 'pagination' => array( |
|
210 | + 'pageSize' => $this->pageSize |
|
211 | + ) |
|
212 | + )); |
|
213 | + } |
|
214 | + |
|
215 | + /** |
|
216 | + * Sets some default values for the user record. |
|
217 | + * @see CActiveRecord::beforeValidate() |
|
218 | + **/ |
|
219 | + public function beforeValidate() |
|
220 | + { |
|
221 | + // If the password is nulled, or unchanged |
|
222 | + if ($this->password == NULL || $this->password == Cii::get($this->_oldAttributes, 'password', false)) |
|
223 | + { |
|
224 | + if (!$this->isNewRecord) |
|
225 | + $this->password = $this->_oldAttributes['password']; |
|
226 | + } |
|
227 | + else |
|
228 | + { |
|
229 | + $this->password = password_hash($this->password, PASSWORD_BCRYPT, array('cost' => Cii::getBcryptCost())); |
|
230 | + |
|
231 | + if (!$this->isNewRecord) |
|
232 | + { |
|
233 | + $emailSettings = new EmailSettings; |
|
234 | + $emailSettings->send( |
|
235 | + $this, |
|
236 | + Yii::t('ciims.models.Users', 'CiiMS Password Change Notification'), |
|
237 | + 'base.themes.' . Cii::getConfig('theme', 'default') .'.views.email.passwordchange', |
|
238 | + array('user' => $this) |
|
239 | + ); |
|
240 | + } |
|
241 | + } |
|
242 | + |
|
243 | + return parent::beforeValidate(); |
|
244 | + } |
|
245 | + |
|
246 | + /** |
|
247 | + * Lets us know if the user likes a given content post or not |
|
248 | + * @param int $id The id of the content we want to know about |
|
249 | + * @return bool Whether or not the user likes the post |
|
250 | + */ |
|
251 | + public function likesPost($id = NULL) |
|
252 | + { |
|
253 | + if ($id === NULL) |
|
254 | + return false; |
|
255 | + |
|
256 | + $likes = UserMetadata::model()->findByAttributes(array('user_id' => $this->id, 'key' => 'likes')); |
|
257 | + |
|
258 | + if ($likes === NULL) |
|
259 | + return false; |
|
260 | + |
|
261 | + $likesArray = json_decode($likes->value, true); |
|
262 | + if (in_array($id, array_values($likesArray))) |
|
263 | + return true; |
|
264 | + |
|
265 | + return false; |
|
266 | + } |
|
267 | + |
|
268 | + /** |
|
269 | + * Helper method to get the usermetadata object rather than calling getPrototype everywhere |
|
270 | + * @param string $key |
|
271 | + * @param mixed $value |
|
272 | + * @return UserMetadata prototype object |
|
273 | + */ |
|
274 | + public function getMetadataObject($key, $value=NULL) |
|
275 | + { |
|
276 | + return UserMetadata::model()->getPrototype('UserMetadata', array( |
|
277 | + 'user_id' => $this->id, |
|
278 | + 'key' => $key |
|
279 | + ),array( |
|
280 | + 'user_id' => $this->id, |
|
281 | + 'key' => $key, |
|
282 | + 'value' => $value, |
|
283 | + )); |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Helper method to set the usermetadata object rather than calling getPrototype everywhere |
|
288 | + * @param string $key |
|
289 | + * @param mixed $value |
|
290 | + * @return UserMetadata prototype object |
|
291 | + */ |
|
292 | + public function setMetadataObject($key, $value) |
|
293 | + { |
|
294 | + $metadata = $this->getMetadataObject(); |
|
295 | + |
|
296 | + $metadata->value = $value; |
|
297 | + |
|
298 | + return $metadata->save(); |
|
299 | + } |
|
300 | + |
|
301 | + /** |
|
302 | 302 | * Determines if two factor authentication code is required |
303 | 303 | * @return boolean |
304 | 304 | */ |
305 | 305 | public function needsTwoFactorAuth() |
306 | 306 | { |
307 | - $metadata = $this->getMetadataObject('OTPSeed', false); |
|
307 | + $metadata = $this->getMetadataObject('OTPSeed', false); |
|
308 | 308 | |
309 | - if ($metadata->value !== false) |
|
310 | - return true; |
|
309 | + if ($metadata->value !== false) |
|
310 | + return true; |
|
311 | 311 | |
312 | - return false; |
|
312 | + return false; |
|
313 | 313 | } |
314 | 314 | |
315 | - /** |
|
316 | - * Returns the gravatar image url for a particular user |
|
317 | - * The beauty of this is that you can call User::model()->findByPk()->gravatarImage() and not have to do anything else |
|
318 | - * Implemention details borrowed from Hypatia Cii User Extensions with permission |
|
319 | - * @param integer $size The size of the image we want to display |
|
320 | - * @param string $default The default image to be displayed if none is found |
|
321 | - * @return string gravatar api image |
|
322 | - */ |
|
323 | - public function gravatarImage($size=20, $default=NULL) |
|
324 | - { |
|
325 | - return "https://www.gravatar.com/avatar/" . md5(strtolower(trim($this->email))).'?s='.$size; |
|
326 | - } |
|
315 | + /** |
|
316 | + * Returns the gravatar image url for a particular user |
|
317 | + * The beauty of this is that you can call User::model()->findByPk()->gravatarImage() and not have to do anything else |
|
318 | + * Implemention details borrowed from Hypatia Cii User Extensions with permission |
|
319 | + * @param integer $size The size of the image we want to display |
|
320 | + * @param string $default The default image to be displayed if none is found |
|
321 | + * @return string gravatar api image |
|
322 | + */ |
|
323 | + public function gravatarImage($size=20, $default=NULL) |
|
324 | + { |
|
325 | + return "https://www.gravatar.com/avatar/" . md5(strtolower(trim($this->email))).'?s='.$size; |
|
326 | + } |
|
327 | 327 | } |
@@ -135,8 +135,9 @@ discard block |
||
135 | 135 | { |
136 | 136 | $reputation = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'reputation'), array('value' => 150)); |
137 | 137 | |
138 | - if ($model === true) |
|
139 | - return $reputation; |
|
138 | + if ($model === true) { |
|
139 | + return $reputation; |
|
140 | + } |
|
140 | 141 | |
141 | 142 | return $reputation->value; |
142 | 143 | } |
@@ -161,8 +162,9 @@ discard block |
||
161 | 162 | { |
162 | 163 | $flags = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'flaggedComments'), array('value' => CJSON::encode(array()))); |
163 | 164 | |
164 | - if ($model === true) |
|
165 | - return $flags; |
|
165 | + if ($model === true) { |
|
166 | + return $flags; |
|
167 | + } |
|
166 | 168 | |
167 | 169 | return CJSON::decode($flags->value); |
168 | 170 | } |
@@ -177,8 +179,9 @@ discard block |
||
177 | 179 | $flags = CJSON::decode($flaggedComments->value); |
178 | 180 | |
179 | 181 | // If the comment has already been flagged, just return true |
180 | - if (in_array($id, $flags)) |
|
181 | - return true; |
|
182 | + if (in_array($id, $flags)) { |
|
183 | + return true; |
|
184 | + } |
|
182 | 185 | |
183 | 186 | $flags[] = $id; |
184 | 187 | $flaggedComments->value = CJSON::encode($flags); |
@@ -221,10 +224,10 @@ discard block |
||
221 | 224 | // If the password is nulled, or unchanged |
222 | 225 | if ($this->password == NULL || $this->password == Cii::get($this->_oldAttributes, 'password', false)) |
223 | 226 | { |
224 | - if (!$this->isNewRecord) |
|
225 | - $this->password = $this->_oldAttributes['password']; |
|
226 | - } |
|
227 | - else |
|
227 | + if (!$this->isNewRecord) { |
|
228 | + $this->password = $this->_oldAttributes['password']; |
|
229 | + } |
|
230 | + } else |
|
228 | 231 | { |
229 | 232 | $this->password = password_hash($this->password, PASSWORD_BCRYPT, array('cost' => Cii::getBcryptCost())); |
230 | 233 | |
@@ -250,17 +253,20 @@ discard block |
||
250 | 253 | */ |
251 | 254 | public function likesPost($id = NULL) |
252 | 255 | { |
253 | - if ($id === NULL) |
|
254 | - return false; |
|
256 | + if ($id === NULL) { |
|
257 | + return false; |
|
258 | + } |
|
255 | 259 | |
256 | 260 | $likes = UserMetadata::model()->findByAttributes(array('user_id' => $this->id, 'key' => 'likes')); |
257 | 261 | |
258 | - if ($likes === NULL) |
|
259 | - return false; |
|
262 | + if ($likes === NULL) { |
|
263 | + return false; |
|
264 | + } |
|
260 | 265 | |
261 | 266 | $likesArray = json_decode($likes->value, true); |
262 | - if (in_array($id, array_values($likesArray))) |
|
263 | - return true; |
|
267 | + if (in_array($id, array_values($likesArray))) { |
|
268 | + return true; |
|
269 | + } |
|
264 | 270 | |
265 | 271 | return false; |
266 | 272 | } |
@@ -306,8 +312,9 @@ discard block |
||
306 | 312 | { |
307 | 313 | $metadata = $this->getMetadataObject('OTPSeed', false); |
308 | 314 | |
309 | - if ($metadata->value !== false) |
|
310 | - return true; |
|
315 | + if ($metadata->value !== false) { |
|
316 | + return true; |
|
317 | + } |
|
311 | 318 | |
312 | 319 | return false; |
313 | 320 | } |
@@ -37,15 +37,15 @@ discard block |
||
37 | 37 | * @param string $className active record class name. |
38 | 38 | * @return Users the static model class |
39 | 39 | */ |
40 | - public static function model($className=__CLASS__) |
|
40 | + public static function model ($className = __CLASS__) |
|
41 | 41 | { |
42 | - return parent::model($className); |
|
42 | + return parent::model ($className); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @return string the associated database table name |
47 | 47 | */ |
48 | - public function tableName() |
|
48 | + public function tableName () |
|
49 | 49 | { |
50 | 50 | return 'users'; |
51 | 51 | } |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | /** |
54 | 54 | * @return array validation rules for model attributes. |
55 | 55 | */ |
56 | - public function rules() |
|
56 | + public function rules () |
|
57 | 57 | { |
58 | 58 | // NOTE: you should only define rules for those attributes that |
59 | 59 | // will receive user inputs. |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | /** |
72 | 72 | * @return array relational rules. |
73 | 73 | */ |
74 | - public function relations() |
|
74 | + public function relations () |
|
75 | 75 | { |
76 | 76 | // NOTE: you may need to adjust the relation name and the related |
77 | 77 | // class name for the relations automatically generated below. |
@@ -86,24 +86,24 @@ discard block |
||
86 | 86 | /** |
87 | 87 | * @return array customized attribute labels (name=>label) |
88 | 88 | */ |
89 | - public function attributeLabels() |
|
89 | + public function attributeLabels () |
|
90 | 90 | { |
91 | 91 | return array( |
92 | - 'id' => Yii::t('ciims.models.Users', 'ID'), |
|
93 | - 'email' => Yii::t('ciims.models.Users', 'Email'), |
|
94 | - 'password' => Yii::t('ciims.models.Users', 'Password'), |
|
95 | - 'username' => Yii::t('ciims.models.Users', 'User Name'), |
|
96 | - 'user_role' => Yii::t('ciims.models.Users', 'User Role'), |
|
97 | - 'status' => Yii::t('ciims.models.Users', 'Active'), |
|
98 | - 'created' => Yii::t('ciims.models.Users', 'Created'), |
|
99 | - 'updated' => Yii::t('ciims.models.Users', 'Updated'), |
|
92 | + 'id' => Yii::t ('ciims.models.Users', 'ID'), |
|
93 | + 'email' => Yii::t ('ciims.models.Users', 'Email'), |
|
94 | + 'password' => Yii::t ('ciims.models.Users', 'Password'), |
|
95 | + 'username' => Yii::t ('ciims.models.Users', 'User Name'), |
|
96 | + 'user_role' => Yii::t ('ciims.models.Users', 'User Role'), |
|
97 | + 'status' => Yii::t ('ciims.models.Users', 'Active'), |
|
98 | + 'created' => Yii::t ('ciims.models.Users', 'Created'), |
|
99 | + 'updated' => Yii::t ('ciims.models.Users', 'Updated'), |
|
100 | 100 | ); |
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
104 | 104 | * Gets the first and last name instead of the username |
105 | 105 | */ |
106 | - public function getName() |
|
106 | + public function getName () |
|
107 | 107 | { |
108 | 108 | return $this->username; |
109 | 109 | } |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | /** |
112 | 112 | * Retrieves the username |
113 | 113 | */ |
114 | - public function getUsername() |
|
114 | + public function getUsername () |
|
115 | 115 | { |
116 | 116 | return $this->username; |
117 | 117 | } |
@@ -120,10 +120,10 @@ discard block |
||
120 | 120 | * Retrieves the username |
121 | 121 | * @todo This is technical debt. At some point this should be completely depricated |
122 | 122 | */ |
123 | - public function getDisplayName() |
|
123 | + public function getDisplayName () |
|
124 | 124 | { |
125 | - Yii::log('Users::displayName has been deprecated. Use Users::username moving forward', 'warning', 'models.users'); |
|
126 | - return $this->getUsername(); |
|
125 | + Yii::log ('Users::displayName has been deprecated. Use Users::username moving forward', 'warning', 'models.users'); |
|
126 | + return $this->getUsername (); |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | /** |
@@ -131,9 +131,9 @@ discard block |
||
131 | 131 | * @param boolean $model Whether an instance of UserMetadata should be returned or not |
132 | 132 | * @return mixed |
133 | 133 | */ |
134 | - public function getReputation($model=false) |
|
134 | + public function getReputation ($model = false) |
|
135 | 135 | { |
136 | - $reputation = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'reputation'), array('value' => 150)); |
|
136 | + $reputation = UserMetadata::model ()->getPrototype ('UserMetadata', array('user_id' => $this->id, 'key' => 'reputation'), array('value' => 150)); |
|
137 | 137 | |
138 | 138 | if ($model === true) |
139 | 139 | return $reputation; |
@@ -145,11 +145,11 @@ discard block |
||
145 | 145 | * Updates a user's reputation |
146 | 146 | * @return boolean |
147 | 147 | */ |
148 | - public function setReputation($rep = 10) |
|
148 | + public function setReputation ($rep = 10) |
|
149 | 149 | { |
150 | - $reputation = $this->getReputation(true); |
|
150 | + $reputation = $this->getReputation (true); |
|
151 | 151 | $reputation->value += $rep; |
152 | - return $reputation->save(); |
|
152 | + return $reputation->save (); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | /** |
@@ -157,54 +157,54 @@ discard block |
||
157 | 157 | * @param boolean $model Whether an instance of UserMetadata should be returned or not |
158 | 158 | * @return mixed |
159 | 159 | */ |
160 | - public function getFlaggedComments($model=false) |
|
160 | + public function getFlaggedComments ($model = false) |
|
161 | 161 | { |
162 | - $flags = UserMetadata::model()->getPrototype('UserMetadata', array('user_id' => $this->id, 'key' => 'flaggedComments'), array('value' => CJSON::encode(array()))); |
|
162 | + $flags = UserMetadata::model ()->getPrototype ('UserMetadata', array('user_id' => $this->id, 'key' => 'flaggedComments'), array('value' => CJSON::encode (array()))); |
|
163 | 163 | |
164 | 164 | if ($model === true) |
165 | 165 | return $flags; |
166 | 166 | |
167 | - return CJSON::decode($flags->value); |
|
167 | + return CJSON::decode ($flags->value); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
171 | 171 | * Flags a comment with a given ID |
172 | 172 | * @return boolean |
173 | 173 | */ |
174 | - public function flagComment($id) |
|
174 | + public function flagComment ($id) |
|
175 | 175 | { |
176 | - $flaggedComments = $this->getFlaggedComments(true); |
|
177 | - $flags = CJSON::decode($flaggedComments->value); |
|
176 | + $flaggedComments = $this->getFlaggedComments (true); |
|
177 | + $flags = CJSON::decode ($flaggedComments->value); |
|
178 | 178 | |
179 | 179 | // If the comment has already been flagged, just return true |
180 | - if (in_array($id, $flags)) |
|
180 | + if (in_array ($id, $flags)) |
|
181 | 181 | return true; |
182 | 182 | |
183 | 183 | $flags[] = $id; |
184 | - $flaggedComments->value = CJSON::encode($flags); |
|
184 | + $flaggedComments->value = CJSON::encode ($flags); |
|
185 | 185 | |
186 | - return $flaggedComments->save(); |
|
186 | + return $flaggedComments->save (); |
|
187 | 187 | } |
188 | 188 | |
189 | 189 | /** |
190 | 190 | * Retrieves a list of models based on the current search/filter conditions. |
191 | 191 | * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. |
192 | 192 | */ |
193 | - public function search() |
|
193 | + public function search () |
|
194 | 194 | { |
195 | - $criteria=new CDbCriteria; |
|
196 | - |
|
197 | - $criteria->compare('id',$this->id); |
|
198 | - $criteria->compare('email',$this->email,true); |
|
199 | - $criteria->compare('password',$this->password,true); |
|
200 | - $criteria->compare('username',$this->username,true); |
|
201 | - $criteria->compare('user_role',$this->user_role); |
|
202 | - $criteria->compare('status',$this->status); |
|
203 | - $criteria->compare('created',$this->created,true); |
|
204 | - $criteria->compare('updated',$this->updated,true); |
|
195 | + $criteria = new CDbCriteria; |
|
196 | + |
|
197 | + $criteria->compare ('id', $this->id); |
|
198 | + $criteria->compare ('email', $this->email, true); |
|
199 | + $criteria->compare ('password', $this->password, true); |
|
200 | + $criteria->compare ('username', $this->username, true); |
|
201 | + $criteria->compare ('user_role', $this->user_role); |
|
202 | + $criteria->compare ('status', $this->status); |
|
203 | + $criteria->compare ('created', $this->created, true); |
|
204 | + $criteria->compare ('updated', $this->updated, true); |
|
205 | 205 | $criteria->order = "user_role DESC, created DESC"; |
206 | 206 | |
207 | - return new CActiveDataProvider($this, array( |
|
207 | + return new CActiveDataProvider ($this, array( |
|
208 | 208 | 'criteria' => $criteria, |
209 | 209 | 'pagination' => array( |
210 | 210 | 'pageSize' => $this->pageSize |
@@ -216,31 +216,31 @@ discard block |
||
216 | 216 | * Sets some default values for the user record. |
217 | 217 | * @see CActiveRecord::beforeValidate() |
218 | 218 | **/ |
219 | - public function beforeValidate() |
|
219 | + public function beforeValidate () |
|
220 | 220 | { |
221 | 221 | // If the password is nulled, or unchanged |
222 | - if ($this->password == NULL || $this->password == Cii::get($this->_oldAttributes, 'password', false)) |
|
222 | + if ($this->password == NULL || $this->password == Cii::get ($this->_oldAttributes, 'password', false)) |
|
223 | 223 | { |
224 | 224 | if (!$this->isNewRecord) |
225 | 225 | $this->password = $this->_oldAttributes['password']; |
226 | 226 | } |
227 | 227 | else |
228 | 228 | { |
229 | - $this->password = password_hash($this->password, PASSWORD_BCRYPT, array('cost' => Cii::getBcryptCost())); |
|
229 | + $this->password = password_hash ($this->password, PASSWORD_BCRYPT, array('cost' => Cii::getBcryptCost ())); |
|
230 | 230 | |
231 | 231 | if (!$this->isNewRecord) |
232 | 232 | { |
233 | 233 | $emailSettings = new EmailSettings; |
234 | - $emailSettings->send( |
|
234 | + $emailSettings->send ( |
|
235 | 235 | $this, |
236 | - Yii::t('ciims.models.Users', 'CiiMS Password Change Notification'), |
|
237 | - 'base.themes.' . Cii::getConfig('theme', 'default') .'.views.email.passwordchange', |
|
236 | + Yii::t ('ciims.models.Users', 'CiiMS Password Change Notification'), |
|
237 | + 'base.themes.'.Cii::getConfig ('theme', 'default').'.views.email.passwordchange', |
|
238 | 238 | array('user' => $this) |
239 | 239 | ); |
240 | 240 | } |
241 | 241 | } |
242 | 242 | |
243 | - return parent::beforeValidate(); |
|
243 | + return parent::beforeValidate (); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | /** |
@@ -248,18 +248,18 @@ discard block |
||
248 | 248 | * @param int $id The id of the content we want to know about |
249 | 249 | * @return bool Whether or not the user likes the post |
250 | 250 | */ |
251 | - public function likesPost($id = NULL) |
|
251 | + public function likesPost ($id = NULL) |
|
252 | 252 | { |
253 | 253 | if ($id === NULL) |
254 | 254 | return false; |
255 | 255 | |
256 | - $likes = UserMetadata::model()->findByAttributes(array('user_id' => $this->id, 'key' => 'likes')); |
|
256 | + $likes = UserMetadata::model ()->findByAttributes (array('user_id' => $this->id, 'key' => 'likes')); |
|
257 | 257 | |
258 | 258 | if ($likes === NULL) |
259 | 259 | return false; |
260 | 260 | |
261 | - $likesArray = json_decode($likes->value, true); |
|
262 | - if (in_array($id, array_values($likesArray))) |
|
261 | + $likesArray = json_decode ($likes->value, true); |
|
262 | + if (in_array ($id, array_values ($likesArray))) |
|
263 | 263 | return true; |
264 | 264 | |
265 | 265 | return false; |
@@ -271,12 +271,12 @@ discard block |
||
271 | 271 | * @param mixed $value |
272 | 272 | * @return UserMetadata prototype object |
273 | 273 | */ |
274 | - public function getMetadataObject($key, $value=NULL) |
|
274 | + public function getMetadataObject ($key, $value = NULL) |
|
275 | 275 | { |
276 | - return UserMetadata::model()->getPrototype('UserMetadata', array( |
|
276 | + return UserMetadata::model ()->getPrototype ('UserMetadata', array( |
|
277 | 277 | 'user_id' => $this->id, |
278 | 278 | 'key' => $key |
279 | - ),array( |
|
279 | + ), array( |
|
280 | 280 | 'user_id' => $this->id, |
281 | 281 | 'key' => $key, |
282 | 282 | 'value' => $value, |
@@ -289,22 +289,22 @@ discard block |
||
289 | 289 | * @param mixed $value |
290 | 290 | * @return UserMetadata prototype object |
291 | 291 | */ |
292 | - public function setMetadataObject($key, $value) |
|
292 | + public function setMetadataObject ($key, $value) |
|
293 | 293 | { |
294 | - $metadata = $this->getMetadataObject(); |
|
294 | + $metadata = $this->getMetadataObject (); |
|
295 | 295 | |
296 | 296 | $metadata->value = $value; |
297 | 297 | |
298 | - return $metadata->save(); |
|
298 | + return $metadata->save (); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | /** |
302 | 302 | * Determines if two factor authentication code is required |
303 | 303 | * @return boolean |
304 | 304 | */ |
305 | - public function needsTwoFactorAuth() |
|
305 | + public function needsTwoFactorAuth () |
|
306 | 306 | { |
307 | - $metadata = $this->getMetadataObject('OTPSeed', false); |
|
307 | + $metadata = $this->getMetadataObject ('OTPSeed', false); |
|
308 | 308 | |
309 | 309 | if ($metadata->value !== false) |
310 | 310 | return true; |
@@ -320,8 +320,8 @@ discard block |
||
320 | 320 | * @param string $default The default image to be displayed if none is found |
321 | 321 | * @return string gravatar api image |
322 | 322 | */ |
323 | - public function gravatarImage($size=20, $default=NULL) |
|
323 | + public function gravatarImage ($size = 20, $default = NULL) |
|
324 | 324 | { |
325 | - return "https://www.gravatar.com/avatar/" . md5(strtolower(trim($this->email))).'?s='.$size; |
|
325 | + return "https://www.gravatar.com/avatar/".md5 (strtolower (trim ($this->email))).'?s='.$size; |
|
326 | 326 | } |
327 | 327 | } |
@@ -2,117 +2,117 @@ |
||
2 | 2 | |
3 | 3 | class ActivationForm extends CFormModel |
4 | 4 | { |
5 | - /** |
|
6 | - * The password provided by the user |
|
7 | - * @var string $password |
|
8 | - */ |
|
9 | - public $password; |
|
10 | - |
|
11 | - /** |
|
12 | - * The activation key originally sent to the user's email |
|
13 | - * @var string $activationKey |
|
14 | - */ |
|
15 | - public $activationKey; |
|
16 | - |
|
17 | - /** |
|
18 | - * The user model |
|
19 | - * @var Users $_user |
|
20 | - */ |
|
21 | - private $_user; |
|
22 | - |
|
23 | - /** |
|
24 | - * The activation key metadata model. This is loaded to ensure it gets cleaned up properly |
|
25 | - * @var UserMetadata $_meta |
|
26 | - */ |
|
27 | - private $_meta; |
|
28 | - |
|
29 | - /** |
|
30 | - * Validation rules |
|
31 | - * @return array |
|
32 | - */ |
|
33 | - public function rules() |
|
34 | - { |
|
35 | - return array( |
|
36 | - array('password, activationKey', 'required'), |
|
37 | - array('password', 'length', 'min'=>8), |
|
38 | - array('activationKey', 'validateKey'), |
|
39 | - array('password', 'validateUserPassword'), |
|
40 | - ); |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Attribute labels |
|
45 | - * @return array |
|
46 | - */ |
|
47 | - public function attributeLabels() |
|
48 | - { |
|
49 | - return array( |
|
50 | - 'password' => Yii::t('ciims.models.ActivationForm', 'Your Password'), |
|
51 | - 'activationKey' => Yii::t('ciims.models.ActivationForm', 'Your Activation Key') |
|
52 | - ); |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * Validates that the activation key belongs to a user and is valid |
|
57 | - * @param array $attributes |
|
58 | - * @param array $params |
|
59 | - * return array |
|
60 | - */ |
|
61 | - public function validateKey($attributes=array(), $params=array()) |
|
62 | - { |
|
63 | - $this->_meta = UserMetadata::model()->findByAttributes(array('key'=>'activationKey', 'value'=>$this->activationKey)); |
|
64 | - |
|
65 | - if ($this->_meta == NULL) |
|
66 | - { |
|
67 | - $this->addError('activationKey', Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); |
|
68 | - return false; |
|
69 | - } |
|
70 | - |
|
71 | - return true; |
|
72 | - } |
|
73 | - |
|
74 | - /** |
|
75 | - * Ensures that the password entered matches the one provided during registration |
|
76 | - * @param array $attributes |
|
77 | - * @param array $params |
|
78 | - * return array |
|
79 | - */ |
|
80 | - public function validateUserPassword($attributes, $params) |
|
81 | - { |
|
82 | - if ($this->_user == NULL) |
|
83 | - { |
|
84 | - $this->addError('activationKey', Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); |
|
85 | - return false; |
|
86 | - } |
|
87 | - |
|
88 | - $result = password_verify($this->password, $this->_user->password); |
|
89 | - |
|
90 | - if ($result == false) |
|
91 | - { |
|
92 | - $this->addError('password', Yii::t('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.')); |
|
93 | - return false; |
|
94 | - } |
|
95 | - |
|
96 | - return true; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Makes the user an active user in the database, and deletes their activation token |
|
101 | - * @return boolean |
|
102 | - */ |
|
103 | - public function save() |
|
104 | - { |
|
105 | - $userId = $this->_meta->user_id; |
|
106 | - $this->_user = Users::model()->findByPk($userId); |
|
107 | - |
|
108 | - if (!$this->validate()) |
|
109 | - return false; |
|
110 | - |
|
111 | - $this->_user->status = Users::ACTIVE; |
|
5 | + /** |
|
6 | + * The password provided by the user |
|
7 | + * @var string $password |
|
8 | + */ |
|
9 | + public $password; |
|
10 | + |
|
11 | + /** |
|
12 | + * The activation key originally sent to the user's email |
|
13 | + * @var string $activationKey |
|
14 | + */ |
|
15 | + public $activationKey; |
|
16 | + |
|
17 | + /** |
|
18 | + * The user model |
|
19 | + * @var Users $_user |
|
20 | + */ |
|
21 | + private $_user; |
|
22 | + |
|
23 | + /** |
|
24 | + * The activation key metadata model. This is loaded to ensure it gets cleaned up properly |
|
25 | + * @var UserMetadata $_meta |
|
26 | + */ |
|
27 | + private $_meta; |
|
28 | + |
|
29 | + /** |
|
30 | + * Validation rules |
|
31 | + * @return array |
|
32 | + */ |
|
33 | + public function rules() |
|
34 | + { |
|
35 | + return array( |
|
36 | + array('password, activationKey', 'required'), |
|
37 | + array('password', 'length', 'min'=>8), |
|
38 | + array('activationKey', 'validateKey'), |
|
39 | + array('password', 'validateUserPassword'), |
|
40 | + ); |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Attribute labels |
|
45 | + * @return array |
|
46 | + */ |
|
47 | + public function attributeLabels() |
|
48 | + { |
|
49 | + return array( |
|
50 | + 'password' => Yii::t('ciims.models.ActivationForm', 'Your Password'), |
|
51 | + 'activationKey' => Yii::t('ciims.models.ActivationForm', 'Your Activation Key') |
|
52 | + ); |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * Validates that the activation key belongs to a user and is valid |
|
57 | + * @param array $attributes |
|
58 | + * @param array $params |
|
59 | + * return array |
|
60 | + */ |
|
61 | + public function validateKey($attributes=array(), $params=array()) |
|
62 | + { |
|
63 | + $this->_meta = UserMetadata::model()->findByAttributes(array('key'=>'activationKey', 'value'=>$this->activationKey)); |
|
64 | + |
|
65 | + if ($this->_meta == NULL) |
|
66 | + { |
|
67 | + $this->addError('activationKey', Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); |
|
68 | + return false; |
|
69 | + } |
|
70 | + |
|
71 | + return true; |
|
72 | + } |
|
73 | + |
|
74 | + /** |
|
75 | + * Ensures that the password entered matches the one provided during registration |
|
76 | + * @param array $attributes |
|
77 | + * @param array $params |
|
78 | + * return array |
|
79 | + */ |
|
80 | + public function validateUserPassword($attributes, $params) |
|
81 | + { |
|
82 | + if ($this->_user == NULL) |
|
83 | + { |
|
84 | + $this->addError('activationKey', Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); |
|
85 | + return false; |
|
86 | + } |
|
87 | + |
|
88 | + $result = password_verify($this->password, $this->_user->password); |
|
89 | + |
|
90 | + if ($result == false) |
|
91 | + { |
|
92 | + $this->addError('password', Yii::t('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.')); |
|
93 | + return false; |
|
94 | + } |
|
95 | + |
|
96 | + return true; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Makes the user an active user in the database, and deletes their activation token |
|
101 | + * @return boolean |
|
102 | + */ |
|
103 | + public function save() |
|
104 | + { |
|
105 | + $userId = $this->_meta->user_id; |
|
106 | + $this->_user = Users::model()->findByPk($userId); |
|
107 | + |
|
108 | + if (!$this->validate()) |
|
109 | + return false; |
|
110 | + |
|
111 | + $this->_user->status = Users::ACTIVE; |
|
112 | 112 | |
113 | - if ($this->_user->save()) |
|
114 | - return $this->_meta->delete(); |
|
113 | + if ($this->_user->save()) |
|
114 | + return $this->_meta->delete(); |
|
115 | 115 | |
116 | - return false; |
|
117 | - } |
|
116 | + return false; |
|
117 | + } |
|
118 | 118 | } |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * Validation rules |
31 | 31 | * @return array |
32 | 32 | */ |
33 | - public function rules() |
|
33 | + public function rules () |
|
34 | 34 | { |
35 | 35 | return array( |
36 | 36 | array('password, activationKey', 'required'), |
@@ -44,11 +44,11 @@ discard block |
||
44 | 44 | * Attribute labels |
45 | 45 | * @return array |
46 | 46 | */ |
47 | - public function attributeLabels() |
|
47 | + public function attributeLabels () |
|
48 | 48 | { |
49 | 49 | return array( |
50 | - 'password' => Yii::t('ciims.models.ActivationForm', 'Your Password'), |
|
51 | - 'activationKey' => Yii::t('ciims.models.ActivationForm', 'Your Activation Key') |
|
50 | + 'password' => Yii::t ('ciims.models.ActivationForm', 'Your Password'), |
|
51 | + 'activationKey' => Yii::t ('ciims.models.ActivationForm', 'Your Activation Key') |
|
52 | 52 | ); |
53 | 53 | } |
54 | 54 | |
@@ -58,13 +58,13 @@ discard block |
||
58 | 58 | * @param array $params |
59 | 59 | * return array |
60 | 60 | */ |
61 | - public function validateKey($attributes=array(), $params=array()) |
|
61 | + public function validateKey ($attributes = array(), $params = array()) |
|
62 | 62 | { |
63 | - $this->_meta = UserMetadata::model()->findByAttributes(array('key'=>'activationKey', 'value'=>$this->activationKey)); |
|
63 | + $this->_meta = UserMetadata::model ()->findByAttributes (array('key'=>'activationKey', 'value'=>$this->activationKey)); |
|
64 | 64 | |
65 | 65 | if ($this->_meta == NULL) |
66 | 66 | { |
67 | - $this->addError('activationKey', Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); |
|
67 | + $this->addError ('activationKey', Yii::t ('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); |
|
68 | 68 | return false; |
69 | 69 | } |
70 | 70 | |
@@ -77,19 +77,19 @@ discard block |
||
77 | 77 | * @param array $params |
78 | 78 | * return array |
79 | 79 | */ |
80 | - public function validateUserPassword($attributes, $params) |
|
80 | + public function validateUserPassword ($attributes, $params) |
|
81 | 81 | { |
82 | 82 | if ($this->_user == NULL) |
83 | 83 | { |
84 | - $this->addError('activationKey', Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); |
|
84 | + $this->addError ('activationKey', Yii::t ('ciims.models.ActivationForm', 'The activation key you provided is invalid.')); |
|
85 | 85 | return false; |
86 | 86 | } |
87 | 87 | |
88 | - $result = password_verify($this->password, $this->_user->password); |
|
88 | + $result = password_verify ($this->password, $this->_user->password); |
|
89 | 89 | |
90 | 90 | if ($result == false) |
91 | 91 | { |
92 | - $this->addError('password', Yii::t('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.')); |
|
92 | + $this->addError ('password', Yii::t ('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.')); |
|
93 | 93 | return false; |
94 | 94 | } |
95 | 95 | |
@@ -100,18 +100,18 @@ discard block |
||
100 | 100 | * Makes the user an active user in the database, and deletes their activation token |
101 | 101 | * @return boolean |
102 | 102 | */ |
103 | - public function save() |
|
103 | + public function save () |
|
104 | 104 | { |
105 | 105 | $userId = $this->_meta->user_id; |
106 | - $this->_user = Users::model()->findByPk($userId); |
|
106 | + $this->_user = Users::model ()->findByPk ($userId); |
|
107 | 107 | |
108 | - if (!$this->validate()) |
|
108 | + if (!$this->validate ()) |
|
109 | 109 | return false; |
110 | 110 | |
111 | 111 | $this->_user->status = Users::ACTIVE; |
112 | 112 | |
113 | - if ($this->_user->save()) |
|
114 | - return $this->_meta->delete(); |
|
113 | + if ($this->_user->save ()) |
|
114 | + return $this->_meta->delete (); |
|
115 | 115 | |
116 | 116 | return false; |
117 | 117 | } |
@@ -105,13 +105,15 @@ |
||
105 | 105 | $userId = $this->_meta->user_id; |
106 | 106 | $this->_user = Users::model()->findByPk($userId); |
107 | 107 | |
108 | - if (!$this->validate()) |
|
109 | - return false; |
|
108 | + if (!$this->validate()) { |
|
109 | + return false; |
|
110 | + } |
|
110 | 111 | |
111 | 112 | $this->_user->status = Users::ACTIVE; |
112 | 113 | |
113 | - if ($this->_user->save()) |
|
114 | - return $this->_meta->delete(); |
|
114 | + if ($this->_user->save()) { |
|
115 | + return $this->_meta->delete(); |
|
116 | + } |
|
115 | 117 | |
116 | 118 | return false; |
117 | 119 | } |
@@ -2,154 +2,154 @@ |
||
2 | 2 | |
3 | 3 | class EmailChangeForm extends CFormModel |
4 | 4 | { |
5 | - /** |
|
6 | - * The user's existing password |
|
7 | - * @var string $password |
|
8 | - */ |
|
9 | - public $password; |
|
10 | - |
|
11 | - /** |
|
12 | - * The veification key |
|
13 | - * @var string $verificationKey |
|
14 | - */ |
|
15 | - public $verificationKey; |
|
16 | - |
|
17 | - /** |
|
18 | - * The user model |
|
19 | - * @var Users $_user |
|
20 | - */ |
|
21 | - private $_user; |
|
22 | - |
|
23 | - /** |
|
24 | - * The new email address change key |
|
25 | - * @var UserMetadata $_newEmailAddressChangeKey |
|
26 | - */ |
|
27 | - private $_newEmailAddressChangeKey; |
|
28 | - |
|
29 | - /** |
|
30 | - * The new email address record on file |
|
31 | - * @var UserMetadata $_newEmailAddress |
|
32 | - */ |
|
33 | - private $_newEmailAddress; |
|
34 | - |
|
35 | - /** |
|
36 | - * Validation rules |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public function rules() |
|
40 | - { |
|
41 | - return array( |
|
42 | - array('password, verificationKey', 'required'), |
|
43 | - array('password', 'length', 'min' => 8), |
|
44 | - array('password', 'validateUserPassword'), |
|
45 | - array('verificationKey', 'validateVerificationKey') |
|
46 | - ); |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Attribute labels |
|
51 | - * @return array |
|
52 | - */ |
|
53 | - public function attributeLabels() |
|
54 | - { |
|
55 | - return array( |
|
56 | - 'password' => Yii::t('ciims.models.EmailChangeForm', 'Your Password'), |
|
57 | - 'verificationKey' => Yii::t('ciims.models.EmailChangeForm', 'The Verification Key') |
|
58 | - ); |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Sets the user model |
|
63 | - * @param Users $user |
|
64 | - */ |
|
65 | - public function setUser($user) |
|
66 | - { |
|
67 | - $this->_user = $user; |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * Validates the tokens supplied and that the request hasn't expired |
|
72 | - * @param array $attributes |
|
73 | - * @param array $params |
|
74 | - * return array |
|
75 | - */ |
|
76 | - public function validateVerificationKey($attributes = array(), $params = array()) |
|
77 | - { |
|
78 | - $this->_newEmailAddressChangeKey = UserMetadata::model()->findByAttributes(array( |
|
79 | - 'user_id' => $this->_user->id, |
|
80 | - 'key' => 'newEmailAddressChangeKey', |
|
81 | - 'value' => $this->verificationKey |
|
82 | - )); |
|
83 | - |
|
84 | - if ($this->_newEmailAddressChangeKey == NULL) |
|
85 | - { |
|
86 | - $this->addError('verificationKey', Yii::t('ciims.models.EmailChangeForm', 'The activation key you provided is invalid')); |
|
87 | - return false; |
|
88 | - } |
|
89 | - |
|
90 | - $this->_newEmailAddress = UserMetadata::model()->findByAttributes(array( |
|
91 | - 'user_id' => $this->_user->id, |
|
92 | - 'key' => 'newEmailAddress' |
|
93 | - )); |
|
94 | - |
|
95 | - if ($this->_newEmailAddress == NULL) |
|
96 | - { |
|
97 | - $this->addError('verificationKey', Yii::t('ciims.models.EmailChangeForm', 'The activation key you provided is invalid')); |
|
98 | - return false; |
|
99 | - } |
|
100 | - |
|
101 | - return true; |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * Ensures that the password entered matches the one provided during registration |
|
106 | - * @param array $attributes |
|
107 | - * @param array $params |
|
108 | - * return array |
|
109 | - */ |
|
110 | - public function validateUserPassword($attributes, $params) |
|
111 | - { |
|
112 | - $result = password_verify($this->password, $this->_user->password); |
|
113 | - |
|
114 | - if ($result == false) |
|
115 | - { |
|
116 | - $this->addError('password', Yii::t('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.')); |
|
117 | - return false; |
|
118 | - } |
|
119 | - |
|
120 | - return true; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Updates the user's email address and rehashes their password since the password is bound to the email |
|
125 | - * @return boolean |
|
126 | - */ |
|
127 | - public function save() |
|
128 | - { |
|
129 | - if (!$this->validate()) |
|
130 | - return false; |
|
131 | - |
|
132 | - // This is super buggy for some reason |
|
133 | - $this->_user->email = $this->_newEmailAddress->value; |
|
134 | - |
|
135 | - // Save the model |
|
136 | - if ($this->_user->save()) |
|
137 | - { |
|
138 | - // Delete the metadata |
|
139 | - $this->_newEmailAddressChangeKey->delete(); |
|
140 | - $this->_newEmailAddress->delete(); |
|
141 | - return true; |
|
142 | - } |
|
143 | - |
|
144 | - return false; |
|
145 | - } |
|
146 | - |
|
147 | - /** |
|
148 | - * Retrieves the user's email address from the model |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - public function getEmail() |
|
152 | - { |
|
153 | - return $this->_user->email; |
|
154 | - } |
|
5 | + /** |
|
6 | + * The user's existing password |
|
7 | + * @var string $password |
|
8 | + */ |
|
9 | + public $password; |
|
10 | + |
|
11 | + /** |
|
12 | + * The veification key |
|
13 | + * @var string $verificationKey |
|
14 | + */ |
|
15 | + public $verificationKey; |
|
16 | + |
|
17 | + /** |
|
18 | + * The user model |
|
19 | + * @var Users $_user |
|
20 | + */ |
|
21 | + private $_user; |
|
22 | + |
|
23 | + /** |
|
24 | + * The new email address change key |
|
25 | + * @var UserMetadata $_newEmailAddressChangeKey |
|
26 | + */ |
|
27 | + private $_newEmailAddressChangeKey; |
|
28 | + |
|
29 | + /** |
|
30 | + * The new email address record on file |
|
31 | + * @var UserMetadata $_newEmailAddress |
|
32 | + */ |
|
33 | + private $_newEmailAddress; |
|
34 | + |
|
35 | + /** |
|
36 | + * Validation rules |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public function rules() |
|
40 | + { |
|
41 | + return array( |
|
42 | + array('password, verificationKey', 'required'), |
|
43 | + array('password', 'length', 'min' => 8), |
|
44 | + array('password', 'validateUserPassword'), |
|
45 | + array('verificationKey', 'validateVerificationKey') |
|
46 | + ); |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Attribute labels |
|
51 | + * @return array |
|
52 | + */ |
|
53 | + public function attributeLabels() |
|
54 | + { |
|
55 | + return array( |
|
56 | + 'password' => Yii::t('ciims.models.EmailChangeForm', 'Your Password'), |
|
57 | + 'verificationKey' => Yii::t('ciims.models.EmailChangeForm', 'The Verification Key') |
|
58 | + ); |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Sets the user model |
|
63 | + * @param Users $user |
|
64 | + */ |
|
65 | + public function setUser($user) |
|
66 | + { |
|
67 | + $this->_user = $user; |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * Validates the tokens supplied and that the request hasn't expired |
|
72 | + * @param array $attributes |
|
73 | + * @param array $params |
|
74 | + * return array |
|
75 | + */ |
|
76 | + public function validateVerificationKey($attributes = array(), $params = array()) |
|
77 | + { |
|
78 | + $this->_newEmailAddressChangeKey = UserMetadata::model()->findByAttributes(array( |
|
79 | + 'user_id' => $this->_user->id, |
|
80 | + 'key' => 'newEmailAddressChangeKey', |
|
81 | + 'value' => $this->verificationKey |
|
82 | + )); |
|
83 | + |
|
84 | + if ($this->_newEmailAddressChangeKey == NULL) |
|
85 | + { |
|
86 | + $this->addError('verificationKey', Yii::t('ciims.models.EmailChangeForm', 'The activation key you provided is invalid')); |
|
87 | + return false; |
|
88 | + } |
|
89 | + |
|
90 | + $this->_newEmailAddress = UserMetadata::model()->findByAttributes(array( |
|
91 | + 'user_id' => $this->_user->id, |
|
92 | + 'key' => 'newEmailAddress' |
|
93 | + )); |
|
94 | + |
|
95 | + if ($this->_newEmailAddress == NULL) |
|
96 | + { |
|
97 | + $this->addError('verificationKey', Yii::t('ciims.models.EmailChangeForm', 'The activation key you provided is invalid')); |
|
98 | + return false; |
|
99 | + } |
|
100 | + |
|
101 | + return true; |
|
102 | + } |
|
103 | + |
|
104 | + /** |
|
105 | + * Ensures that the password entered matches the one provided during registration |
|
106 | + * @param array $attributes |
|
107 | + * @param array $params |
|
108 | + * return array |
|
109 | + */ |
|
110 | + public function validateUserPassword($attributes, $params) |
|
111 | + { |
|
112 | + $result = password_verify($this->password, $this->_user->password); |
|
113 | + |
|
114 | + if ($result == false) |
|
115 | + { |
|
116 | + $this->addError('password', Yii::t('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.')); |
|
117 | + return false; |
|
118 | + } |
|
119 | + |
|
120 | + return true; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Updates the user's email address and rehashes their password since the password is bound to the email |
|
125 | + * @return boolean |
|
126 | + */ |
|
127 | + public function save() |
|
128 | + { |
|
129 | + if (!$this->validate()) |
|
130 | + return false; |
|
131 | + |
|
132 | + // This is super buggy for some reason |
|
133 | + $this->_user->email = $this->_newEmailAddress->value; |
|
134 | + |
|
135 | + // Save the model |
|
136 | + if ($this->_user->save()) |
|
137 | + { |
|
138 | + // Delete the metadata |
|
139 | + $this->_newEmailAddressChangeKey->delete(); |
|
140 | + $this->_newEmailAddress->delete(); |
|
141 | + return true; |
|
142 | + } |
|
143 | + |
|
144 | + return false; |
|
145 | + } |
|
146 | + |
|
147 | + /** |
|
148 | + * Retrieves the user's email address from the model |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + public function getEmail() |
|
152 | + { |
|
153 | + return $this->_user->email; |
|
154 | + } |
|
155 | 155 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | * Validation rules |
37 | 37 | * @return array |
38 | 38 | */ |
39 | - public function rules() |
|
39 | + public function rules () |
|
40 | 40 | { |
41 | 41 | return array( |
42 | 42 | array('password, verificationKey', 'required'), |
@@ -50,11 +50,11 @@ discard block |
||
50 | 50 | * Attribute labels |
51 | 51 | * @return array |
52 | 52 | */ |
53 | - public function attributeLabels() |
|
53 | + public function attributeLabels () |
|
54 | 54 | { |
55 | 55 | return array( |
56 | - 'password' => Yii::t('ciims.models.EmailChangeForm', 'Your Password'), |
|
57 | - 'verificationKey' => Yii::t('ciims.models.EmailChangeForm', 'The Verification Key') |
|
56 | + 'password' => Yii::t ('ciims.models.EmailChangeForm', 'Your Password'), |
|
57 | + 'verificationKey' => Yii::t ('ciims.models.EmailChangeForm', 'The Verification Key') |
|
58 | 58 | ); |
59 | 59 | } |
60 | 60 | |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * Sets the user model |
63 | 63 | * @param Users $user |
64 | 64 | */ |
65 | - public function setUser($user) |
|
65 | + public function setUser ($user) |
|
66 | 66 | { |
67 | 67 | $this->_user = $user; |
68 | 68 | } |
@@ -73,9 +73,9 @@ discard block |
||
73 | 73 | * @param array $params |
74 | 74 | * return array |
75 | 75 | */ |
76 | - public function validateVerificationKey($attributes = array(), $params = array()) |
|
76 | + public function validateVerificationKey ($attributes = array(), $params = array()) |
|
77 | 77 | { |
78 | - $this->_newEmailAddressChangeKey = UserMetadata::model()->findByAttributes(array( |
|
78 | + $this->_newEmailAddressChangeKey = UserMetadata::model ()->findByAttributes (array( |
|
79 | 79 | 'user_id' => $this->_user->id, |
80 | 80 | 'key' => 'newEmailAddressChangeKey', |
81 | 81 | 'value' => $this->verificationKey |
@@ -83,18 +83,18 @@ discard block |
||
83 | 83 | |
84 | 84 | if ($this->_newEmailAddressChangeKey == NULL) |
85 | 85 | { |
86 | - $this->addError('verificationKey', Yii::t('ciims.models.EmailChangeForm', 'The activation key you provided is invalid')); |
|
86 | + $this->addError ('verificationKey', Yii::t ('ciims.models.EmailChangeForm', 'The activation key you provided is invalid')); |
|
87 | 87 | return false; |
88 | 88 | } |
89 | 89 | |
90 | - $this->_newEmailAddress = UserMetadata::model()->findByAttributes(array( |
|
90 | + $this->_newEmailAddress = UserMetadata::model ()->findByAttributes (array( |
|
91 | 91 | 'user_id' => $this->_user->id, |
92 | 92 | 'key' => 'newEmailAddress' |
93 | 93 | )); |
94 | 94 | |
95 | 95 | if ($this->_newEmailAddress == NULL) |
96 | 96 | { |
97 | - $this->addError('verificationKey', Yii::t('ciims.models.EmailChangeForm', 'The activation key you provided is invalid')); |
|
97 | + $this->addError ('verificationKey', Yii::t ('ciims.models.EmailChangeForm', 'The activation key you provided is invalid')); |
|
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | |
@@ -107,13 +107,13 @@ discard block |
||
107 | 107 | * @param array $params |
108 | 108 | * return array |
109 | 109 | */ |
110 | - public function validateUserPassword($attributes, $params) |
|
110 | + public function validateUserPassword ($attributes, $params) |
|
111 | 111 | { |
112 | - $result = password_verify($this->password, $this->_user->password); |
|
112 | + $result = password_verify ($this->password, $this->_user->password); |
|
113 | 113 | |
114 | 114 | if ($result == false) |
115 | 115 | { |
116 | - $this->addError('password', Yii::t('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.')); |
|
116 | + $this->addError ('password', Yii::t ('ciims.models.ActivationForm', 'The password you entered does not match the password you registered with.')); |
|
117 | 117 | return false; |
118 | 118 | } |
119 | 119 | |
@@ -124,20 +124,20 @@ discard block |
||
124 | 124 | * Updates the user's email address and rehashes their password since the password is bound to the email |
125 | 125 | * @return boolean |
126 | 126 | */ |
127 | - public function save() |
|
127 | + public function save () |
|
128 | 128 | { |
129 | - if (!$this->validate()) |
|
129 | + if (!$this->validate ()) |
|
130 | 130 | return false; |
131 | 131 | |
132 | 132 | // This is super buggy for some reason |
133 | 133 | $this->_user->email = $this->_newEmailAddress->value; |
134 | 134 | |
135 | 135 | // Save the model |
136 | - if ($this->_user->save()) |
|
136 | + if ($this->_user->save ()) |
|
137 | 137 | { |
138 | 138 | // Delete the metadata |
139 | - $this->_newEmailAddressChangeKey->delete(); |
|
140 | - $this->_newEmailAddress->delete(); |
|
139 | + $this->_newEmailAddressChangeKey->delete (); |
|
140 | + $this->_newEmailAddress->delete (); |
|
141 | 141 | return true; |
142 | 142 | } |
143 | 143 | |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | * Retrieves the user's email address from the model |
149 | 149 | * @return string |
150 | 150 | */ |
151 | - public function getEmail() |
|
151 | + public function getEmail () |
|
152 | 152 | { |
153 | 153 | return $this->_user->email; |
154 | 154 | } |
@@ -107,8 +107,9 @@ |
||
107 | 107 | */ |
108 | 108 | public function save($sendEmail = true) |
109 | 109 | { |
110 | - if (!$this->validate()) |
|
111 | - return false; |
|
110 | + if (!$this->validate()) { |
|
111 | + return false; |
|
112 | + } |
|
112 | 113 | |
113 | 114 | $this->_user = new Users; |
114 | 115 |
@@ -2,94 +2,94 @@ |
||
2 | 2 | |
3 | 3 | class ForgotForm extends CFormModel |
4 | 4 | { |
5 | - /** |
|
6 | - * @var string $email The user's email address |
|
7 | - */ |
|
8 | - public $email; |
|
9 | - |
|
10 | - /** |
|
11 | - * @var Users $_user The user's model |
|
12 | - */ |
|
13 | - private $_user = NULL; |
|
14 | - |
|
15 | - /** |
|
16 | - * Validation rules |
|
17 | - * @return array |
|
18 | - */ |
|
19 | - public function rules() |
|
20 | - { |
|
21 | - return array( |
|
22 | - array('email', 'required'), |
|
23 | - array('email', 'email'), |
|
24 | - array('email', 'exists') |
|
25 | - ); |
|
26 | - } |
|
27 | - |
|
28 | - public function attributeLabels() |
|
29 | - { |
|
30 | - return array( |
|
31 | - 'email' => Yii::t('ciims.models.ForgotForm', 'Email Address') |
|
32 | - ); |
|
33 | - } |
|
34 | - |
|
35 | - /** |
|
36 | - * Determines if we have a user in our database with that email address |
|
37 | - * @param array $attributes |
|
38 | - * @param array $params |
|
39 | - * @return boolean |
|
40 | - */ |
|
41 | - public function exists($attributes, $params) |
|
42 | - { |
|
43 | - $this->_user = Users::model()->findByAttributes(array('email' => $this->email)); |
|
44 | - |
|
45 | - if ($this->_user == NULL) |
|
46 | - { |
|
47 | - $this->addError('email', Yii::t('ciims.models.ForgotForm', 'The email address you entered is either invalid, or does not belong to a user in our system.')); |
|
48 | - return false; |
|
49 | - } |
|
50 | - |
|
51 | - return true; |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * Initiates the password reset process on behalf of the user |
|
56 | - * Generates a unique hash and an expiration time that the hash is valid up until (defaults to 15 minutes) |
|
57 | - * This key will internally expire (but not be expunged) after that time |
|
58 | - */ |
|
59 | - public function initPasswordResetProcess() |
|
60 | - { |
|
61 | - if (!$this->validate()) |
|
62 | - return false; |
|
63 | - |
|
64 | - $hash = Cii::generateSafeHash(); |
|
65 | - $expires = strtotime("+15 minutes"); |
|
66 | - |
|
67 | - $meta = UserMetadata::model()->findByAttributes(array('user_id'=>$this->_user->id, 'key'=>'passwordResetCode')); |
|
68 | - if ($meta === NULL) |
|
69 | - $meta = new UserMetadata; |
|
70 | - |
|
71 | - $meta->user_id = $this->_user->id; |
|
72 | - $meta->key = 'passwordResetCode'; |
|
73 | - $meta->value = $hash; |
|
74 | - $meta->save(); |
|
75 | - |
|
76 | - $meta = UserMetadata::model()->findByAttributes(array('user_id'=>$this->_user->id, 'key'=>'passwordResetExpires')); |
|
77 | - if ($meta === NULL) |
|
78 | - $meta = new UserMetadata; |
|
79 | - |
|
80 | - $meta->user_id = $this->_user->id; |
|
81 | - $meta->key = 'passwordResetExpires'; |
|
82 | - $meta->value = $expires; |
|
83 | - $meta->save(); |
|
84 | - |
|
85 | - $emailSettings = new EmailSettings; |
|
86 | - $emailSettings->send($this->_user, Yii::t('ciims.email', 'Your Password Reset Information'), 'webroot.themes.' . Cii::getConfig('theme', 'default') .'.views.email.forgot', array('user' => $this->_user, 'hash' => $hash), true, true); |
|
87 | - |
|
88 | - // Set success flash |
|
89 | - Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'An email has been sent to {{email}} with further instructions on how to reset your password', array( |
|
90 | - '{{email}}' => $this->email |
|
91 | - ))); |
|
92 | - |
|
93 | - return true; |
|
94 | - } |
|
5 | + /** |
|
6 | + * @var string $email The user's email address |
|
7 | + */ |
|
8 | + public $email; |
|
9 | + |
|
10 | + /** |
|
11 | + * @var Users $_user The user's model |
|
12 | + */ |
|
13 | + private $_user = NULL; |
|
14 | + |
|
15 | + /** |
|
16 | + * Validation rules |
|
17 | + * @return array |
|
18 | + */ |
|
19 | + public function rules() |
|
20 | + { |
|
21 | + return array( |
|
22 | + array('email', 'required'), |
|
23 | + array('email', 'email'), |
|
24 | + array('email', 'exists') |
|
25 | + ); |
|
26 | + } |
|
27 | + |
|
28 | + public function attributeLabels() |
|
29 | + { |
|
30 | + return array( |
|
31 | + 'email' => Yii::t('ciims.models.ForgotForm', 'Email Address') |
|
32 | + ); |
|
33 | + } |
|
34 | + |
|
35 | + /** |
|
36 | + * Determines if we have a user in our database with that email address |
|
37 | + * @param array $attributes |
|
38 | + * @param array $params |
|
39 | + * @return boolean |
|
40 | + */ |
|
41 | + public function exists($attributes, $params) |
|
42 | + { |
|
43 | + $this->_user = Users::model()->findByAttributes(array('email' => $this->email)); |
|
44 | + |
|
45 | + if ($this->_user == NULL) |
|
46 | + { |
|
47 | + $this->addError('email', Yii::t('ciims.models.ForgotForm', 'The email address you entered is either invalid, or does not belong to a user in our system.')); |
|
48 | + return false; |
|
49 | + } |
|
50 | + |
|
51 | + return true; |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * Initiates the password reset process on behalf of the user |
|
56 | + * Generates a unique hash and an expiration time that the hash is valid up until (defaults to 15 minutes) |
|
57 | + * This key will internally expire (but not be expunged) after that time |
|
58 | + */ |
|
59 | + public function initPasswordResetProcess() |
|
60 | + { |
|
61 | + if (!$this->validate()) |
|
62 | + return false; |
|
63 | + |
|
64 | + $hash = Cii::generateSafeHash(); |
|
65 | + $expires = strtotime("+15 minutes"); |
|
66 | + |
|
67 | + $meta = UserMetadata::model()->findByAttributes(array('user_id'=>$this->_user->id, 'key'=>'passwordResetCode')); |
|
68 | + if ($meta === NULL) |
|
69 | + $meta = new UserMetadata; |
|
70 | + |
|
71 | + $meta->user_id = $this->_user->id; |
|
72 | + $meta->key = 'passwordResetCode'; |
|
73 | + $meta->value = $hash; |
|
74 | + $meta->save(); |
|
75 | + |
|
76 | + $meta = UserMetadata::model()->findByAttributes(array('user_id'=>$this->_user->id, 'key'=>'passwordResetExpires')); |
|
77 | + if ($meta === NULL) |
|
78 | + $meta = new UserMetadata; |
|
79 | + |
|
80 | + $meta->user_id = $this->_user->id; |
|
81 | + $meta->key = 'passwordResetExpires'; |
|
82 | + $meta->value = $expires; |
|
83 | + $meta->save(); |
|
84 | + |
|
85 | + $emailSettings = new EmailSettings; |
|
86 | + $emailSettings->send($this->_user, Yii::t('ciims.email', 'Your Password Reset Information'), 'webroot.themes.' . Cii::getConfig('theme', 'default') .'.views.email.forgot', array('user' => $this->_user, 'hash' => $hash), true, true); |
|
87 | + |
|
88 | + // Set success flash |
|
89 | + Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'An email has been sent to {{email}} with further instructions on how to reset your password', array( |
|
90 | + '{{email}}' => $this->email |
|
91 | + ))); |
|
92 | + |
|
93 | + return true; |
|
94 | + } |
|
95 | 95 | } |
@@ -58,15 +58,17 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function initPasswordResetProcess() |
60 | 60 | { |
61 | - if (!$this->validate()) |
|
62 | - return false; |
|
61 | + if (!$this->validate()) { |
|
62 | + return false; |
|
63 | + } |
|
63 | 64 | |
64 | 65 | $hash = Cii::generateSafeHash(); |
65 | 66 | $expires = strtotime("+15 minutes"); |
66 | 67 | |
67 | 68 | $meta = UserMetadata::model()->findByAttributes(array('user_id'=>$this->_user->id, 'key'=>'passwordResetCode')); |
68 | - if ($meta === NULL) |
|
69 | - $meta = new UserMetadata; |
|
69 | + if ($meta === NULL) { |
|
70 | + $meta = new UserMetadata; |
|
71 | + } |
|
70 | 72 | |
71 | 73 | $meta->user_id = $this->_user->id; |
72 | 74 | $meta->key = 'passwordResetCode'; |
@@ -74,8 +76,9 @@ discard block |
||
74 | 76 | $meta->save(); |
75 | 77 | |
76 | 78 | $meta = UserMetadata::model()->findByAttributes(array('user_id'=>$this->_user->id, 'key'=>'passwordResetExpires')); |
77 | - if ($meta === NULL) |
|
78 | - $meta = new UserMetadata; |
|
79 | + if ($meta === NULL) { |
|
80 | + $meta = new UserMetadata; |
|
81 | + } |
|
79 | 82 | |
80 | 83 | $meta->user_id = $this->_user->id; |
81 | 84 | $meta->key = 'passwordResetExpires'; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * Validation rules |
17 | 17 | * @return array |
18 | 18 | */ |
19 | - public function rules() |
|
19 | + public function rules () |
|
20 | 20 | { |
21 | 21 | return array( |
22 | 22 | array('email', 'required'), |
@@ -25,10 +25,10 @@ discard block |
||
25 | 25 | ); |
26 | 26 | } |
27 | 27 | |
28 | - public function attributeLabels() |
|
28 | + public function attributeLabels () |
|
29 | 29 | { |
30 | 30 | return array( |
31 | - 'email' => Yii::t('ciims.models.ForgotForm', 'Email Address') |
|
31 | + 'email' => Yii::t ('ciims.models.ForgotForm', 'Email Address') |
|
32 | 32 | ); |
33 | 33 | } |
34 | 34 | |
@@ -38,13 +38,13 @@ discard block |
||
38 | 38 | * @param array $params |
39 | 39 | * @return boolean |
40 | 40 | */ |
41 | - public function exists($attributes, $params) |
|
41 | + public function exists ($attributes, $params) |
|
42 | 42 | { |
43 | - $this->_user = Users::model()->findByAttributes(array('email' => $this->email)); |
|
43 | + $this->_user = Users::model ()->findByAttributes (array('email' => $this->email)); |
|
44 | 44 | |
45 | 45 | if ($this->_user == NULL) |
46 | 46 | { |
47 | - $this->addError('email', Yii::t('ciims.models.ForgotForm', 'The email address you entered is either invalid, or does not belong to a user in our system.')); |
|
47 | + $this->addError ('email', Yii::t ('ciims.models.ForgotForm', 'The email address you entered is either invalid, or does not belong to a user in our system.')); |
|
48 | 48 | return false; |
49 | 49 | } |
50 | 50 | |
@@ -56,37 +56,37 @@ discard block |
||
56 | 56 | * Generates a unique hash and an expiration time that the hash is valid up until (defaults to 15 minutes) |
57 | 57 | * This key will internally expire (but not be expunged) after that time |
58 | 58 | */ |
59 | - public function initPasswordResetProcess() |
|
59 | + public function initPasswordResetProcess () |
|
60 | 60 | { |
61 | - if (!$this->validate()) |
|
61 | + if (!$this->validate ()) |
|
62 | 62 | return false; |
63 | 63 | |
64 | - $hash = Cii::generateSafeHash(); |
|
65 | - $expires = strtotime("+15 minutes"); |
|
64 | + $hash = Cii::generateSafeHash (); |
|
65 | + $expires = strtotime ("+15 minutes"); |
|
66 | 66 | |
67 | - $meta = UserMetadata::model()->findByAttributes(array('user_id'=>$this->_user->id, 'key'=>'passwordResetCode')); |
|
67 | + $meta = UserMetadata::model ()->findByAttributes (array('user_id'=>$this->_user->id, 'key'=>'passwordResetCode')); |
|
68 | 68 | if ($meta === NULL) |
69 | 69 | $meta = new UserMetadata; |
70 | 70 | |
71 | 71 | $meta->user_id = $this->_user->id; |
72 | 72 | $meta->key = 'passwordResetCode'; |
73 | 73 | $meta->value = $hash; |
74 | - $meta->save(); |
|
74 | + $meta->save (); |
|
75 | 75 | |
76 | - $meta = UserMetadata::model()->findByAttributes(array('user_id'=>$this->_user->id, 'key'=>'passwordResetExpires')); |
|
76 | + $meta = UserMetadata::model ()->findByAttributes (array('user_id'=>$this->_user->id, 'key'=>'passwordResetExpires')); |
|
77 | 77 | if ($meta === NULL) |
78 | 78 | $meta = new UserMetadata; |
79 | 79 | |
80 | 80 | $meta->user_id = $this->_user->id; |
81 | 81 | $meta->key = 'passwordResetExpires'; |
82 | 82 | $meta->value = $expires; |
83 | - $meta->save(); |
|
83 | + $meta->save (); |
|
84 | 84 | |
85 | 85 | $emailSettings = new EmailSettings; |
86 | - $emailSettings->send($this->_user, Yii::t('ciims.email', 'Your Password Reset Information'), 'webroot.themes.' . Cii::getConfig('theme', 'default') .'.views.email.forgot', array('user' => $this->_user, 'hash' => $hash), true, true); |
|
86 | + $emailSettings->send ($this->_user, Yii::t ('ciims.email', 'Your Password Reset Information'), 'webroot.themes.'.Cii::getConfig ('theme', 'default').'.views.email.forgot', array('user' => $this->_user, 'hash' => $hash), true, true); |
|
87 | 87 | |
88 | 88 | // Set success flash |
89 | - Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'An email has been sent to {{email}} with further instructions on how to reset your password', array( |
|
89 | + Yii::app ()->user->setFlash ('success', Yii::t ('ciims.controllers.Site', 'An email has been sent to {{email}} with further instructions on how to reset your password', array( |
|
90 | 90 | '{{email}}' => $this->email |
91 | 91 | ))); |
92 | 92 |
@@ -2,105 +2,105 @@ |
||
2 | 2 | |
3 | 3 | class InvitationForm extends CFormModel |
4 | 4 | { |
5 | - /** |
|
6 | - * The email of the user to invite |
|
7 | - * @var string $email |
|
8 | - */ |
|
9 | - public $email; |
|
5 | + /** |
|
6 | + * The email of the user to invite |
|
7 | + * @var string $email |
|
8 | + */ |
|
9 | + public $email; |
|
10 | 10 | |
11 | - /** |
|
12 | - * Validation rules |
|
13 | - * @return array |
|
14 | - */ |
|
15 | - public function rules() |
|
16 | - { |
|
17 | - return array( |
|
18 | - array('email', 'required'), |
|
19 | - array('email', 'email'), |
|
20 | - array('email', 'userExists') |
|
21 | - ); |
|
22 | - } |
|
11 | + /** |
|
12 | + * Validation rules |
|
13 | + * @return array |
|
14 | + */ |
|
15 | + public function rules() |
|
16 | + { |
|
17 | + return array( |
|
18 | + array('email', 'required'), |
|
19 | + array('email', 'email'), |
|
20 | + array('email', 'userExists') |
|
21 | + ); |
|
22 | + } |
|
23 | 23 | |
24 | - /** |
|
25 | - * Validates that a user with that email address isn't already invited |
|
26 | - * @param array $attributes |
|
27 | - * @param array $params |
|
28 | - * @return boolean |
|
29 | - */ |
|
30 | - public function userExists($attributes, $params) |
|
31 | - { |
|
32 | - $user = Users::model()->findByAttributes(array('email' => $this->email)); |
|
24 | + /** |
|
25 | + * Validates that a user with that email address isn't already invited |
|
26 | + * @param array $attributes |
|
27 | + * @param array $params |
|
28 | + * @return boolean |
|
29 | + */ |
|
30 | + public function userExists($attributes, $params) |
|
31 | + { |
|
32 | + $user = Users::model()->findByAttributes(array('email' => $this->email)); |
|
33 | 33 | |
34 | - if ($user == NULL) |
|
35 | - return true; |
|
34 | + if ($user == NULL) |
|
35 | + return true; |
|
36 | 36 | |
37 | - $this->addError('email', Yii::t('ciims.models.InvitationForm', 'A user with that email already exists.')); |
|
38 | - return false; |
|
39 | - } |
|
37 | + $this->addError('email', Yii::t('ciims.models.InvitationForm', 'A user with that email already exists.')); |
|
38 | + return false; |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Attribute labels |
|
43 | - * @return array |
|
44 | - */ |
|
45 | - public function attributeLabels() |
|
46 | - { |
|
47 | - return array( |
|
48 | - 'email' => Yii::t('ciims.models.InvitationForm', 'Email Address') |
|
49 | - ); |
|
50 | - } |
|
41 | + /** |
|
42 | + * Attribute labels |
|
43 | + * @return array |
|
44 | + */ |
|
45 | + public function attributeLabels() |
|
46 | + { |
|
47 | + return array( |
|
48 | + 'email' => Yii::t('ciims.models.InvitationForm', 'Email Address') |
|
49 | + ); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Sends an invite to a new user |
|
54 | - * @return boolean |
|
55 | - */ |
|
56 | - public function invite() |
|
57 | - { |
|
58 | - if (!$this->validate()) |
|
59 | - return false; |
|
52 | + /** |
|
53 | + * Sends an invite to a new user |
|
54 | + * @return boolean |
|
55 | + */ |
|
56 | + public function invite() |
|
57 | + { |
|
58 | + if (!$this->validate()) |
|
59 | + return false; |
|
60 | 60 | |
61 | - $user = new Users; |
|
62 | - $user->attributes = array( |
|
63 | - 'email' => $this->email, |
|
64 | - 'firstName' => null, |
|
65 | - 'lastName' => null, |
|
66 | - 'displayName' => null, |
|
67 | - 'password' => null, |
|
68 | - 'user_role' => 5, |
|
69 | - 'status' => Users::PENDING_INVITATION |
|
70 | - ); |
|
61 | + $user = new Users; |
|
62 | + $user->attributes = array( |
|
63 | + 'email' => $this->email, |
|
64 | + 'firstName' => null, |
|
65 | + 'lastName' => null, |
|
66 | + 'displayName' => null, |
|
67 | + 'password' => null, |
|
68 | + 'user_role' => 5, |
|
69 | + 'status' => Users::PENDING_INVITATION |
|
70 | + ); |
|
71 | 71 | |
72 | - // Create a new user, but bypass validation |
|
73 | - if ($user->save(false)) |
|
74 | - { |
|
75 | - $meta = new UserMetadata; |
|
76 | - $meta->attributes = array( |
|
77 | - 'user_id' => $user->id, |
|
78 | - 'key' => 'invitationKey', |
|
79 | - 'value' => Cii::generateSafeHash() |
|
80 | - ); |
|
72 | + // Create a new user, but bypass validation |
|
73 | + if ($user->save(false)) |
|
74 | + { |
|
75 | + $meta = new UserMetadata; |
|
76 | + $meta->attributes = array( |
|
77 | + 'user_id' => $user->id, |
|
78 | + 'key' => 'invitationKey', |
|
79 | + 'value' => Cii::generateSafeHash() |
|
80 | + ); |
|
81 | 81 | |
82 | - // If the key was savedm send the email out |
|
83 | - if ($meta->save()) |
|
84 | - { |
|
85 | - $emailSettings = new EmailSettings; |
|
86 | - $emailSettings->send( |
|
87 | - $user, |
|
88 | - Yii::t('ciims.models.InvitationForm', "You've Been Invited..."), |
|
89 | - 'webroot.themes.' . Cii::getConfig('theme', 'default') .'.views.email.invite', |
|
90 | - array( |
|
91 | - 'user' => $user, |
|
92 | - 'hash' => $meta->value |
|
93 | - ), |
|
94 | - true, |
|
95 | - true |
|
96 | - ); |
|
82 | + // If the key was savedm send the email out |
|
83 | + if ($meta->save()) |
|
84 | + { |
|
85 | + $emailSettings = new EmailSettings; |
|
86 | + $emailSettings->send( |
|
87 | + $user, |
|
88 | + Yii::t('ciims.models.InvitationForm', "You've Been Invited..."), |
|
89 | + 'webroot.themes.' . Cii::getConfig('theme', 'default') .'.views.email.invite', |
|
90 | + array( |
|
91 | + 'user' => $user, |
|
92 | + 'hash' => $meta->value |
|
93 | + ), |
|
94 | + true, |
|
95 | + true |
|
96 | + ); |
|
97 | 97 | |
98 | - return true; |
|
99 | - } |
|
98 | + return true; |
|
99 | + } |
|
100 | 100 | |
101 | - $user->delete(); |
|
102 | - } |
|
101 | + $user->delete(); |
|
102 | + } |
|
103 | 103 | |
104 | - return false; |
|
105 | - } |
|
104 | + return false; |
|
105 | + } |
|
106 | 106 | } |
107 | 107 | \ No newline at end of file |
@@ -31,8 +31,9 @@ discard block |
||
31 | 31 | { |
32 | 32 | $user = Users::model()->findByAttributes(array('email' => $this->email)); |
33 | 33 | |
34 | - if ($user == NULL) |
|
35 | - return true; |
|
34 | + if ($user == NULL) { |
|
35 | + return true; |
|
36 | + } |
|
36 | 37 | |
37 | 38 | $this->addError('email', Yii::t('ciims.models.InvitationForm', 'A user with that email already exists.')); |
38 | 39 | return false; |
@@ -55,8 +56,9 @@ discard block |
||
55 | 56 | */ |
56 | 57 | public function invite() |
57 | 58 | { |
58 | - if (!$this->validate()) |
|
59 | - return false; |
|
59 | + if (!$this->validate()) { |
|
60 | + return false; |
|
61 | + } |
|
60 | 62 | |
61 | 63 | $user = new Users; |
62 | 64 | $user->attributes = array( |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | * Validation rules |
13 | 13 | * @return array |
14 | 14 | */ |
15 | - public function rules() |
|
15 | + public function rules () |
|
16 | 16 | { |
17 | 17 | return array( |
18 | 18 | array('email', 'required'), |
@@ -27,14 +27,14 @@ discard block |
||
27 | 27 | * @param array $params |
28 | 28 | * @return boolean |
29 | 29 | */ |
30 | - public function userExists($attributes, $params) |
|
30 | + public function userExists ($attributes, $params) |
|
31 | 31 | { |
32 | - $user = Users::model()->findByAttributes(array('email' => $this->email)); |
|
32 | + $user = Users::model ()->findByAttributes (array('email' => $this->email)); |
|
33 | 33 | |
34 | 34 | if ($user == NULL) |
35 | 35 | return true; |
36 | 36 | |
37 | - $this->addError('email', Yii::t('ciims.models.InvitationForm', 'A user with that email already exists.')); |
|
37 | + $this->addError ('email', Yii::t ('ciims.models.InvitationForm', 'A user with that email already exists.')); |
|
38 | 38 | return false; |
39 | 39 | } |
40 | 40 | |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | * Attribute labels |
43 | 43 | * @return array |
44 | 44 | */ |
45 | - public function attributeLabels() |
|
45 | + public function attributeLabels () |
|
46 | 46 | { |
47 | 47 | return array( |
48 | - 'email' => Yii::t('ciims.models.InvitationForm', 'Email Address') |
|
48 | + 'email' => Yii::t ('ciims.models.InvitationForm', 'Email Address') |
|
49 | 49 | ); |
50 | 50 | } |
51 | 51 | |
@@ -53,9 +53,9 @@ discard block |
||
53 | 53 | * Sends an invite to a new user |
54 | 54 | * @return boolean |
55 | 55 | */ |
56 | - public function invite() |
|
56 | + public function invite () |
|
57 | 57 | { |
58 | - if (!$this->validate()) |
|
58 | + if (!$this->validate ()) |
|
59 | 59 | return false; |
60 | 60 | |
61 | 61 | $user = new Users; |
@@ -70,23 +70,23 @@ discard block |
||
70 | 70 | ); |
71 | 71 | |
72 | 72 | // Create a new user, but bypass validation |
73 | - if ($user->save(false)) |
|
73 | + if ($user->save (false)) |
|
74 | 74 | { |
75 | 75 | $meta = new UserMetadata; |
76 | 76 | $meta->attributes = array( |
77 | 77 | 'user_id' => $user->id, |
78 | 78 | 'key' => 'invitationKey', |
79 | - 'value' => Cii::generateSafeHash() |
|
79 | + 'value' => Cii::generateSafeHash () |
|
80 | 80 | ); |
81 | 81 | |
82 | 82 | // If the key was savedm send the email out |
83 | - if ($meta->save()) |
|
83 | + if ($meta->save ()) |
|
84 | 84 | { |
85 | 85 | $emailSettings = new EmailSettings; |
86 | - $emailSettings->send( |
|
86 | + $emailSettings->send ( |
|
87 | 87 | $user, |
88 | - Yii::t('ciims.models.InvitationForm', "You've Been Invited..."), |
|
89 | - 'webroot.themes.' . Cii::getConfig('theme', 'default') .'.views.email.invite', |
|
88 | + Yii::t ('ciims.models.InvitationForm', "You've Been Invited..."), |
|
89 | + 'webroot.themes.'.Cii::getConfig ('theme', 'default').'.views.email.invite', |
|
90 | 90 | array( |
91 | 91 | 'user' => $user, |
92 | 92 | 'hash' => $meta->value |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | return true; |
99 | 99 | } |
100 | 100 | |
101 | - $user->delete(); |
|
101 | + $user->delete (); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | return false; |
@@ -2,75 +2,75 @@ |
||
2 | 2 | |
3 | 3 | class InviteForm extends CFormModel |
4 | 4 | { |
5 | - /** |
|
6 | - * @var $id int The User's ID that we are working with |
|
7 | - */ |
|
8 | - public $id = NULL; |
|
5 | + /** |
|
6 | + * @var $id int The User's ID that we are working with |
|
7 | + */ |
|
8 | + public $id = NULL; |
|
9 | 9 | |
10 | - /** |
|
11 | - * @var $displayName string The user's requested display name |
|
12 | - */ |
|
13 | - public $username = NULL; |
|
10 | + /** |
|
11 | + * @var $displayName string The user's requested display name |
|
12 | + */ |
|
13 | + public $username = NULL; |
|
14 | 14 | |
15 | - /** |
|
16 | - * @var $email string |
|
17 | - */ |
|
18 | - public $email = NULL; |
|
15 | + /** |
|
16 | + * @var $email string |
|
17 | + */ |
|
18 | + public $email = NULL; |
|
19 | 19 | |
20 | - /** |
|
21 | - * @var $password string The user's selected password |
|
22 | - */ |
|
23 | - public $password = NULL; |
|
20 | + /** |
|
21 | + * @var $password string The user's selected password |
|
22 | + */ |
|
23 | + public $password = NULL; |
|
24 | 24 | |
25 | - /** |
|
26 | - * Validation Rules |
|
27 | - * @return array |
|
28 | - */ |
|
29 | - public function rules() |
|
30 | - { |
|
31 | - return array( |
|
32 | - array('id, username, password', 'required'), |
|
33 | - array('username, password', 'length', 'max' => 255) |
|
34 | - ); |
|
35 | - } |
|
25 | + /** |
|
26 | + * Validation Rules |
|
27 | + * @return array |
|
28 | + */ |
|
29 | + public function rules() |
|
30 | + { |
|
31 | + return array( |
|
32 | + array('id, username, password', 'required'), |
|
33 | + array('username, password', 'length', 'max' => 255) |
|
34 | + ); |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Attribute labels |
|
39 | - * @return array |
|
40 | - */ |
|
41 | - public function attributeLabels() |
|
42 | - { |
|
43 | - return array( |
|
44 | - 'id' => Yii::t('ciims.models.InviteForm', 'ID'), |
|
45 | - 'username' => Yii::t('ciims.models.InviteForm', 'Username'), |
|
46 | - 'password' => Yii::t('ciims.models.InviteForm', 'Password'), |
|
47 | - ); |
|
48 | - } |
|
37 | + /** |
|
38 | + * Attribute labels |
|
39 | + * @return array |
|
40 | + */ |
|
41 | + public function attributeLabels() |
|
42 | + { |
|
43 | + return array( |
|
44 | + 'id' => Yii::t('ciims.models.InviteForm', 'ID'), |
|
45 | + 'username' => Yii::t('ciims.models.InviteForm', 'Username'), |
|
46 | + 'password' => Yii::t('ciims.models.InviteForm', 'Password'), |
|
47 | + ); |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * Actually creates the users |
|
52 | - * @return bool If the user was created |
|
53 | - */ |
|
54 | - public function acceptInvite() |
|
55 | - { |
|
56 | - if (!$this->validate()) |
|
57 | - return false; |
|
50 | + /** |
|
51 | + * Actually creates the users |
|
52 | + * @return bool If the user was created |
|
53 | + */ |
|
54 | + public function acceptInvite() |
|
55 | + { |
|
56 | + if (!$this->validate()) |
|
57 | + return false; |
|
58 | 58 | |
59 | - $user = Users::model()->findByPk($this->id); |
|
59 | + $user = Users::model()->findByPk($this->id); |
|
60 | 60 | |
61 | - // Bcrypt the initial password instead of just using the basic hashing mechanism |
|
62 | - $hash = Users::model()->encryptHash($this->email, $this->password, Yii::app()->params['encryptionKey']); |
|
63 | - $cost = Cii::getBcryptCost(); |
|
61 | + // Bcrypt the initial password instead of just using the basic hashing mechanism |
|
62 | + $hash = Users::model()->encryptHash($this->email, $this->password, Yii::app()->params['encryptionKey']); |
|
63 | + $cost = Cii::getBcryptCost(); |
|
64 | 64 | |
65 | - $this->password = password_hash($hash, PASSWORD_BCRYPT, array('cost' => $cost)); |
|
65 | + $this->password = password_hash($hash, PASSWORD_BCRYPT, array('cost' => $cost)); |
|
66 | 66 | |
67 | - $user->attributes = array( |
|
68 | - 'email' => $this->email, |
|
69 | - 'password' => $this->password, |
|
70 | - 'username' => $this->username, |
|
71 | - 'status' => Users::ACTIVE |
|
72 | - ); |
|
67 | + $user->attributes = array( |
|
68 | + 'email' => $this->email, |
|
69 | + 'password' => $this->password, |
|
70 | + 'username' => $this->username, |
|
71 | + 'status' => Users::ACTIVE |
|
72 | + ); |
|
73 | 73 | |
74 | - return $user->save(); |
|
75 | - } |
|
74 | + return $user->save(); |
|
75 | + } |
|
76 | 76 | } |
77 | 77 | \ No newline at end of file |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * Validation Rules |
27 | 27 | * @return array |
28 | 28 | */ |
29 | - public function rules() |
|
29 | + public function rules () |
|
30 | 30 | { |
31 | 31 | return array( |
32 | 32 | array('id, username, password', 'required'), |
@@ -38,12 +38,12 @@ discard block |
||
38 | 38 | * Attribute labels |
39 | 39 | * @return array |
40 | 40 | */ |
41 | - public function attributeLabels() |
|
41 | + public function attributeLabels () |
|
42 | 42 | { |
43 | 43 | return array( |
44 | - 'id' => Yii::t('ciims.models.InviteForm', 'ID'), |
|
45 | - 'username' => Yii::t('ciims.models.InviteForm', 'Username'), |
|
46 | - 'password' => Yii::t('ciims.models.InviteForm', 'Password'), |
|
44 | + 'id' => Yii::t ('ciims.models.InviteForm', 'ID'), |
|
45 | + 'username' => Yii::t ('ciims.models.InviteForm', 'Username'), |
|
46 | + 'password' => Yii::t ('ciims.models.InviteForm', 'Password'), |
|
47 | 47 | ); |
48 | 48 | } |
49 | 49 | |
@@ -51,18 +51,18 @@ discard block |
||
51 | 51 | * Actually creates the users |
52 | 52 | * @return bool If the user was created |
53 | 53 | */ |
54 | - public function acceptInvite() |
|
54 | + public function acceptInvite () |
|
55 | 55 | { |
56 | - if (!$this->validate()) |
|
56 | + if (!$this->validate ()) |
|
57 | 57 | return false; |
58 | 58 | |
59 | - $user = Users::model()->findByPk($this->id); |
|
59 | + $user = Users::model ()->findByPk ($this->id); |
|
60 | 60 | |
61 | 61 | // Bcrypt the initial password instead of just using the basic hashing mechanism |
62 | - $hash = Users::model()->encryptHash($this->email, $this->password, Yii::app()->params['encryptionKey']); |
|
63 | - $cost = Cii::getBcryptCost(); |
|
62 | + $hash = Users::model ()->encryptHash ($this->email, $this->password, Yii::app ()->params['encryptionKey']); |
|
63 | + $cost = Cii::getBcryptCost (); |
|
64 | 64 | |
65 | - $this->password = password_hash($hash, PASSWORD_BCRYPT, array('cost' => $cost)); |
|
65 | + $this->password = password_hash ($hash, PASSWORD_BCRYPT, array('cost' => $cost)); |
|
66 | 66 | |
67 | 67 | $user->attributes = array( |
68 | 68 | 'email' => $this->email, |
@@ -71,6 +71,6 @@ discard block |
||
71 | 71 | 'status' => Users::ACTIVE |
72 | 72 | ); |
73 | 73 | |
74 | - return $user->save(); |
|
74 | + return $user->save (); |
|
75 | 75 | } |
76 | 76 | } |
77 | 77 | \ No newline at end of file |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -class InviteForm extends CFormModel |
|
4 | -{ |
|
3 | +class InviteForm extends CFormModel |
|
4 | +{ |
|
5 | 5 | /** |
6 | 6 | * @var $id int The User's ID that we are working with |
7 | 7 | */ |
@@ -26,8 +26,8 @@ discard block |
||
26 | 26 | * Validation Rules |
27 | 27 | * @return array |
28 | 28 | */ |
29 | - public function rules() |
|
30 | - { |
|
29 | + public function rules() |
|
30 | + { |
|
31 | 31 | return array( |
32 | 32 | array('id, username, password', 'required'), |
33 | 33 | array('username, password', 'length', 'max' => 255) |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | * Attribute labels |
39 | 39 | * @return array |
40 | 40 | */ |
41 | - public function attributeLabels() |
|
42 | - { |
|
41 | + public function attributeLabels() |
|
42 | + { |
|
43 | 43 | return array( |
44 | 44 | 'id' => Yii::t('ciims.models.InviteForm', 'ID'), |
45 | 45 | 'username' => Yii::t('ciims.models.InviteForm', 'Username'), |
@@ -51,10 +51,11 @@ discard block |
||
51 | 51 | * Actually creates the users |
52 | 52 | * @return bool If the user was created |
53 | 53 | */ |
54 | - public function acceptInvite() |
|
55 | - { |
|
56 | - if (!$this->validate()) |
|
57 | - return false; |
|
54 | + public function acceptInvite() |
|
55 | + { |
|
56 | + if (!$this->validate()) { |
|
57 | + return false; |
|
58 | + } |
|
58 | 59 | |
59 | 60 | $user = Users::model()->findByPk($this->id); |
60 | 61 |