2 /** @package Cargo::Controller */
4 /** import supporting libraries */
5 require_once("AppBaseController.php");
6 require_once("App/SecureApp.php");
9 * SecureAppController is a sample controller to demonstrate
10 * one approach to authentication in a Phreeze app
12 * From phreeze package
13 * @license http://www.gnu.org/copyleft/lesser.html LGPL
15 * @package Cargo::Controller
16 * @author ClassBuilder
19 class SecureAppController
extends AppBaseController
23 * Override here for any controller-specific functionality
25 protected function Init()
29 // TODO: add controller-wide bootstrap code
33 * This page requires SecureApp::$PERMISSION_USER to view
35 public function UserPage()
37 $this->RequirePermission(
38 SecureApp
::$PERMISSION_USER,
39 'SecureApp.LoginForm',
40 'Login is required to access the secure user page',
41 'You do not have permission to access the secure user page'
44 $this->Assign("currentUser", $this->GetCurrentUser());
46 $this->Assign('page', 'userpage');
47 $this->Render("SecureApp");
51 * This page requires SecureApp::$PERMISSION_ADMIN to view
53 public function AdminPage()
55 $this->RequirePermission(
56 SecureApp
::$PERMISSION_ADMIN,
57 'SecureApp.LoginForm',
58 'Login is required to access the admin page',
59 'Admin permission is required to access the admin page'
62 $this->Assign("currentUser", $this->GetCurrentUser());
64 $this->Assign('page', 'adminpage');
65 $this->Render("SecureApp");
69 * Display the login form
71 public function LoginForm()
73 $this->Assign("currentUser", $this->GetCurrentUser());
75 $this->Assign('page', 'login');
76 $this->Render("SecureApp");
80 * Process the login, create the user session and then redirect to
81 * the appropriate page
83 public function Login()
85 $user = new SecureApp();
87 if ($user->Login(RequestUtil
::Get('username'), RequestUtil
::Get('password'))) {
89 $this->SetCurrentUser($user);
90 $this->Redirect('SecureApp.UserPage');
93 $this->Redirect('SecureApp.LoginForm', 'Unknown username/password combination');
98 * Clear the user session and redirect to the login page
100 public function Logout()
102 $this->ClearCurrentUser();
103 $this->Redirect("SecureApp.LoginForm", "You are now logged out");