Account   A
last analyzed

Complexity

Total Complexity 15

Size/Duplication

Total Lines 139
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 15
lcom 1
cbo 1
dl 0
loc 139
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A model() 0 4 1
A tableName() 0 4 1
B rules() 0 27 1
A attributeLabels() 0 15 2
A validatePassword() 0 4 1
A generateCode() 0 4 1
A authenticate() 0 13 4
A login() 0 17 3
A findByEmail() 0 4 1
1
<?php
2
/**
3
 * This is the model class for table "account".
4
 *
5
 * The followings are the available columns in table 'account':
6
 * @property integer $id
7
 * @property string $email
8
 * @property string $password
9
 * @property string $verifyCode
10
 * @property string $verified
11
 * @property string $emailTemp
12
 */
13
class Account extends CActiveRecord
14
{
15
    public $oldPassword;
16
    public $confirmPassword;
17
    public $acceptTerms;
18
19
    private $identity;
20
21
    /**
22
     * Returns the static model of the specified AR class.
23
     * @param string $className active record class name.
24
     * @return Account the static model class
25
     */
26
    public static function model($className = __CLASS__)
27
    {
28
        return parent::model($className);
29
    }
30
31
    /**
32
     * @return string the associated database table name
33
     */
34
    public function tableName()
35
    {
36
        return 'account';
37
    }
38
39
    /**
40
     * @return array validation rules for model attributes.
41
     */
42
    public function rules()
43
    {
44
        return array(
45
            array('oldPassword', 'required', 'on'=>'changePassword', 'message'=>'A {attribute} kitöltése kötelező.'),
46
            array('username', 'required', 'on'=>array('completeSignup', 'signupNoMail'), 'message'=>'A {attribute} kitöltése kötelező.'),
47
            array('username', 'unique', 'on'=>array('completeSignup', 'signupNoMail'), 'message'=>'A választott {attribute} már foglalt.'),
48
            array('username', 'length', 'min'=>4, 'max'=>16, 'on'=>array('login', 'completeSignup', 'signupNoMail')),
49
            array('username', 'match', 'pattern' => '/^[A-Za-z0-9-]+$/u', 'on'=>array('login','completeSignup', 'signupNoMail'), 'message'=>'A {attribute} csak a következő karakterekből állhat: A-Z, a-z, 0-9 és -'),
50
            array('username', 'match', 'pattern' => '/^[A-Za-z]+/u', 'on'=>array('login', 'completeSignup', 'signupNoMail'), 'message'=>'A {attribute} csak a betűvel kezdődhet.'),
51
            array('username', 'match', 'pattern' => '/(\-).*(\-)/u', 'not'=>true, 'on'=>array('login', 'completeSignup', 'signupNoMail'), 'message'=>'A {attribute} csak egy kötőjelet tartalmazhat.'),
52
            array('email', 'required', 'on'=>array('signupWithMail','login','changeEmail','resetPassword'), 'message'=>'Az {attribute} kitöltése kötelező.'),
53
            array('email', 'length', 'max'=>128, 'on'=>array('signupWithMail','changeEmail')),
54
            array('email', 'email', 'on'=>array('signupWithMail','changeEmail'), 'message'=>'Az {attribute} nem érvényes.'),
55
            array('email', 'unique', 'on'=>array('signupWithMail','changeEmail'), 'message'=>'A választott {attribute} már foglalt.'),
56
            array('email', 'exist', 'on'=>'resetPassword'),
57
            array('password', 'required', 'on'=>array('login', 'completeSignup', 'signupNoMail', 'changeEmail','changePassword','completeResetPassword','desactivate'), 'message'=>'A {attribute} kitöltése kötelező.'),
58
            array('password', 'length', 'min'=>6, 'max'=>255, 'on'=>array('completeSignup', 'signupNoMail','changePassword','completeResetPassword')),
59
            array('password', 'match', 'pattern' => '/[A-Za-z]/u', 'on'=>array('completeSignup', 'signupNoMail','changePassword','completeResetPassword'), 'message'=>'A {attribute}nak tartalmaznia kell legalább egy betűt: A-Z, a-z'),
60
            array('password', 'match', 'pattern' => '/[0-9]/u', 'on'=>array('completeSignup', 'signupNoMail','changePassword','completeResetPassword'), 'message'=>'A {attribute}nak tartalmaznia kell legalább egy számot.'),
61
            array('confirmPassword', 'required', 'on'=>array('changePassword','completeResetPassword', 'signupNoMail'), 'message'=>'A {attribute} kitöltése kötelező.'),
62
            array('confirmPassword', 'compare', 'compareAttribute'=>'password', 'on'=>array('changePassword','completeResetPassword', 'signupNoMail')),
63
            array('password', 'authenticate', 'on'=>'login'),
64
            array('verifyCode, verified', 'safe', 'on'=>'completeSignup'),
65
            array('resetPasswordCode, passwordReset', 'safe', 'on'=>'completeResetPassword'),
66
            array('acceptTerms', 'required', 'on'=>array('completeSignup', 'signupNoMail'), 'requiredValue'=>1, 'message'=>'A regisztrációhoz el kell fogadni az általános felhasználói feltételeket.'),
67
        );
68
    }
69
70
    public function attributeLabels()
71
    {
72
        $attributes = [
73
            'username' => 'felhasználónév',
74
            'email' => 'e-mail cím',
75
            'password' => 'jelszó',
76
            'oldPassword' => 'régi jelszó',
77
            'confirmPassword' => 'jelszó újra',
78
            'acceptTerms' => 'Elfogadom az ÁFF-et',
79
            ];
80
        if ($this->scenario == 'login') {
81
            $attributes['email'] = 'e-mail vagy felh.név';
82
        }
83
        return $attributes;
84
    }
85
86
    /**
87
     * @return boolean
88
     */
89
    public function validatePassword($password)
90
    {
91
        return password_verify($password, $this->password);
92
    }
93
94
    /**
95
     * Generates a random code
96
     */
97
    public function generateCode()
98
    {
99
        return md5(mt_rand());
100
    }
101
102
    /**
103
     * Authenticates the password.
104
     * This is the 'authenticate' validator as declared in rules().
105
     */
106
    public function authenticate($attribute, $params)
107
    {
108
        if (!$this->hasErrors()) {
109
            $this->identity=new UserIdentity($this->email, $this->password);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
110
            if (!$this->identity->authenticate()) {
111
                if ($this->identity->findEmail) {
0 ignored issues
show
Bug introduced by
The property findEmail cannot be accessed from this context as it is declared private in class UserIdentity.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
112
                    $this->addError('validation', 'A megadott e-mail cím és jelszó nem érvényes.');
113
                } else {
114
                    $this->addError('validation', 'A megadott felhasználónév és jelszó nem érvényes.');
115
                }
116
            }
117
        }
118
    }
119
120
    /**
121
     * Logs in the user using the given username and password in the model.
122
     * @return boolean whether login is successful
123
     */
124
    public function login()
125
    {
126
        if ($this->identity===null) {
127
            $this->identity=new UserIdentity($this->email, $this->password);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned correctly; expected 1 space but found 0 spaces

This check looks for improperly formatted assignments.

Every assignment must have exactly one space before and one space after the equals operator.

To illustrate:

$a = "a";
$ab = "ab";
$abc = "abc";

will have no issues, while

$a   = "a";
$ab  = "ab";
$abc = "abc";

will report issues in lines 1 and 2.

Loading history...
128
            $this->identity->authenticate();
129
        }
130
131
        if ($this->identity->errorCode===UserIdentity::ERROR_NONE) {
132
            $duration = 3600*24*30; // 30 days
133
            Yii::app()->user->login($this->identity, $duration);
134
            Yii::app()->session['uid'] = $this->identity->uid;
0 ignored issues
show
Bug introduced by
The property uid cannot be accessed from this context as it is declared private in class UserIdentity.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
135
136
            return true;
137
        } else {
138
            return false;
139
        }
140
    }
141
142
    /**
143
     * Finds an account by email
144
     * @param string $email The email
145
     * @return Account
146
     */
147
    public function findByEmail($email)
148
    {
149
        return $this->find('LOWER(email)=?', array(strtolower($email)));
150
    }
151
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
152