-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathUserController.php
More file actions
50 lines (33 loc) · 1.11 KB
/
UserController.php
File metadata and controls
50 lines (33 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace App\Controller;
use App\{Model\User AS UserModel,Helper\AuthHelper};
use Core\View;
class UserController extends \Core\Controller {
const defaultMethod = 'profile';
public function initialize() {
AuthHelper::getInstance()->authAreaControl();
}
public function profile() {
$modelUser = new UserModel;
$user = $modelUser->getUserById(AuthHelper::getInstance()->get('user'));
View::render('user-profile.php',['user'=>$user]);
}
public function profileAction() {
header('Content-Type: application/json');
$response = ['status' => false];
try {
if(empty($_POST))
throw new \InvalidArgumentException(__METHOD__.':eksik argüman');
if($_POST['password']=='')
unset($_POST['password']);
if(isset($_POST['password']))
$_POST['password'] = password_hash($_POST['password'],PASSWORD_DEFAULT);
$modelUser = new UserModel;
$modelUser -> updateUser(AuthHelper::getInstance()->get('user'),$_POST);
$response['status'] = true;
} catch(\Exception | \Error $e) {
$response['error'] = $e -> getMessage();
}
echo json_encode($response);
}
}