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

Update permission by individual controller rather than general

Files:
1 modified

Legend:

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

    r336 r339  
    1919 public function beforeFilter()  
    2020 { 
    21     $this->Auth->allow(array('blog', 'entry','portfolio', 'about', 'check', 'register', 'directory', 'bloggers')); 
     21    $this->Auth->allow(array('blog', 'entry','portfolio', 'about', 'register', 'directory', 'bloggers', 'insert')); 
    2222    parent::beforeFilter(); 
    2323 } 
     
    336336       $message['email_exist'] = "The email already exist "; 
    337337    } 
    338     // the user try to be a teacher 
    339     if ( $this->data['User']['group_id'] == 2)  
    340     { 
    341        // get the secret code for teachers registration process 
    342       $code  = $this->User->Group->field('code', array("id"=>2)); 
    343  
    344       if ( $this->data['User']['code'] != $code ) 
    345       { 
    346         $message['wrong_code'] = "The teacher's code is incorrect"; 
    347       } 
     338     
     339    // get the secret code for teachers registration process 
     340    $code  = $this->User->Group->field('code', array("id"=>$this->data['User']['group_id'])); 
     341     
     342    if ( $this->data['User']['code'] != $code ) 
     343    { 
     344        $message['wrong_code'] = "The code is incorrect, please put in contact with your school webmaster."; 
    348345    } 
    349346     
     
    351348    {   
    352349       $this->set('message', $message); 
    353        die($this->render('validate', 'ajax')); //if error exist, stop here 
    354     } 
    355      
    356      
    357     $this->data['User']['pwd']    = md5($this->data['User']['pwd']); // MD5 
    358     $this->data['User']['active']    = 0; 
    359     $this->data['User']['name_blog'] = $this->data['User']['username'].'\'s corner';  
     350       $this->render('validate', 'ajax'); //if error exist, stop here 
     351       exit; 
     352    } 
     353     
     354    $this->data['User']['active']     = 0; 
     355    $this->data['User']['name_blog']  = $this->data['User']['username'].'\'s corner';  
    360356    $this->User->create(); 
    361357    //exit(var_dump($this->data["User"])); 
    362     if ($this->User->save($this->data["User"])) 
     358    if ($this->User->save($this->data['User'])) 
    363359    {   
    364360        $this->data['Confirm']['user_id']  = $this->User->getLastInsertID();   // the user id 
    365361        $this->data['Confirm']['secret']   = $this->Adds->genPassword(14);     // secret confirm ID 
    366  
    367         // put the user in confirm model, this is, waiting confirmation 
     362     
     363    $this->User->Confirm->create(); 
     364         
     365        // put the user in confirm model, this is, waiting for user confirmation trough email 
    368366        if ($this->User->Confirm->save($this->data["Confirm"]))   
    369367        { 
    370368          //Send the confirmation email 
    371           if ( $this->sendMail($this->data['User']['email'], $this->data['Confirm']['secret']) )  
     369          if ( $this-> _sendNewUserPwd($this->data['User']['email'], $this->data['Confirm']['secret']) )  
    372370          {  
    373371            $msg  = "<h2>You have been registered!</h2> <p>A confirmation email has been sent to: ".$this->data['User']['email']; 
    374         $msg .= " In order to complete the registration process, please click on the link contained on the email.In order to complete the registration process, please click on the link contained on the email.</p>"; 
     372        $msg .= "In order to complete the registration process, please click on the link contained on the email.</p>"; 
    375373            $this->set('message', array("Suceess"=>$msg));  
    376374            $this->set('ok', true); 
     
    503501 
    504502 /****   AVATAR   ***/ 
    505  public function avatar()  
     503 public function admin_avatar()  
    506504 { 
    507505    $this->layout    = 'admin'; 
     
    619617} 
    620618 
    621   /** Private functions */ 
    622 private function get_extension($imagetype)  
    623 {     
    624      if ( empty($imagetype) ) 
    625      { 
    626          return false; 
    627      } 
    628       
    629      switch($imagetype) 
    630      { 
    631            case 'image/bmp': return '.bmp'; 
    632            case 'image/cis-cod': return '.cod'; 
    633            case 'image/gif': return '.gif'; 
    634            case 'image/ief': return '.ief'; 
    635            case 'image/jpeg': return '.jpg'; 
    636            case 'image/pipeg': return '.jfif'; 
    637            case 'image/tiff': return '.tif'; 
    638            case 'image/x-cmu-raster': return '.ras'; 
    639            case 'image/x-cmx': return '.cmx'; 
    640            case 'image/x-icon': return '.ico'; 
    641            case 'image/x-portable-anymap': return '.pnm'; 
    642            case 'image/x-portable-bitmap': return '.pbm'; 
    643            case 'image/x-portable-graymap': return '.pgm'; 
    644            case 'image/x-portable-pixmap': return '.ppm'; 
    645            case 'image/x-rgb': return '.rgb'; 
    646            case 'image/x-xbitmap': return '.xbm'; 
    647            case 'image/x-xpixmap': return '.xpm'; 
    648            case 'image/x-xwindowdump': return '.xwd'; 
    649            case 'image/png': return '.png'; 
    650            case 'image/x-jps': return '.jps'; 
    651            case 'image/x-freehand': return '.fh'; 
    652            default: return false; 
    653        } 
    654   } 
    655  
    656 private function sendMail($email, $secret)  
    657 {        
    658         $this->Email->sender    = '::MonoNeurona.org::'; 
    659         $this->Email->to        = $email; 
    660         $this->Email->subject   = 'Confirm karamelo activation account'; 
    661         //$this->Email->replyTo   = 'noreply@mononeurona.org'; 
    662         $this->Email->sendAs    = 'html'; 
    663         $this->Email->template  = null; 
    664         $this->Email->from      = 'noreply@ononeurona.org'; 
    665         //$this->set('foo', 'Cake tastes good today');  
    666         //Set the body of the mail as we send it. 
    667         //Note: the text can be an array, each element will appear as a 
    668         //seperate line in the message body. 
    669          
    670         $url  = '<h2>Karamelo</h2><p>Open this in new tab to confirm: '; 
    671         $url .= '<a href="http://'.$_SERVER['SERVER_NAME'].'/confirms/signup/'.$secret.'">'; 
    672         $url .= 'http://'.$_SERVER['SERVER_NAME'].'/confirms/signup/'.$secret.'</a></p>'; 
    673          
    674         //die($url); 
    675          
    676         if ( $this->Email->send($url) )  
    677         { 
     619/* == PRIVATE == **/ 
     620private function _sendNewUserPwd($email, $random) 
     621{    
     622    $this->layout          = 'confirmation'; 
     623    $this->Email->to       = $email; 
     624    //$this->Email->bcc    = array('noreply@karamelo.org');  // note 
     625    // this could be just a string too 
     626    $this->Email->subject  = 'Karamelo e-Learning:: confirma account'; 
     627    $this->Email->replyTo  = 'support@karamelo.org'; 
     628    $this->Email->from     = 'Chipotle-software.com'; 
     629    $this->Email->template = 'confirmation'; // note no '.ctp' 
     630    //Send as 'html', 'text' or 'both' (default is 'text') 
     631    $this->Email->sendAs   = 'text'; // because we like to send pretty mail 
     632    //Set view variables as normal 
     633    $this->set('random', $random); 
     634    //Do not pass any args to send()  
     635    if ( $this->Email->send() )  
     636    { 
    678637            return true;  
    679         }  
    680         else  
    681         { 
    682            exit("Error!!"); 
    683         } 
    684  }  
     638    }  
     639    else 
     640    { 
     641            return false; 
     642    } 
     643 } 
    685644} 
    686645?>