Changeset 480

Show
Ignore:
Timestamp:
05/13/08 00:50:52 (7 months ago)
Author:
aarkerio
Message:

Messages to all class

Location:
trunk/app
Files:
3 added
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/controllers/messages_controller.php

    r477 r480  
    1414 public $components    = array('Portal', 'Security', 'Email', 'Session', 'Edublog'); 
    1515  
    16   public function beforeFilter()  
    17  { 
    18     $this->Auth->allow(array('message', 'deliver')); 
     16 public function beforeFilter()  
     17 { 
     18    $this->Auth->allow(array('message', 'deliver', 'listing', 'compose')); 
    1919    parent::beforeFilter(); 
    2020 } 
     
    100100 } 
    101101 
     102 public function listing() 
     103 { 
     104   if ( !$this->Auth->user() ): 
     105         $this->redirect('/users/login'); 
     106         return false;         
     107   endif; 
     108 
     109   $this->layout    = 'portal'; 
     110       
     111   $this->pageTitle = 'Messages'; 
     112       
     113   $conditions      = array("Message.user_id" => $this->Auth->user('id')); 
     114   fields          = array("Message.id", "Message.title", "Message.body", "Message.created", "Message.sender", "Message.status", "User.username"); 
     115      $order           = "Message.id DESC"; 
     116      $limit           = 20; 
     117       
     118      $this->set('data', $this->Message->findAll($conditions, $fields, $order, $limit)); 
     119 
     120      $this->Portal->statics(); // Charge Portal components aka Sidebars 
     121 } 
     122 
     123 
    102124  /* == PRIVATE == **/ 
    103125  private function __sendMail($email) 
     
    113135    $this->Email->sendAs   = 'text'; // because we like to send pretty mail 
    114136    //Do not pass any args to send() 
    115     if ( $this->Email->send() ) 
    116     { 
     137    if ( $this->Email->send() ): 
    117138              return true; 
    118     } 
    119     else 
    120     { 
    121                 return false; 
    122     } 
     139    else: 
     140                  return false; 
     141    endif; 
    123142 } 
    124143 
  • trunk/app/controllers/users_controller.php

    r479 r480  
    1919 public function beforeFilter()  
    2020 { 
     21   if ( !empty($this->data['User'] ) ):  
     22       if ( strlen($this->data['User']['pwd']) < 6): 
     23         unset($this->data['User']['pwd']); 
     24       endif; 
     25   endif; 
     26 
    2127    $this->Auth->allow(array('blog', 'entry','portfolio', 'edit', 'about', 'register', 'directory', 'bloggers', 'insert', 'validate', 'logout')); 
    22     parent::beforeFilter(); 
    23  
    24     if ( !empty($this->data['User']['pwd']) ) 
    25     { 
    26         if ( strlen($this->data['User']['pwd']) < 5)   // only if pwd is big enough 
    27         { 
    28                  unset($this->data['User']['pwd']);       
    29         }    
    30     } 
     28   
     29  parent::beforeFilter(); 
    3130 } 
    3231   
    3332 public function isAuthorized()  
    3433 {       
    35     if (isset( $this->params[Configure::read('Routing.admin')] ))  
    36     { 
    37         if ($this->Auth->user('group_id') == 1 || $this->Auth->user('group_id') == 2 )  // admin and teachers 
    38         { 
    39         return true; 
    40         }  
    41     }  
     34    if (isset( $this->params[Configure::read('Routing.admin')] )): 
     35 
     36        if ($this->Auth->user('group_id') == 1 || $this->Auth->user('group_id') == 2 ):  // admin and teachers 
     37        return true; 
     38    endif;  
     39 
     40    endif;  
     41 
    4242    return false;  // go away !! 
    4343 } 
     
    409409  endif; 
    410410 
     411  $this->User->escapeField('pwd'); 
     412   
    411413  if ( empty($this->data['User']) ): 
    412414 
     
    415417      $this->Portal->statics(); // Using Portal components 
    416418         
    417       $this->User->unbindModel($this->User->notNow); 
    418              
     419      $this->User->unbindModel($this->User->notNow);         
     420       
    419421      $this->data = $this->User->read(null, $this->Auth->user('id')); 
    420422 
  • trunk/app/models/user.php

    r471 r480  
    5454 
    5555 public $validate = array( 
    56       'login'    => VALID_NOT_EMPTY, 
    57       'pwd' => VALID_NOT_EMPTY, 
    58       'username' => VALID_NOT_EMPTY, 
    59       'name' => VALID_NOT_EMPTY, 
    60       'email'    => VALID_EMAIL 
    61    ); 
    62   
     56              'login'    => VALID_NOT_EMPTY, 
     57              'pwd'      => VALID_NOT_EMPTY, 
     58              'username' => VALID_NOT_EMPTY, 
     59              'name'     => VALID_NOT_EMPTY, 
     60              'email'    => VALID_EMAIL 
     61               ); 
     62/*  
     63I will work on this later 
     64public $validate = array( 
     65            'username' => array('rule' => 'alphanumeric', 
     66                        'required' => true, 
     67                        'message' => 'Please enter a username'), 
     68            'pwd' => array('rule' => array('confirmPassword', 'password'), 
     69                        'message' => 'Passwords do not match'), 
     70            'pwd_confirm' => array('rule' => 'alphanumeric', 
     71                            'required' => true) 
     72            ); 
     73*/ 
     74 
     75public function confirmPassword($data)  
     76{ 
     77  $valid = false; 
     78         
     79  if ($data['password'] == Security::hash(Configure::read('Security.salt') . $this->data['User']['password_confirm']))  
     80  { 
     81      $valid = true; 
     82  }  
     83         
     84  return $valid; 
     85}  
     86 
    6387 /* 
    6488  * excepts : model you need 
     
    79103    return true; 
    80104  } 
     105 
     106 /* 
     107  * Remove pwd if too short 
     108  * 
     109  */ 
     110  public function beforeValidate() 
     111  { 
     112    
     113    if ( !empty($this->data['User']['pwd']) ): 
     114           die( debug($this->data['User']['pwd'])); 
     115          if ( strlen($this->data['User']['pwd']) < 6):   // only if pwd is big enough 
     116                 unset($this->data['User']['pwd']);       
     117      endif; 
     118 
     119    endif; 
     120 
     121 
     122    return true; 
     123  } 
    81124} 
    82125?>