/** * 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 primary key value. Defaults to null, meaning using the 'id' GET variable */ public function loadModel() { if ($this->_nw === null) { if ($id !== isset($_GET['id'])) { $this->_nw = Network::model()->findByPk($_GET['id']); } if ($this->_nw === null || $this->_nw->userId != Yii::app()->user->id) { throw new CHttpException(404, 'The requested network does not exist.'); } } return $this->_nw; }
public function authenticate($uloginModel = null) { $criteria = new CDbCriteria(); $criteria->condition = 'identity=:identity AND network=:network'; $criteria->params = array(':identity' => $uloginModel->identity, ':network' => $uloginModel->network); $userNetwork = Network::model()->find($criteria); if (null !== $userNetwork) { $user = $userNetwork->user; $this->id = $user->id; $this->name = $user->email; } else { $user = new User(); $user->email = $uloginModel->email; $user->firstName = $uloginModel->first_name; $user->lastName = $uloginModel->last_name; $user->sex = $uloginModel->sex; $user->phone = $uloginModel->phone; $user->bDate = $this->convertDate($uloginModel->bdate); $user->city = $uloginModel->city; $user->country = $uloginModel->country; $user->ava = $uloginModel->photo; $user->ava_full = $uloginModel->photo_big; $user->activated = true; if (!$user->save()) { return false; } $nw = new Network(); $nw->identity = $uloginModel->identity; $nw->network = $uloginModel->network; $nw->userId = $user->id; $nw->save(); $this->id = $user->id; $this->name = $user->username; } $this->isAuthenticated = true; return true; }