php class UserController extends BaseController public function indexA

  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
<?php
class UserController extends BaseController {
public function indexAction() {
$this->tag->setTitle('Кабинет');
$this->view->setVar('user', $this->auth->user);
}
public function profileAction($login = null) {
$login = $this->dispatcher->getParam('user');
$profile = Users::findFirstByUrl($login) ? Users::findFirstByUrl($login) : (Users::findFirstByLogin($login) ? Users::findFirstByLogin($login) : Users::findFirstById($login));
if ($profile == false) {
$this->flash->error('Пользователь '.$this->dispatcher->getParam('user').' не найден');
$this->response->redirect();
$this->view->disable();
return false;
}
$paginator = new \Сontrario\Paginator($profile->feeds, (int)$this->dispatcher->getParam('page'), 1);
$this->tag->setTitle($profile->login . ' / Профиль');
$this->view->setVars(array(
'profile' => $profile,
'user' => $this->auth->user,
'feeds' => $paginator->paginate
));
}
public function registerAction() {
$form = new Сontrario\Forms\RegisterForm();
if ($this->request->isPost()) {
if ($form->isValid($this->request->getPost())) {
$email = $this->request->getPost('email');
$name = $this->request->getPost('name');
$password = $this->request->getPost('password');
$user = new Users();
$user->email = $email;
$user->login = $name;
$user->url = $name;
$user->updated_at = (string) \Сontrario\Carbon::now();
$user->created_at = (string) \Сontrario\Carbon::now();
$user->password = $this->security->hash($password);
if ($user->save()) {
$this->flash->success('Регистрация прошла успешно');
$this->response->redirect('user/login');
$this->view->disable();
} else {
foreach ($user->getMessages() as $message) {
$this->flash->error($message);
}
}
} else {
foreach ($form->getMessages() as $message) {
$this->flash->error($message);
}
}
}
$this->tag->setTitle('Регистрация');
$this->view->form = $form;
}
public function loginAction() {
$form = new Сontrario\Forms\LoginForm();
if ($this->request->isPost()) {
if ($form->isValid($this->request->getPost())) {
$name = $this->request->getPost('name');
$password = $this->request->getPost('password');
if ($this->auth->attempt(array('login' => $name, 'password' => $password))) {
$user = $this->auth->user();
$this->flash->success('Добро пожаловать, '.$user->login);
$this->response->redirect('user');
$this->view->disable();
} else {
$this->flash->error('Не правильный логин или пароль');
}
} else {
foreach ($form->getMessages() as $message) {
$this->flash->error($message);
}
}
}
$this->tag->setTitle('Авторизация');
$this->view->form = $form;
}
public function exitAction() {
$this->auth->logout();
$this->response->redirect();
$this->view->disable();
}
}