/
auth.php
122 lines (87 loc) · 3.87 KB
/
auth.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Auth extends Controller_Index{
public function action_index() {
$this->action_login();
}
public function action_login() {
if(Auth::instance()->logged_in('login')) {
$this->request->redirect('account');
}
if (isset($_POST['submit'])){
$data = Arr::extract($_POST, array('username', 'password', 'remember'));
$status = Auth::instance()->login($data['username'], $data['password'], (bool) $data['remember']);
if ($status){
if(Auth::instance()->logged_in('login')) {
$this->request->redirect('account');
}
$this->request->redirect('account');
}
else {
$errors = array(Kohana::message('validation', 'no_user'));
}
}
$login = View::factory('v_login')
->bind('errors', $errors)
->bind('reg_ok', $this->reg_ok)
->bind('data', $data);
// Выводим в шаблон
$this->template->title = 'Авторизация';
$this->template->page_title = 'Вход в личный кабинет';
$this->template->block_center = array('login'=>$login);
}
public function action_register() {
if (isset($_POST['submit'])){
$data = Arr::extract($_POST, array('username', 'password', 'first_name', 'password_confirm', 'email', 'phone', 'address', 'country_id', 'zone_id', 'city_id', 'agree'));
$users = ORM::factory('user');
// $content->message = '';
// $content->message = Captcha::valid($_POST['captcha'])? 'Не угадал';
try {
$regdate = date("Y-M-D");
$users->create_user($_POST, array(
'username',
'first_name',
'password',
'email',
'phone',
'address',
'country_id',
'zone_id',
'city_id',
'regdate'=>$regdate,
));
$role = ORM::factory('role', array('name' => 'login'));
$users->add('roles', $role);
// $users->add('roles', 1);
$email = Email::factory('Регистрация на сайте','Регистрация на сайте успешно завешена')
->to($data['email'],$data['first_name'])
->from('admin@mykohana.loc','mykohan')
->send();
$this->action_login();
$this->request->redirect('account');
// $this->reg_ok = "<p><b>Ваш профил успешно созданно</b></p>";
$this->action_login();
$this->request->redirect('account');
}
catch (ORM_Validation_Exception $e) {
$errors = $e->errors('user');
}
}
$captcha = Captcha::instance();
$captcha_image = $captcha->render();
$country = ORM::factory('country')->find_all();
$zones = ORM::factory('zone')->where('country_id', '=', 176)->find_all();
$form_register = View::factory('v_registration',array('country'=>$country, 'zones'=>$zones))
->bind('errors', $errors)
->bind('data', $data)
->bind('captcha_image', $captcha_image);
// Выводим в шаблон
$this->template->title = 'Регистрация';
$this->template->page_title = 'Регистрация новога пользователя';
$this->template->block_center = array('form_register'=>$form_register);
}
public function action_logout() {
if(Auth::instance()->logout()) {
$this->request->redirect();
}
}
}