summaryrefslogtreecommitdiffstats
path: root/application/controllers/user.php
blob: 4dc92bea24a70f6da11b03ff0763e180d6382ba5 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php

class User extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->library('migration');
		if ( ! $this->migration->current()) {
			show_error($this->migration->error_string());
		}

		$this->load->model("muser");
		$this->data["title"] = "FileBin";
		
		$this->load->helper('form');

		$this->var->view_dir = "user/";
	}
	
	function index()
	{
		$this->data["username"] = $this->muser->get_username();

		$this->load->view($this->var->view_dir.'header', $this->data);
		$this->load->view($this->var->view_dir.'index', $this->data);
		$this->load->view($this->var->view_dir.'footer', $this->data);
	}
	
	function login()
	{
		$this->session->keep_flashdata("uri");

		if ($this->input->post('process')) {
			$username = $this->input->post('username');
			$password = $this->input->post('password');

			$result = $this->muser->login($username, $password);

			if ($result !== true) {
				$data['login_error'] = true;
				$this->load->view($this->var->view_dir.'header', $this->data);
				$this->load->view($this->var->view_dir.'login', $this->data);
				$this->load->view($this->var->view_dir.'footer', $this->data);
			} else {
				$uri = $this->session->flashdata("uri");
				if ($uri) {
					redirect($uri);
				} else {
					$this->load->view($this->var->view_dir.'header', $this->data);
					$this->load->view($this->var->view_dir.'login_successful', $this->data);
					$this->load->view($this->var->view_dir.'footer', $this->data);
				}
			}
		} else {
			$this->load->view($this->var->view_dir.'header', $this->data);
			$this->load->view($this->var->view_dir.'login', $this->data);
			$this->load->view($this->var->view_dir.'footer', $this->data);
		}
	}
	
	function logout()
	{
		$this->muser->logout();
		redirect('/');
	}
	
	function hash_password()
	{
		$password = $this->input->post("password");
		echo "hashing $password: ";
		echo $this->muser->hash_password($password);
	}
}