student numbers
[ssproject1617.git] / testcms-final-anon / system / admin / controllers / users.php
1 <?php defined('IN_CMS') or die('No direct access allowed.');
2
3 class Users_controller {
4
5 public function __construct() {
6 $this->admin_url = Config::get('application.admin_folder');
7 }
8
9 public function index() {
10 $users = Users::list_all();
11 Template::render('users/index', array('users' => $users));
12 }
13
14 public function login() {
15 if(Input::method() == 'POST') {
16 if(Users::login()) {
17 return Response::redirect($this->admin_url . '/posts');
18 }
19 }
20 Template::render('users/login');
21 }
22
23 public function logout() {
24 Users::logout();
25 return Response::redirect($this->admin_url . '/login');
26 }
27
28 public function amnesia() {
29 if(Input::method() == 'POST') {
30 if(Users::recover_password()) {
31 return Response::redirect($this->admin_url . '/users/login');
32 }
33 }
34 Template::render('users/amnesia');
35 }
36
37 public function reset($hash) {
38 // find user
39 if(($user = Users::find(array('hash' => $hash))) === false) {
40 Notifications::set('error', 'User not found');
41 return Response::redirect($this->admin_url . '/users');
42 }
43
44 if(Input::method() == 'POST') {
45 if(Users::reset_password($user->id)) {
46 return Response::redirect($this->admin_url);
47 }
48 }
49
50 Template::render('users/reset', array('user' => $user));
51 }
52
53 public function add() {
54 if(Input::method() == 'POST') {
55 if(Users::add()) {
56 return Response::redirect($this->admin_url . '/users/edit/' . Db::insert_id());
57 }
58 }
59 Template::render('users/add');
60 }
61
62 public function edit($id) {
63 // find user
64 if(($user = Users::find(array('id' => $id))) === false) {
65 return Response::redirect($this->admin_url . '/users');
66 }
67
68 // process post request
69 if(Input::method() == 'POST') {
70 if(Users::update($id)) {
71 // redirect path
72 return Response::redirect($this->admin_url . '/users/edit/' . $id);
73 }
74 }
75
76 Template::render('users/edit', array('user' => $user));
77 }
78
79 }