Changeset 339

Show
Ignore:
Timestamp:
03/24/08 17:06:55 (10 months ago)
Author:
aarkerio
Message:

Update permission by individual controller rather than general

Location:
trunk/app
Files:
3 added
25 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/app_controller.php

    r336 r339  
    1616 public function beforeFilter() 
    1717 { 
    18      $this->Auth->fields = array('username' => 'username', 'password' => 'pwd'); 
     18     $this->Auth->fields = array('username' => 'email', 'password' => 'pwd'); 
    1919     $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login'); 
    2020     $this->Auth->loginRedirect = array('controller' => 'news', 'action' => 'display'); 
  • trunk/app/app_model.php

    r1 r339  
    11<?php 
    22class AppModel extends Model{ 
    3  
    4 public function expects() 
    5     { 
    6         $models = array(); 
    7          
    8         $arguments = func_get_args(); 
    9          
    10         foreach($arguments as $index => $argument) 
    11         { 
    12             if (is_array($argument)) 
    13             { 
    14                 if (count($argument) > 0) 
    15                 { 
    16                     $arguments = array_merge($arguments, $argument); 
    17                 } 
    18                  
    19                 unset($arguments[$index]); 
     3  
     4 public $assocs = array( 
     5        'Book' => array( 
     6            'type' => 'belongsTo', 
     7            'className' => 'Book', 
     8            'foreignKey' => 'collection_id', 
     9        ), 
     10        'Story' => array( 
     11            'type' => 'hasOne', 
     12            'className' => 'Story', 
     13        ), 
     14        'Album' => array( 
     15            'type' => 'belongsTo', 
     16            'className' => 'Album', 
     17            'foreignKey' => 'collection_id', 
     18        ), 
     19        'Photo' => array( 
     20            'type' => 'hasOne', 
     21            'className' => 'Photo', 
     22        ), 
     23        'Post' => array( 
     24            'type' => 'hasMany', 
     25            'className' => 'Post', 
     26            'order' => 'Post.id DESC', 
     27        ), 
     28    );  
     29  
     30 public function expects($array)  
     31 { 
     32     foreach ($array as $assoc)  
     33     { 
     34            $this->bindModel 
     35        ( 
     36                array($this->assocs[$assoc]['type'] => 
     37            array($assoc => $this->assocs[$assoc]))); 
    2038            } 
    21         } 
    22          
    23         if (count($arguments) == 0) 
    24         { 
    25             $models[$this->name] = array(); 
    26         } 
    27         else 
    28         { 
    29             foreach($arguments as $argument) 
    30             { 
    31                 if (strpos($argument, '.') !== false) 
    32                 { 
    33                     $model = substr($argument, 0, strpos($argument, '.')); 
    34                     $child = substr($argument, strpos($argument, '.') + 1); 
    35                      
    36                     if ($child == $model) 
    37                     { 
    38                         $models[$model] = array(); 
    39                     } 
    40                     else 
    41                     { 
    42                         $models[$model][] = $child; 
    43                     } 
    44                 } 
    45                 else 
    46                 { 
    47                     $models[$this->name][] = $argument; 
    48                 } 
    49             } 
    50         } 
    51          
    52         foreach($models as $model => $children) 
    53         { 
    54             if ($model != $this->name && isset($this->$model)) 
    55             { 
    56                 $this->$model->expects($children); 
    57             } 
    58         } 
    59          
    60         if (isset($models[$this->name])) 
    61         { 
    62             foreach($models as $model => $children) 
    63             { 
    64                 if ($model != $this->name) 
    65                 { 
    66                     $models[$this->name][] = $model; 
    67                 } 
    68             } 
    69              
    70             $models = array_unique($models[$this->name]); 
    71              
    72             $unbind = array(); 
    73          
    74             $relations = array ('belongsTo', 'hasOne', 'hasMany', 'hasAndBelongsToMany'); 
    75              
    76             foreach($relations as $relation) 
    77             { 
    78                 if (isset($this->$relation)) 
    79                 { 
    80                     foreach($this->$relation as $currentModel) 
    81                     { 
    82                         if (!in_array($currentModel['className'], $models)) 
    83                         { 
    84                             $unbind[$relation][] = $currentModel['className']; 
    85                         } 
    86                     } 
    87                 } 
    88             } 
    89              
    90             if (count($unbind) > 0) 
    91             { 
    92                 $this->unbindModel($unbind); 
    93             } 
    94   } 
    95 } 
    96  
    97  
    98 public function unbindAll($params = array()) 
    99     { 
    100         foreach($this->__associations as $ass) 
    101         { 
    102             if(!empty($this->{$ass})) 
    103             { 
    104                  $this->__backAssociation[$ass] = $this->{$ass}; 
    105                 if(isset($params[$ass])) 
    106                 { 
    107                     foreach($this->{$ass} as $model => $detail) 
    108                     { 
    109                         if(!in_array($model,$params[$ass])) 
    110                         { 
    111                              $this->__backAssociation = array_merge($this->__backAssociation, $this->{$ass}); 
    112                             unset($this->{$ass}[$model]); 
    113                         } 
    114                     } 
    115                 } 
    116                 else 
    117                 { 
    118                     $this->__backAssociation = array_merge($this->__backAssociation, $this->{$ass}); 
    119                     $this->{$ass} = array(); 
    120                 } 
    121                  
    122             } 
    123         } 
    124         return true; 
    125     } 
     39     }  
    12640} 
    12741?> 
  • trunk/app/config/core.php

    r333 r339  
    9898 * Actual value depends on 'Security.level' setting. 
    9999 */ 
    100     Configure::write('Session.timeout', '220'); 
     100    Configure::write('Session.timeout', '120'); 
    101101/** 
    102102 * If set to false, sessions are not automatically started. 
     
    120120 * 'Security.level' is set to 'high'. 
    121121 */ 
    122     Configure::write('Security.level', 'medium'); 
     122    Configure::write('Security.level', 'high'); 
    123123/** 
    124124 * A random string used in security hashing methods. 
    125125 */ 
    126     Configure::write('Security.salt', 'DYhG93b0qyJfIxfsvgTR5UubWwvniR2G0FgaC9mi'); 
     126    Configure::write('Security.salt', 'DYhG93b0qyJfIxfs66vgTR5UubWwvniR2G0FgaC9mi'); 
    127127/** 
    128128 * Compress CSS output by removing comments, whitespace, repeating tags, etc. 
  • trunk/app/config/sql/karamelo_postgres.sql

    r333 r339  
    531531); 
    532532  
    533 -- this is a table to keep tempral data, is used to recover the user passwords 
     533-- this is a table to keep temporal data, is used to recover the user password -- see  recovers_controller.php  file 
    534534CREATE TABLE "recovers" ( 
    535535  "id" serial PRIMARY KEY, 
    536   "user_id" int REFERENCES users (id) ON DELETE CASCADE, 
    537   "email" varchar(50), 
    538   "random_string" varchar(150), -- the confirmation string sended to email user to reset his password 
     536  "user_id" int REFERENCES users(id) ON DELETE CASCADE, 
     537  "random" varchar(150) NOT NULL UNIQUE, -- the confirmation string sended to email user to reset his password 
    539538  "created" timestamp(0) with time zone DEFAULT now() NOT NULL 
    540539); 
     540 
    541541--- This models (Test, Webquest ans Treasure) belongsTO to vclassrooms 
    542542-- Webquest 
  • trunk/app/controllers/acquaintances_controller.php

    r322 r339  
    1212 
    1313 public $components   = array('Edublog'); 
     14  
     15 public function beforeFilter()  
     16 { 
     17    $this->Auth->allow(array('display')); 
     18    parent::beforeFilter(); 
     19 } 
    1420  
    1521 public function isAuthorized()  
  • trunk/app/controllers/answers_controller.php

    r328 r339  
    1111class AnswersController extends AppController 
    1212{ 
    13   public $helpers = array('Ajax'); 
    14  
     13 public $helpers = array('Ajax'); 
     14  
    1515 public function isAuthorized()  
    1616 {       
  • trunk/app/controllers/catfaqs_controller.php

    r305 r339  
    1010class CatfaqsController extends AppController 
    1111{ 
    12   public $helpers       = array('Ajax', 'User', 'Gags'); 
    13    
    14   public $components    = array('Edublog'); 
    15    
     12 public $helpers       = array('Ajax', 'User', 'Gags'); 
     13  
     14 public $components    = array('Edublog'); 
     15  
     16 public function beforeFilter()  
     17 { 
     18    $this->Auth->allow(array('display', 'view')); 
     19    parent::beforeFilter(); 
     20 } 
     21  
    1622 public function isAuthorized()  
    1723 {       
     
    2531    return false;  // go away !! 
    2632 } 
    27  
     33  
    2834 public function view($catfaq_id, $user_id) 
    2935 { 
    3036        $this->pageTitle = 'FAQ'; 
    31  
     37         
    3238        $this->layout    = $this->Edublog->layout($user_id); 
    3339         
     
    3541         
    3642        $conditions = array("Catfaq.id"=>$catfaq_id, "Catfaq.status"=>1); 
    37  
     43         
    3844        $fields     = array("id", "title", "body", "categories_id"); 
    3945         
  • trunk/app/controllers/catglossaries_controller.php

    r317 r339  
    1414 public $components       = array('Edublog'); 
    1515 
    16  public function isAuthorized() 
     16 public function beforeFilter()  
    1717 { 
    18         if (isset($this->params[Configure::read('Routing.admin')])) 
    19         { 
    20                  if ($this->Auth->user('group_id') == 1 || $this->Auth->user('group_id') == 2) 
    21                  { 
    22                         return true; 
    23                  } 
    24     } 
    25         return false; 
     18    $this->Auth->allow(array('display', 'view')); 
     19    parent::beforeFilter(); 
    2620 } 
    2721  
     22 public function isAuthorized()  
     23 {       
     24    if (isset( $this->params[Configure::read('Routing.admin')] ))  
     25    { 
     26        if ($this->Auth->user('group_id') == 1 || $this->Auth->user('group_id') == 2 )  // admin and teachers 
     27        { 
     28        return true; 
     29        }  
     30    }  
     31    return false;  // go away !! 
     32 } 
     33 
    2834 public function display($username) 
    2935 { 
  • trunk/app/controllers/colleges_controller.php

    r274 r339  
    33    *  Karamelo E-Learning Platform 
    44    *  Manuel Montoya 2002-2008  
    5     *  GPL License manuel<at>mononeurona<punto>org 
     5    *  GPLv3 License manuel<at>mononeurona<punto>org 
    66    *  Chipotle Software TM 
    77*/  
     
    1515 public $components       = array('Portal'); 
    1616 
     17 public function beforeFilter()  
     18 { 
     19    $this->Auth->allow(array('view')); 
     20    parent::beforeFilter(); 
     21 } 
     22  
    1723 public function isAuthorized()  
    18  { 
    19     if ($this->action == 'delete')  
    20       { 
    21     if ($this->Auth->user('group_id') == 1)  
    22           { 
     24 {       
     25    if (isset( $this->params[Configure::read('Routing.admin')] ))  
     26    { 
     27        if ($this->Auth->user('group_id') == 1 || $this->Auth->user('group_id') == 2 )  // admin and teachers 
     28        { 
    2329        return true; 
    24           } else { 
    25         return false; 
    26           } 
    27       } 
    28   
    29     return true; 
     30        }  
     31    }  
     32    return false;  // go away !! 
    3033 } 
     34 
    3135 
    3236 public function view()  
  • trunk/app/controllers/comments_controller.php

    r325 r339  
    1515 public $helpers = array('Fck', 'News', 'Time', 'Gags', 'Session'); 
    1616 
     17 public function beforeFilter()  
     18 { 
     19    $this->Auth->allow(array('view', 'add')); 
     20    parent::beforeFilter(); 
     21 } 
     22  
    1723 public function isAuthorized()  
    1824 {       
     
    2632    return false;  // go away !! 
    2733 } 
     34 
    2835 
    2936 public function view($username=null, $entry_id=null) 
  • trunk/app/controllers/confirms_controller.php

    r247 r339  
    33*  Karamelo E-Learning Platform 
    44*  Chipotle Software 2002-2008  
    5 *  GPLv3 manuel<at>mononeurona<punto>org 
     5*  GPLv3 manuel<arroba>mononeurona<punto>org 
    66*/  
    7 //File: /app/controllers/users_controller.php 
     7//File: /app/controllers/confirms_controller.php 
    88 
    99uses('sanitize'); 
     
    1111class ConfirmsController extends AppController 
    1212{ 
    13   public function isAuthorized()  
    14   { 
    15     if ($this->action == 'delete')  
    16       { 
    17     if ($this->Auth->user('group_id') == 1)  
    18           { 
     13  
     14 public function beforeFilter()  
     15 { 
     16    $this->Auth->allow(array('signup')); 
     17    parent::beforeFilter(); 
     18 } 
     19  
     20 public function isAuthorized()  
     21 {       
     22    if (isset( $this->params[Configure::read('Routing.admin')] ))  
     23    { 
     24        if ($this->Auth->user('group_id') == 1 || $this->Auth->user('group_id') == 2 )  // admin and teachers 
     25        { 
    1926        return true; 
    20           } else { 
    21         return false; 
    22           } 
    23       } 
     27        }  
     28    }  
     29    return false;  // go away !! 
     30 } 
    2431  
    25     return true; 
    26   } 
    27      
    28   public function signup($secret = null) 
    29   {    
    30         $this->pageTitle = 'Active User Account'; 
    31          
    32         $conditions      = array("secret" => $secret); 
    33          
    34         $fields          = array('id', 'user_id'); 
    35          
    36         $data            = $this->Confirm->find($conditions, $fields); 
    37          
    38         //die(var_dump($data)); 
    39          
    40           if ($data != false) 
    41           { 
    42              $this->User = new User; 
    43               
    44              $this->data['User']['id']       = $data['Confirm']['user_id']; 
    45              $this->data['User']['active']   = 1; 
    46               
    47              if ($this->User->save($this->data) && $this->Confirm->delete($data['Confirm']['id'])) 
    48              { 
    49                  $this->flash('Your account has been activatedd', '/users/login'); 
    50              } 
    51              else 
    52              { 
     32 public function signup($secret = null) 
     33 {  
     34   $this->pageTitle = 'Active User Account'; 
     35    
     36   $conditions      = array("secret" => $secret); 
     37    
     38   $fields          = array('id', 'user_id'); 
     39    
     40   $data            = $this->Confirm->find($conditions, $fields); 
     41    
     42   //die(var_dump($data)); 
     43    
     44   if ($data != null) 
     45   { 
     46     $this->User = new User; 
     47      
     48     $this->data['User']['id']       = $data['Confirm']['user_id']; 
     49     $this->data['User']['active']   = 1; 
     50      
     51     if ($this->User->save($this->data) && $this->Confirm->delete($data['Confirm']['id'])) 
     52     { 
     53                 $this->flash('Your account has been activated', '/users/login'); 
     54     } 
     55     else 
     56     { 
    5357                 $this->flash('Problem, please report to support@mononeurona.org', '/users/login'); 
    54              } 
    55           } 
    56           else 
    57           { 
     58     } 
     59   } 
     60   else 
     61   { 
    5862             $this->flash('There is not such account', '/users/login'); 
    59           } 
    60     } 
    61  
     63   } 
     64 } 
    6265} 
    6366?> 
  • trunk/app/controllers/entries_controller.php

    r301 r339  
    1414 public $components    = array('Edublog', 'Portal'); 
    1515 
     16  public function beforeFilter()  
     17 { 
     18    $this->Auth->allow(array('rss', 'search')); 
     19    parent::beforeFilter(); 
     20 } 
     21  
    1622 public function isAuthorized()  
    1723 {       
     
    2632 } 
    2733 
    28  public function results($string)  
    29  { 
    30       $this->layout = 'portal'; 
    31        
    32       $conditions   = array("Entry.body"=>$string); 
    33        
    34       $this->set('data', $this->Entry->findAll($conditions, $order)); 
    35  } 
    36     
    3734 public function rss($username) 
    3835 { 
  • trunk/app/controllers/forums_controller.php

    r333 r339  
    1313  
    1414 public $components    = array('Edublog'); 
    15  
    16  public function isAuthorized() 
     15  
     16 public function beforeFilter()  
    1717 { 
    18       if (isset($this->params[Configure::read('Routing.admin')])) 
    19       { 
    20                  if ($this->Auth->user('group_id') == 1 || $this->Auth->user('group_id') == 2) 
    21                  { 
    22                       return true; 
    23                  } 
    24       } 
    25       return false; // go away!! 
     18    $this->Auth->allow(array('display', 'discussion', 'view')); 
     19    parent::beforeFilter(); 
    2620 } 
    27  
     21  
     22 public function isAuthorized()  
     23 {       
     24    if (isset( $this->params[Configure::read('Routing.admin')] ))  
     25    { 
     26        if ($this->Auth->user('group_id') == 1 || $this->Auth->user('group_id') == 2 )  // admin and teachers 
     27        { 
     28        return true; 
     29        }  
     30    }  
     31    return false;  // go away !! 
     32 } 
     33  
    2834 public function display($forum_id)  
    2935 {       
     
    7985 } 
    8086  
     87 /* === ADMIN METHODS == */ 
    8188 public function admin_listing()  
    8289 {   
  • trunk/app/controllers/recovers_controller.php

    r338 r339  
    1212 public $helpers       = array('Javascript', 'Ajax', 'Form', 'Fck'); 
    1313  
    14  public $components    = array('Security', 'Portal', 'Adds'); 
     14 public $components    = array('Security', 'Portal', 'Email', 'Adds'); 
    1515  
    16   public function beforeFilter()  
     16 public function beforeFilter()  
    1717 { 
    18     $this->Auth->allow(array('check', 'display', 'recover')); 
     18    $this->Auth->allow(array('check', 'newpwd', 'recover')); 
    1919    parent::beforeFilter(); 
    2020 } 
     
    4949        if ( !empty( $this->data["User"] ) ) 
    5050        { 
    51            $user_id = $this->Recover->User->field('id', array("email" => $this->data["User"]["email"] )); 
     51           $user_id = $this->Recover->User->field('id', array('email' => $this->data['User']['email'], 'active'=>1)); 
    5252            
    5353           if ($user_id == null) 
    5454           { 
    55                    $this->set('error_message', "Error: email <b>" . $this->data["User"]["email"] . "</b> does not exist on database"); 
    56                    $this->render('check', 'ajax'); 
     55               $this->set('error_message', "Error: email <b>" . $this->data["User"]["email"] . "</b> does not exist on database"); 
     56               $this->render('check', 'ajax'); 
    5757           } 
    58            else 
     58           else  // email exist