|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* User controller |
|
5
|
|
|
* |
|
6
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
|
7
|
|
|
* @author Omar El Gabry <[email protected]> |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
class UserController extends Controller{ |
|
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
public function beforeAction(){ |
|
13
|
|
|
|
|
14
|
|
|
parent::beforeAction(); |
|
15
|
|
|
|
|
16
|
|
|
$action = $this->request->param('action'); |
|
17
|
|
|
$actions = ['updateProfileInfo', 'updateProfilePicture', 'reportBug']; |
|
18
|
|
|
$this->Security->requirePost($actions); |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
switch($action){ |
|
21
|
|
|
case "updateProfileInfo": |
|
22
|
|
|
$this->Security->config("form", [ 'fields' => ['name', 'password', 'email', 'confirm_email']]); |
|
|
|
|
|
|
23
|
|
|
break; |
|
24
|
|
|
case "updateProfilePicture": |
|
25
|
|
|
$this->Security->config("form", [ 'fields' => ['file']]); |
|
|
|
|
|
|
26
|
|
|
break; |
|
27
|
|
|
case "reportBug": |
|
28
|
|
|
$this->Security->config("form", [ 'fields' => ['subject', 'label', 'message']]); |
|
|
|
|
|
|
29
|
|
|
break; |
|
30
|
|
|
} |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* show dashboard page |
|
35
|
|
|
* |
|
36
|
|
|
*/ |
|
37
|
|
|
public function index(){ |
|
38
|
|
|
|
|
39
|
|
|
Config::setJsConfig('curPage', "dashboard"); |
|
40
|
|
|
$this->view->renderWithLayouts(Config::get('VIEWS_PATH') . "layout/default/", Config::get('VIEWS_PATH') . 'dashboard/index.php'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public function profile(){ |
|
44
|
|
|
|
|
45
|
|
|
Config::setJsConfig('curPage', "profile"); |
|
46
|
|
|
$this->view->renderWithLayouts(Config::get('VIEWS_PATH') . "layout/default/", Config::get('VIEWS_PATH') . 'user/profile.php'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function updateProfileInfo(){ |
|
50
|
|
|
|
|
51
|
|
|
$name = $this->request->data("name"); |
|
52
|
|
|
$password = $this->request->data("password"); |
|
53
|
|
|
$email = $this->request->data("email"); |
|
54
|
|
|
$confirmEmail = $this->request->data("confirm_email"); |
|
55
|
|
|
|
|
56
|
|
|
$result = $this->user->updateProfileInfo(Session::getUserId(), $name, $password, $email, $confirmEmail); |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
if(!$result){ |
|
59
|
|
|
|
|
60
|
|
|
Session::set('profile-info-errors', $this->user->errors()); |
|
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
}else{ |
|
63
|
|
|
|
|
64
|
|
|
$message = "Your Profile has been updated. "; |
|
65
|
|
|
$message .= $result["emailUpdated"]? "Please check your new email to confirm the changes, or your current email to revoke the changes": ""; |
|
66
|
|
|
|
|
67
|
|
|
Session::set('profile-info-success', $message); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $this->redirector->root("User/Profile"); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function updateProfilePicture(){ |
|
74
|
|
|
|
|
75
|
|
|
$fileData = $this->request->data("file"); |
|
76
|
|
|
$image = $this->user->updateProfilePicture(Session::getUserId(), $fileData); |
|
|
|
|
|
|
77
|
|
|
|
|
78
|
|
|
if(!$image){ |
|
79
|
|
|
Session::set('profile-picture-errors', $this->user->errors()); |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
return $this->redirector->root("User/Profile"); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* revoke email updates |
|
87
|
|
|
* |
|
88
|
|
|
* You must be logged in with your current email |
|
89
|
|
|
*/ |
|
90
|
|
|
public function revokeEmail(){ |
|
91
|
|
|
|
|
92
|
|
|
$userId = $this->request->query("id"); |
|
93
|
|
|
$userId = empty($userId)? null: Encryption::decryptId($this->request->query("id")); |
|
94
|
|
|
$token = $this->request->query("token"); |
|
95
|
|
|
|
|
96
|
|
|
$result = $this->user->revokeEmail($userId, $token); |
|
|
|
|
|
|
97
|
|
|
|
|
98
|
|
View Code Duplication |
if(!$result){ |
|
|
|
|
|
|
99
|
|
|
return $this->error(404); |
|
100
|
|
|
}else{ |
|
101
|
|
|
$this->view->renderWithLayouts(Config::get('VIEWS_PATH') . "layout/default/", Config::get('VIEWS_PATH') . 'user/profile.php', ["emailUpdates" => ["success" => "Your email updates has been revoked successfully."]]); |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* confirm on email updates |
|
107
|
|
|
* |
|
108
|
|
|
* You must be logged in with your current email |
|
109
|
|
|
*/ |
|
110
|
|
|
public function updateEmail(){ |
|
111
|
|
|
|
|
112
|
|
|
$userId = $this->request->query("id"); |
|
113
|
|
|
$userId = empty($userId)? null: Encryption::decryptId($this->request->query("id")); |
|
114
|
|
|
$token = $this->request->query("token"); |
|
115
|
|
|
|
|
116
|
|
|
$result = $this->user->updateEmail($userId, $token); |
|
|
|
|
|
|
117
|
|
|
$errors = $this->user->errors(); |
|
|
|
|
|
|
118
|
|
|
|
|
119
|
|
|
if(!$result && empty($errors)){ |
|
120
|
|
|
return $this->error(404); |
|
121
|
|
|
}else if(!$result && !empty($errors)){ |
|
122
|
|
|
$this->view->renderWithLayouts(Config::get('VIEWS_PATH') . "layout/default/", Config::get('VIEWS_PATH') . 'user/profile.php', ["emailUpdates" => ["errors" => $this->user->errors()]]); |
|
|
|
|
|
|
123
|
|
View Code Duplication |
}else{ |
|
|
|
|
|
|
124
|
|
|
$this->view->renderWithLayouts(Config::get('VIEWS_PATH') . "layout/default/", Config::get('VIEWS_PATH') . 'user/profile.php', |
|
125
|
|
|
["emailUpdates" => ["success" => "Your email updates has been updated successfully."]]); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* users can report bugs, features, or enhancement |
|
131
|
|
|
* - Bug is an error you encountered |
|
132
|
|
|
* - Feature is a new functionality you suggest to add |
|
133
|
|
|
* - Enhancement is an existing feature, but you want to improve |
|
134
|
|
|
* |
|
135
|
|
|
*/ |
|
136
|
|
|
public function bugs(){ |
|
137
|
|
|
Config::setJsConfig('curPage', "bugs"); |
|
138
|
|
|
$this->view->renderWithLayouts(Config::get('VIEWS_PATH') . "layout/default/", Config::get('VIEWS_PATH') . 'bugs/index.php'); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* send email to admin for reporting any bugs, features, or enhancement |
|
143
|
|
|
* |
|
144
|
|
|
*/ |
|
145
|
|
View Code Duplication |
public function reportBug(){ |
|
|
|
|
|
|
146
|
|
|
|
|
147
|
|
|
$subject = $this->request->data("subject"); |
|
148
|
|
|
$label = $this->request->data("label"); |
|
149
|
|
|
$message = $this->request->data("message"); |
|
150
|
|
|
|
|
151
|
|
|
$result = $this->user->reportBug(Session::getUserId(), $subject, $label, $message); |
|
|
|
|
|
|
152
|
|
|
|
|
153
|
|
|
if(!$result){ |
|
154
|
|
|
Session::set('report-bug-errors', $this->user->errors()); |
|
|
|
|
|
|
155
|
|
|
}else{ |
|
156
|
|
|
Session::set('report-bug-success', "Email has been sent successfully, We will consider your report."); |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
return $this->redirector->root("User/Bugs"); |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
public function isAuthorized(){ |
|
163
|
|
|
return true; |
|
164
|
|
|
} |
|
165
|
|
|
} |
|
166
|
|
|
|
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.