Ejemplo n.º 1
0
 public function authenticate()
 {
     //cerco l'utente $this->username nella classe User
     //Controllo nel DB Utenti per default  si controlla nella Tbl Utenti
     //$record=User::model()->findByAttributes(array('username'=>$this->username));
     //il rigo seguente  chiama il model utenti  per fare l'autenticazione.
     $record = Utenti::model()->findByAttributes(array('username' => $this->username));
     //e non lo trovo
     if ($record === null) {
         $this->errorCode = self::ERROR_USERNAME_INVALID;
     } else {
         if ($record->password !== $this->password) {
             $this->errorCode = self::ERROR_PASSWORD_INVALID;
         } else {
             //mi segno l'id dell'utente autenticato
             $this->_id = $record->id;
             $this->setState('email', $record->email);
             $this->setState('id', $record->id);
             $this->setState('title', 'titolo');
             // metto in variabile il nome
             $this->setState('nome', $record->nome);
             /* se voglio mi posso memorizzare in sessione altri dati dell'utente loggato
                $this->setState('title', 'titolo');
                $this->setState('cognome', $record->cognome);
                Yu::app()->user->titolo
                Qui ci sono maggiori informazioni in merito per estendere la classe User
                http://www.yiiframework.com/forum/index.php?/topic/22225-yiiapp-user-name-extender
                */
             $this->errorCode = self::ERROR_NONE;
             //nessun errore, tutto ok!
         }
     }
     return !$this->errorCode;
     //true = do il conseso a loggare l'utente
 }
 public function actionIndex()
 {
     $argomenti = Argomenti::model()->FindAll(array('order' => 'Titolo'));
     $moderatori = Utenti::model()->getNamesById();
     $i = 0;
     foreach ($argomenti as $argomento) {
         $discussioni[$i++] = Discussioni::model()->findAll('Argomento =' . $argomento->ID);
     }
     $data['argomenti'] = $argomenti;
     $data['moderatori'] = $moderatori;
     $data['discussioni'] = $discussioni;
     $this->render('index', $data);
 }
Ejemplo n.º 3
0
 function run()
 {
     if (empty($_GET['id'])) {
         throw new CHttpException(404);
     }
     $model = Utenti::model()->findByPK($_GET['id']);
     if ($model === null) {
         throw new CHttpException(404);
     }
     $model->stato = $model->stato == 1 ? 0 : 1;
     if ($model->update()) {
         $this->controller->redirect(array('index'));
     }
     throw new CHttpException(500);
 }
Ejemplo n.º 4
0
 public function authenticate()
 {
     if (!$this->hasErrors()) {
         $record = Utenti::model()->findByAttributes(array('Email' => $this->username));
         if ($record === null) {
             $this->errorCode = self::ERROR_USERNAME_INVALID;
         } else {
             if ($this->password != $record->Password) {
                 $this->errorCode = self::ERROR_PASSWORD_INVALID;
             } else {
                 $this->_identity = new UserIdentity($record->Email, $record->Password);
                 $this->_identity->setState("Name", $record->Nome);
                 return $this->_identity;
                 //$this->errorCode=self::ERROR_NONE;
             }
         }
         return !$this->errorCode;
     }
 }
Ejemplo n.º 5
0
 public function getNamesById()
 {
     $utenti = Utenti::model()->findAll();
     $r;
     foreach ($utenti as $utente) {
         $r[$utente->ID] = $utente->Nome . " " . $utente->Cognome;
     }
     return $r;
 }
Ejemplo n.º 6
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer the ID of the model to be loaded
  */
 public function loadModel($id)
 {
     $model = Utenti::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }