1
|
|
|
<?php |
2
|
|
|
class SetupController extends GameController |
3
|
|
|
{ |
4
|
|
|
public function actionPassword() |
5
|
|
|
{ |
6
|
|
|
$model=new Account('changePassword'); |
7
|
|
|
|
8
|
|
|
if (isset($_POST['Account'])) { |
9
|
|
|
$model->attributes=$_POST['Account']; |
10
|
|
|
if ($model->validate()) { |
11
|
|
|
$account=$this->loadModel(Yii::app()->player->uid); |
12
|
|
|
|
13
|
|
|
if ($account->validatePassword($model->oldPassword)) { |
14
|
|
|
$account->password = password_hash($model->password, PASSWORD_BCRYPT); |
15
|
|
|
$account->save(false); |
16
|
|
|
|
17
|
|
|
Yii::app()->user->setFlash('success', 'A jelszócsere sikerült.'); |
18
|
|
|
$this->redirect(['/player']); |
19
|
|
|
} else { |
20
|
|
|
$model->addError('oldPassword', 'A megadott régi jelszó nem érvényes.'); |
21
|
|
|
} |
22
|
|
|
} |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
$this->render('changePassword', ['model'=>$model]); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function actionEmail() |
29
|
|
|
{ |
30
|
|
|
$model=new Account('changeEmail'); |
31
|
|
|
$account = $this->loadModel(Yii::app()->player->uid); |
32
|
|
|
|
33
|
|
|
if (isset($_POST['Account'])) { |
34
|
|
|
$model->attributes=$_POST['Account']; |
35
|
|
|
if ($model->validate()) { |
36
|
|
|
if ($account->validatePassword($model->password)) { |
37
|
|
|
if (!$account->changeMailCode) { |
38
|
|
|
$account->changeMailCode = $account->generateCode(); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
Account::model()->updateByPk(Yii::app()->player->uid, array( |
42
|
|
|
'changeMailCode' => $account->changeMailCode, |
43
|
|
|
'emailTemp' => $model->email |
44
|
|
|
)); |
45
|
|
|
|
46
|
|
|
// Send verification mail |
47
|
|
|
$mail=Yii::app()->smtpmail; |
48
|
|
|
$mail->CharSet = 'utf-8'; |
49
|
|
|
$mail->SetFrom('[email protected]', 'ced.local'); //todo: activate sender |
50
|
|
|
$mail->Subject = "Carp-e Diem e-mail cím beállítása"; |
51
|
|
|
$message = $this->renderPartial('_changeEmail', ['model'=>$account], true); |
52
|
|
|
$mail->MsgHTML($message); |
53
|
|
|
$mail->AddAddress($model->email, ""); |
54
|
|
|
$sent = $mail->Send(); |
55
|
|
|
if (!$sent) { |
56
|
|
|
Yii::app()->user->setFlash('error', 'Az új e-mail cím aktiválásához szükséges információkat nem sikerült elküldeni. Kérlek próbálkozz később.'); |
57
|
|
|
} else { |
58
|
|
|
Yii::app()->user->setFlash('success', 'Az új e-mail cím aktiválásához szükséges teendőket elküldtük e-mailben.'); |
59
|
|
|
$this->redirect('email'); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
} else { |
63
|
|
|
$model->addError('password', 'A megadott jelszó nem érvényes.'); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
$this->render('changeEmail', [ |
69
|
|
|
'model'=>$model, |
70
|
|
|
'account'=>$account, |
71
|
|
|
]); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Returns the data model based on the primary key given in the GET variable. |
76
|
|
|
* If the data model is not found, an HTTP exception will be raised. |
77
|
|
|
* @param integer $id the ID of the model to be loaded |
78
|
|
|
* @return Account the loaded model |
79
|
|
|
* @throws CHttpException |
80
|
|
|
*/ |
81
|
|
View Code Duplication |
public function loadModel($id) |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
$model=Account::model()->findByPk((int)$id); |
84
|
|
|
|
85
|
|
|
if ($model===null) { |
86
|
|
|
throw new CHttpException(1, 'A keresett játékos nem található.'); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $model; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.