InviteForm::attributeLabels()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
class InviteForm extends CFormModel
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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
}