php public function startAction if Users findFirstByIp this- request-

 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
<?php
public function startAction() {
if(!Users::findFirstByIp($this->request->getClientAddress())){
if($this->request->hasQuery('prof') and $this->session->has('new-user-race')){
$start = new Users();
$login = 'Воитель'.(count($start::find()) + 1);
$start->login = $login;
$start->ip = $this->request->getClientAddress();
$start->race = $this->session->get('new-user-race');
$start->prof = $this->request->getQuery('prof', 'int');
$start->updated_at = (string) \Сontrario\Carbon::now();
$start->created_at = (string) \Сontrario\Carbon::now();
$start->password = $this->security->hash('temp');
if ($start->save()) {
if ($this->auth->attempt(array('login' => $login, 'password' => 'temp'))) {
$start = $this->auth->user();
$this->flash->success('Регистрация прошла успешно. Добро пожаловать, '.$start->login);
$this->session->remove('new-user-race');
$this->session->remove('new-user-win');
$this->response->redirect();
$this->view->disable();
}
}
else {
$this->response->redirect('user/start');
$this->view->disable();
}
}
elseif($this->request->hasQuery('race')){
$this->session->set('new-user-race', $this->request->getQuery('race', 'int'));
$this->response->redirect('user/start');
$this->view->disable();
}
if($this->request->hasQuery('attack') and $this->session->has('new-user-race')){
$this->view->pick('user/start/first');
$this->session->set('new-user-win', 1);
$this->response->redirect('user/start');
$this->view->disable();
}
elseif($this->session->has('new-user-win')){
$this->view->pick('user/start/enter');
}
}
else {
$this->response->redirect();
$this->view->disable();
}
}