summaryrefslogtreecommitdiff
path: root/src/web/_controller/apps/auth.php
blob: 1df74da6b5df699ee80ac211961a37ff4ed173c5 (plain)
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
<?php /* Copyright (c) 2024 Freya Murphy */
class Auth_controller extends Controller {

	// the home model
	private $auth_model;

	// the post controller
	protected $post_controller;

	function __construct($load) {
		parent::__construct($load);
		$this->auth_model = $this->load->model('apps/auth');
	}

	public function index(): void {
		if ($this->main->session) {
			$this->redirect('/home');
		} else {
			$this->redirect('/auth/login');
		}
	}

	public function login(): void {
		if ($this->main->session) {
			$this->redirect('/home');
		}

		parent::index();
		$data = $this->auth_model->get_data();
		$this->view('head', $data);
		$this->view('apps/auth/login', $data);
		$this->view('footer', $data);
	}

	public function logout(): void {
		if ($this->main->session) {
			$_SESSION['jwt'] = NULL;
		}
		$this->redirect('/auth/login');
	}

	public function update(): void {
		if (!$this->is_ajax()) {
			$this->error(400);
		}
		if (!isset($_POST['key']) || !isset($_POST['value'])) {
			$this->error(400);
		}
		$key = $_POST['key'];
		$value = $_POST['value'];
		$_SESSION[$key] = $value;
	}

}

?>