Kohana::controller

 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
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Users extends Controller_Base {
public function action_signup() {
if (empty($this->auth())) {
$errors = null;
if ($_POST) {
$_POST = Arr::map('trim', $_POST);
$post = Model::factory('Users')
->signup_valid($_POST);
if ($post->check()) {
Model::factory('Users')
->new_user($_POST['login'], $_POST['email'], md5($_POST['password']));
$logged = $_POST['email'] . ':' . md5($_POST['password']);
Cookie::set('logged', $logged);
} else $errors = $post->errors('signup');
}
$data = array(
'errors' => $errors,
'title' => 'Регистрация',
'captcha' => Captcha::instance(),
'csrf' => Security::token(TRUE)
);
echo View_Fenom::factory('signup', $data);
}
else HTTP::redirect(URL::base(true));
}
public function action_login() {
$errors = null;
if ($_POST) {
$_POST = Arr::map('trim', $_POST);
$post = Model::factory('Users')
->login_valid($_POST);
if ($post->check()) {
$logged = $_POST['email'] . ':' . md5($_POST['password']);
Cookie::set('logged', $logged);
} else $errors = $post->errors('login');
}
$data = array(
'errors' => $errors,
'title' => 'Авторизация',
'captcha' => Captcha::instance(),
'csrf' => Security::token(TRUE)
);
echo View_Fenom::factory('login', $data);
}
public function action_logout() {
Cookie::delete('logged');
HTTP::redirect(URL::base(true));
}
}