Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php // Only for hightlighting
- // Actions in controllers
- ////////////////////////////////////////////////////////////////////////////////
- // In app controller
- function beforeFilter () {
- $this->Auth->loginAction = array (
- 'controller' => 'users',
- 'action' => 'login'
- );
- $this->Auth->autoRedirect = array (
- 'controller' => 'users',
- 'action' => 'dashboard'
- );
- $this->Auth->loginRedirect = array (
- 'controller' => 'users',
- 'action' => 'dashboard'
- );
- $this->Auth->logoutRedirect = array (
- 'controller' => 'users',
- 'action' => 'logout'
- );
- $this->Auth->loginError = "No t'has identificat correctament";
- $this->Auth->authError = "Has d'identificar-te com a usuari per accedir a aquesta secció";
- $this->Auth->actionPath = 'controllers/';
- $this->Auth->authorize = 'actions';
- }
- // In users controller
- public function login () {
- $this->set ('title_for_layout', 'ARE · Gestió de Pràctiques externes');
- $this->set ('header_text', 'ARE · Gestió de Pràctiques externes');
- $userinfo = $this->Auth->user ();
- if ($userinfo) {
- if (substr($userinfo['User']['validate'], 0, 2) == 'v:') {
- $this->Auth->logout ();
- $this->redirect(array(
- 'controller' => 'users',
- 'action' => 'login'
- ));
- } else {
- $this->redirect(array(
- 'controller' => 'users',
- 'action' => 'dashboard'
- ));
- }
- } elseif (isset($this->data)) {
- if ($this->Auth->login($this->data) == 0) {
- $this->set ('cleanLogin', false);
- }
- } else {
- $this->set ('cleanLogin', true);
- }
- }
- public function dashboard () {
- $this->set ('title_for_layout', 'ARE · Panell de gestió');
- $this->set ('header_text', 'ARE · Panell de gestió');
- $userinfo = $this->Auth->user ();
- // The user have to be validated
- if (substr($userinfo['User']['validate'], 0, 2) == 'v:') {
- $this->Auth->logout ();
- $this->redirect(array(
- 'controller' => 'users',
- 'action' => 'login'
- ));
- }
- $groupid = $userinfo['User']['group_id'];
- $dashboard = $this->requestAction (
- array (
- 'controller' => $this->group_numbers[$groupid],
- 'action' => 'dashboard'
- ),
- array (
- 'named' => array (),
- 'pass' => array (),
- 'return'
- )
- );
- $this->set('dashboard', $dashboard);
- }
- // In companies controller (the specific user I'm trying represents a company
- public function dashboard () {
- $session = $this->Session;
- $user = $this->Auth->user ();
- if (!$session->check ('Role')) {
- $company = $this->Company->find (
- 'first',
- array (
- 'conditions' => array (
- 'user_id' => $user['User']['id']
- ),
- 'recursive' => -1
- )
- );
- $session->write ('Role', $company);
- }
- $this->set ('named', array ());
- }
- ?> // End of PHP block (for hightlighting)
- // The users login view
- ////////////////////////////////////////////////////////////////////////////////
- <form id="UserLoginForm" method="post" action="<?php echo $html->url(array ('controller' => 'users', 'action' => 'login')); ?>" accept-charset="utf-8">
- <div style="display:none;"><input type="hidden" name="_method" value="POST" /></div>
- <div id="login-box">
- <div class="input text login-field">
- <label for="UserUsername">Usuari: </label>
- <input name="data[User][username]" type="text" maxlength="32" id="UserUsername" />
- </div>
- <div class="input password login-field">
- <label for="UserPassword">Clau: </label>
- <input type="password" name="data[User][password]" id="UserPassword" />
- </div>
- <div class="submit login-button">
- <input type="submit" value="Entra" />
- </div>
- <div class="login-register">
- <?php
- echo $html->link (
- 'Registri un usuari per a la seva empresa',
- array (
- 'controller' => 'companies',
- 'action' => 'create'
- )
- ).'<br/>';
- echo $html->link (
- 'Registra\'t com a estudiant',
- array (
- 'controller' => 'students',
- 'action' => 'create'
- )
- ).'<br/>';
- ?>
- </div>
- </div>
- <?php if (!$cleanLogin): ?>
- <div class="login-error">No ha introduit les dades correctes</div>
- <?php endif;?>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment