Ejemplo n.º 1
0
 public function setProfilePic($value)
 {
     if (!is_numeric($value)) {
         return false;
     }
     while (count($this->userToContents) > 0) {
         $this->userToContents[0]->delete();
     }
     $userToContent = new UserToContent();
     $userToContent->Content_ID = $value;
     $userToContent->User_ID = $this->User_ID;
     $saved = $userToContent->save();
     return $saved;
 }
Ejemplo n.º 2
0
 public function actionUpdate()
 {
     $id = Yii::app()->user->id;
     $model = $this->loadModel($id);
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $imageFile = CUploadedFile::getInstanceByName('profilePic');
     if ($imageFile != null) {
         $imageContent = Content::AddContent($imageFile, 'User Image', ContentType::ImageID, 1);
         if ($imageContent != null) {
             $userToContent = new UserToContent();
             $userToContent->User_ID = $model->User_ID;
             $userToContent->Content_ID = $imageContent->Content_ID;
             $userToContent->save();
         }
     }
     $this->redirect(array('view', 'id' => $model->User_ID));
 }
Ejemplo n.º 3
0
 /**
  * Main method to handle login attempts.  If the user passes authentication with their
  * chosen provider then it displays a form for them to choose their username and email.
  * The email address they choose is *not* verified.
  *
  * If they are already logged in then it links the new provider to their account
  *
  * @throws Exception if a provider isn't supplied, or it has non-alpha characters
  */
 private function _doLogin()
 {
     if (!isset($_GET['provider'])) {
         throw new Exception("You haven't supplied a provider");
     }
     if (!ctype_alpha($_GET['provider'])) {
         throw new Exception("Invalid characters in provider string");
     }
     $identity = new RemoteUserIdentity($_GET['provider'], $this->module->getHybridauth());
     if ($identity->authenticate()) {
         // They have authenticated AND we have a user record associated with that provider
         if (Yii::app()->user->isGuest) {
             $this->_loginUser($identity);
         } else {
             //they shouldn't get here because they are already logged in AND have a record for
             // that provider.  Just bounce them on
             $this->redirect(Yii::app()->user->returnUrl);
         }
     } else {
         if ($identity->errorCode == RemoteUserIdentity::ERROR_USERNAME_INVALID) {
             // They have authenticated to their provider but we don't have a matching HaLogin entry
             if (Yii::app()->user->isGuest) {
                 // They aren't logged in => display a form to choose their username & email
                 // (we might not get it from the provider)
                 if ($this->module->withYiiUser == true) {
                     Yii::import('application.modules.user.models.*');
                 } else {
                     Yii::import('application.models.*');
                 }
                 $adapter = $identity->getAdapter();
                 $profile = $adapter->getUserProfile();
                 $user = new User();
                 if (isset($profile->email)) {
                     $user->Email = $profile->email;
                 }
                 if (isset($profile->firstName)) {
                     $user->First_name = $profile->firstName;
                 }
                 if (isset($profile->lastName)) {
                     $user->Last_name = $profile->lastName;
                 }
                 if (isset($profile->phone)) {
                     $user->Phone_number = $profile->phone;
                 }
                 $user->save(false);
                 if (isset($profile->photoURL)) {
                     $photoURL = $profile->photoURL;
                     if (!strstr($photoURL, '?')) {
                         $photoURL .= '?width=400&height=400';
                     } else {
                         $photoURL .= '&width=400&height=400';
                     }
                     $content = Content::model()->AddContentFromURL($photoURL, 'User Image Link', ContentType::ImageURL);
                     $userToContent = new UserToContent();
                     $userToContent->Content_ID = $content->Content_ID;
                     $userToContent->User_ID = $user->User_ID;
                     $userToContent->save();
                 }
                 $identity->id = $user->User_ID;
                 $this->_linkProvider($identity);
                 $this->_loginUser($identity);
             } else {
                 // They are already logged in, link their user account with new provider
                 $identity->id = Yii::app()->user->id;
                 $this->_linkProvider($identity);
                 $this->redirect(Yii::app()->session['hybridauth-ref']);
                 unset(Yii::app()->session['hybridauth-ref']);
             }
         }
     }
 }