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
|
|
|
|
PHP provides two ways to mark string literals. Either with single quotes
'literal'
or with double quotes"literal"
. The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (
\'
) and the backslash (\\
). Every other character is displayed as is.Double quoted string literals may contain other variables or more complex escape sequences.
will print an indented:
Single is Value
If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.
For more information on PHP string literals and available escape sequences see the PHP core documentation.