-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.php
More file actions
140 lines (47 loc) · 1.59 KB
/
controller.php
File metadata and controls
140 lines (47 loc) · 1.59 KB
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
<?php
namespace modules\auth;
class controller extends \Controller {
public function get() {
$this->reroute("/login", SELF::REROUTE_MODULE);
}
public function login() {
$this->redirectIfLoggedIn();
$this->f3->set('fields', $this->settings->login_fields);
$this->renderView('login');
}
public function register() {
$this->redirectIfLoggedIn();
$this->f3->set('fields', $this->settings->register_fields);
$this->renderView('register');
}
public function loginPost() {
$this->redirectIfLoggedIn();
$login = $this->loadModel('Login');
if(is_array($response = $login->loginUser($_POST))) {
$this->redirectIfLoggedIn();
} else {
$this->reroute("/login?error={$response}", SELF::REROUTE_MODULE);
}
}
public function registerPost() {
$registration = $this->loadModel('Registration');
if(($response = $registration->registerUser($_POST)) === true) {
$this->loginPost();
} else {
$this->reroute("/register?error={$response}", SELF::REROUTE_MODULE);
}
}
public function logout() {
unset($_SESSION['user']);
$this->reroute('/login', SELF::REROUTE_MODULE);
}
private function redirectIfLoggedIn() {
if(!empty($_SESSION['user'])) {
$path = $this->settings->successful_login_path;
if($path == 'default') {
$path = $this->f3->get('defaultModule');
}
$this->f3->reroute($path);
}
}
}