1 <?php
defined('IN_CMS') or die('No direct access allowed.');
3 class Users_controller
{
5 public function __construct() {
6 $this->admin_url
= Config
::get('application.admin_folder');
9 public function index() {
10 $users = Users
::list_all();
11 Template
::render('users/index', array('users' => $users));
14 public function login() {
15 if(Input
::method() == 'POST') {
17 return Response
::redirect($this->admin_url
. '/posts');
20 Template
::render('users/login');
23 public function logout() {
25 return Response
::redirect($this->admin_url
. '/login');
28 public function amnesia() {
29 if(Input
::method() == 'POST') {
30 if(Users
::recover_password()) {
31 return Response
::redirect($this->admin_url
. '/users/login');
34 Template
::render('users/amnesia');
37 public function reset($hash) {
39 if(($user = Users
::find(array('hash' => $hash))) === false) {
40 Notifications
::set('error', 'User not found');
41 return Response
::redirect($this->admin_url
. '/users');
44 if(Input
::method() == 'POST') {
45 if(Users
::reset_password($user->id
)) {
46 return Response
::redirect($this->admin_url
);
50 Template
::render('users/reset', array('user' => $user));
53 public function add() {
54 if(Input
::method() == 'POST') {
56 return Response
::redirect($this->admin_url
. '/users/edit/' . Db
::insert_id());
59 Template
::render('users/add');
62 public function edit($id) {
64 if(($user = Users
::find(array('id' => $id))) === false) {
65 return Response
::redirect($this->admin_url
. '/users');
68 // process post request
69 if(Input
::method() == 'POST') {
70 if(Users
::update($id)) {
72 return Response
::redirect($this->admin_url
. '/users/edit/' . $id);
76 Template
::render('users/edit', array('user' => $user));