-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.php
91 lines (77 loc) · 2.37 KB
/
profile.php
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
require_once 'init.php';
$user = new User();
if (!$user->exists()) Redirect::to();
$page_title = 'Профиль пользователя - ' . $user->data()->username;
$validate = new Validate();
$validate->check($_POST, [
'username' => [
'required' => true,
'min' => 2
]
]);
if (Input::exists()) {
if (Token::check(Input::get('token'))) {
if ($validate->passed()) {
$user->update([
'username' => Input::get('username'),
'status' => Input::get('status'),
]);
Session::setFlash('Профиль обновлен', 'success');
Redirect::to('profile.php');
} else {
$errors = '';
foreach ($validate->errors() as $error) {
$errors .= $error . '<br>';
}
Session::setFlash($errors);
}
}
}
require 'header.php';
?>
<div class="container">
<div class="row">
<div class="col-md-8">
<h1><?=$page_title?></h1>
<?php if (Session::exists('success')) {
echo '<div class="alert alert-success">' . Session::getFlash('success') . '</div>';
}
if (Session::exists('danger')) {
echo '<div class="alert alert-danger">' . Session::getFlash('danger') . '</div>';
}
if (Session::exists('info')) {
echo '<div class="alert alert-info">' . Session::getFlash('info') . '</div>';
}
Form::begin([
'method' => 'post',
'class' => "form",
]);?>
<div class="form-group">
<?php Form::input('username', [
'class' => 'form-control',
'label' => 'Имя',
'value' => $user->data()->username,
]); ?>
</div>
<div class="form-group">
<?php Form::input('status', [
'class' => 'form-control',
'label' => 'Статус',
'value' => $user->data()->status,
]); ?>
</div>
<?php Form::input('token'); ?>
<div class="form-group">
<?php Form::button([
'class' => 'btn btn-warning',
'type' => 'submit',
], 'Обновить профиль'); ?>
<a href="<?=Config::get('site.baseurl')?>/changepassword.php" class="ml-3 btn btn-secondary">Изменить пароль</a>
</div>
<?php Form::end();?>
</div>
</div>
</div>
</body>
</html>