Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!-- User model -->
- <?php
- class User extends AppModel {
- var $name = 'User';
- var $belongsTo = array (
- 'Group'
- );
- var $hasMany = array (
- 'UserLog',
- 'WorkLog'
- );
- var $actAs = array (
- 'Acl' => array ('type' => 'requester')
- );
- function parentNode () {
- if (!$this->id && empty ($this->data)) {
- return null;
- }
- if (isset ($this->data['User']['group_id'])) {
- $groupId = $this->data['User']['group_id'];
- } else {
- $groupId = $this->field ('group_id');
- }
- if (!$groupId) {
- return null;
- } else {
- return array (
- 'Group' => array ('id' => $groupId)
- );
- }
- }
- }
- ?>
- <!-- Group Model -->
- <?php
- class Group extends AppModel {
- var $name = 'Group';
- var $hasMany = array (
- 'User'
- );
- var $actAs = array (
- 'Acl' => array ('type' => 'requester')
- );
- function parentNode () {
- return null;
- }
- }
- ?>
- <!-- Users Controller -->
- <?php
- class UsersController extends AppController {
- var $name = 'Users';
- function index() {
- $this->User->recursive = 0;
- $this->set('users', $this->paginate());
- }
- function beforeFilter () {
- parent::beforeFilter();
- /* FIXME: Temporal code */
- $this->Auth->allow (array ('*'));
- }
- public function login () {
- }
- public function logout () {
- $this->Auth->logout();
- $this->redirect('/');
- }
- public function dashboard () {
- }
- function view($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid user', true));
- $this->redirect(array('action' => 'index'));
- }
- $this->set('user', $this->User->read(null, $id));
- }
- function add() {
- if (!empty($this->data)) {
- $this->User->create();
- if ($this->User->save($this->data)) {
- $this->Session->setFlash(__('The user has been saved', true));
- $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__('The user could not be saved. Please, try again.', true));
- }
- }
- $groups = $this->User->Group->find('list');
- $this->set(compact('groups'));
- }
- function edit($id = null) {
- if (!$id && empty($this->data)) {
- $this->Session->setFlash(__('Invalid user', true));
- $this->redirect(array('action' => 'index'));
- }
- if (!empty($this->data)) {
- if ($this->User->save($this->data)) {
- $this->Session->setFlash(__('The user has been saved', true));
- $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__('The user could not be saved. Please, try again.', true));
- }
- }
- if (empty($this->data)) {
- $this->data = $this->User->read(null, $id);
- }
- $groups = $this->User->Group->find('list');
- $this->set(compact('groups'));
- }
- function delete($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid id for user', true));
- $this->redirect(array('action'=>'index'));
- }
- if ($this->User->delete($id)) {
- $this->Session->setFlash(__('User deleted', true));
- $this->redirect(array('action'=>'index'));
- }
- $this->Session->setFlash(__('User was not deleted', true));
- $this->redirect(array('action' => 'index'));
- }
- }
- <!-- Groups Controller -->
- <?php
- class GroupsController extends AppController {
- var $name = 'Groups';
- function beforeFilter () {
- parent::beforeFilter();
- /* FIXME: Temporal code */
- $this->Auth->allow (array ('*'));
- }
- function index() {
- $this->Group->recursive = 0;
- $this->set('groups', $this->paginate());
- }
- function view($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid group', true));
- $this->redirect(array('action' => 'index'));
- }
- $this->set('group', $this->Group->read(null, $id));
- }
- function add() {
- if (!empty($this->data)) {
- $this->Group->create();
- if ($this->Group->save($this->data)) {
- $this->Session->setFlash(__('The group has been saved', true));
- $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__('The group could not be saved. Please, try again.', true));
- }
- }
- }
- function edit($id = null) {
- if (!$id && empty($this->data)) {
- $this->Session->setFlash(__('Invalid group', true));
- $this->redirect(array('action' => 'index'));
- }
- if (!empty($this->data)) {
- if ($this->Group->save($this->data)) {
- $this->Session->setFlash(__('The group has been saved', true));
- $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__('The group could not be saved. Please, try again.', true));
- }
- }
- if (empty($this->data)) {
- $this->data = $this->Group->read(null, $id);
- }
- }
- function delete($id = null) {
- if (!$id) {
- $this->Session->setFlash(__('Invalid id for group', true));
- $this->redirect(array('action'=>'index'));
- }
- if ($this->Group->delete($id)) {
- $this->Session->setFlash(__('Group deleted', true));
- $this->redirect(array('action'=>'index'));
- }
- $this->Session->setFlash(__('Group was not deleted', true));
- $this->redirect(array('action' => 'index'));
- }
- }
- ?>
- <!-- App Controller -->
- <?php
- class AppController extends Controller {
- var $components = array ('Acl', 'Auth', 'Session');
- var $helpers = array ('Html', 'Form', 'Session');
- 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->actionPath = 'controllers/';
- /* FIXME: important read about ACL ( http://api.cakephp.org/class/auth-component ) */
- $this->authorize = 'actions';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment