1
|
|
|
<?php
|
2
|
|
|
|
3
|
|
|
class InviteForm extends CFormModel
|
|
|
|
|
4
|
|
|
{
|
5
|
|
|
/**
|
6
|
|
|
* @var $id int The User's ID that we are working with
|
7
|
|
|
*/
|
8
|
|
|
public $id = NULL;
|
9
|
|
|
|
10
|
|
|
/**
|
11
|
|
|
* @var $displayName string The user's requested display name
|
12
|
|
|
*/
|
13
|
|
|
public $username = NULL;
|
14
|
|
|
|
15
|
|
|
/**
|
16
|
|
|
* @var $email string
|
17
|
|
|
*/
|
18
|
|
|
public $email = NULL;
|
19
|
|
|
|
20
|
|
|
/**
|
21
|
|
|
* @var $password string The user's selected password
|
22
|
|
|
*/
|
23
|
|
|
public $password = NULL;
|
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
|
|
|
}
|
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
|
|
|
}
|
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;
|
58
|
|
|
|
59
|
|
|
$user = Users::model()->findByPk($this->id);
|
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();
|
64
|
|
|
|
65
|
|
|
$this->password = password_hash($hash, PASSWORD_BCRYPT, array('cost' => $cost));
|
66
|
|
|
|
67
|
|
|
$user->attributes = array(
|
68
|
|
|
'email' => $this->email,
|
69
|
|
|
'password' => $this->password,
|
70
|
|
|
'username' => $this->username,
|
71
|
|
|
'status' => Users::ACTIVE
|
72
|
|
|
);
|
73
|
|
|
|
74
|
|
|
return $user->save();
|
75
|
|
|
}
|
76
|
|
|
} |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.