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(SecureApp
::$PERMISSION_USER,
38 'SecureApp.LoginForm',
39 'Login is required to access the secure user page',
40 'You do not have permission to access the secure user page');
42 $this->Assign("currentUser", $this->GetCurrentUser());
44 $this->Assign('page','userpage');
45 $this->Render("SecureApp");
49 * This page requires SecureApp::$PERMISSION_ADMIN to view
51 public function AdminPage()
53 $this->RequirePermission(SecureApp
::$PERMISSION_ADMIN,
54 'SecureApp.LoginForm',
55 'Login is required to access the admin page',
56 'Admin permission is required to access the admin page');
58 $this->Assign("currentUser", $this->GetCurrentUser());
60 $this->Assign('page','adminpage');
61 $this->Render("SecureApp");
65 * Display the login form
67 public function LoginForm()
69 $this->Assign("currentUser", $this->GetCurrentUser());
71 $this->Assign('page','login');
72 $this->Render("SecureApp");
76 * Process the login, create the user session and then redirect to
77 * the appropriate page
79 public function Login()
81 $user = new SecureApp();
83 if ($user->Login(RequestUtil
::Get('username'), RequestUtil
::Get('password')))
86 $this->SetCurrentUser($user);
87 $this->Redirect('SecureApp.UserPage');
92 $this->Redirect('SecureApp.LoginForm','Unknown username/password combination');
97 * Clear the user session and redirect to the login page
99 public function Logout()
101 $this->ClearCurrentUser();
102 $this->Redirect("SecureApp.LoginForm","You are now logged out");