/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. */ public function actionEdit() { $model = $this->loadUser(); $social = Social::model()->find("provider='facebook' AND yiiuser=" . Yii::app()->user->id); $profile = $model->profile; UWprofilepic::handleProfilePic($model, $profile); // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'profile-form') { echo UActiveForm::validate(array($model, $profile)); Yii::app()->end(); } if (isset($_POST['Profile'])) { $model->attributes = $_POST['User']; $profile->attributes = $_POST['Profile']; if ($model->validate() && $profile->validate()) { $model->save(); $profile->save(); Yii::app()->user->setFlash('success', 'Your changes have been saved successfully.'); $this->redirect('/user/profile/edit/'); } else { $profile->validate(); } } $this->render('edit', array('model' => $model, 'social' => $social, 'profile' => $profile)); }
public function testAfterDelete() { $user = User::model()->findByPk('2'); if (X2_TEST_DEBUG_LEVEL > 1) { /**/ print 'id of user to delete: '; /**/ print $user->id; } // test calendar permissions deletion $this->assertNotEquals(0, sizeof(X2CalendarPermissions::model()->findAllByAttributes(array('user_id' => $user->id)))); $this->assertNotEquals(0, sizeof(X2CalendarPermissions::model()->findAllByAttributes(array('other_user_id' => $user->id)))); // assert that group to user records exist for this user $this->assertTrue(sizeof(GroupToUser::model()->findAllByAttributes(array('userId' => $user->id))) > 0); $this->assertTrue($user->delete()); X2_TEST_DEBUG_LEVEL > 1 && (print 'looking for groupToUser records with userId = ' . $user->id); GroupToUser::model()->refresh(); // assert that group to user records were deleted $this->assertTrue(sizeof(GroupToUser::model()->findAllByAttributes(array('userId' => $user->id))) === 0); // test profile deletion $this->assertTrue(sizeof(Profile::model()->findAllByAttributes(array('username' => $user->username))) === 0); // test social deletion $this->assertTrue(sizeof(Social::model()->findAllByAttributes(array('user' => $user->username))) === 0); $this->assertTrue(sizeof(Social::model()->findAllByAttributes(array('associationId' => $user->id))) === 0); // test event deletion $this->assertTrue(sizeof(Events::model()->findAll("user=:username OR (type='feed' AND associationId=" . $user->id . ")", array(':username' => $user->username))) === 0); // test calendar permissions deletion $this->assertEquals(0, sizeof(X2CalendarPermissions::model()->findAllByAttributes(array('user_id' => $user->id)))); $this->assertEquals(0, sizeof(X2CalendarPermissions::model()->findAllByAttributes(array('other_user_id' => $user->id)))); }
public function workOnUser($provider, $provideruser) { $userClass = Yii::app()->controller->module->userClass; $social = Social::model()->find("provider='" . $provider . "' AND provideruser='******'"); if ($social) { $user = $userClass::model()->find("id=" . $social->yiiuser); return $user; } else { // no user is connected to that provideruser, $social = new Social(); // a new relation will be needed $social->provider = $provider; // what provider $social->provideruser = $provideruser; // the unique user // if a yii-user is already logged in add the provideruser to that account if (!Yii::app()->user->isGuest) { $social->yiiuser = Yii::app()->user->id; $user = $userClass::model()->findByPk(Yii::app()->user->id); } else { // we want to create a new $userClass $user = new $userClass(); $user->username = $provideruser; if ($user->save()) { //we get an user id $social->yiiuser = $user->id; } } if ($social->save()) { return $user; } } }
public function loadModel($id) { $model = Social::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function run() { $content = Social::model()->findByAttributes(array('type' => 'motd')); if (isset($content)) { $content = CHtml::encode($content->data); } else { $content = Yii::t('app', 'Please enter a message of the day!'); } $this->render('messageBox', array('content' => $content)); }
public function run() { $content = Social::model()->findAllByAttributes(array('type' => 'note', 'associationId' => Yii::app()->user->getId()), array('order' => 'timestamp DESC')); if (count($content) > 0) { $data = $content; } else { $soc = new Social(); $soc->data = Yii::t('app', "Feel free to enter some notes!"); $data = array($soc); } $this->render('noteBox', array('data' => $data)); }
/** * 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 = null, $userid = null) { if ($id) { $model = Social::model()->findByPk($id); } if ($userid) { $model = Social::model()->find("yiiuser = '******'"); } if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function workOnUser($provider, $provideruser, $profile) { // $provideruser has profile details from provider $social = Social::model()->find("provider='" . $provider . "' AND provideruser='******'"); if ($social) { $user = User::model()->find("id=" . $social->yiiuser); // $user['yiiuser'] has app user id return $user; } else { // no user is connected to that provideruser, $social = new Social(); // a new relation will be needed $social->provider = $provider; // what provider $social->provideruser = $provideruser; // the unique user // if a yii-user is already logged in add the provideruser to that account if (!Yii::app()->user->isGuest) { $social->yiiuser = Yii::app()->user->id; $user = User::model()->findByPk(Yii::app()->user->id); lg('Existing user' . $social->yiiuser); lg('Existing user email' . $user->email); // capture profile info $user_profile = Yii::app()->getModule('user')->user($social->yiiuser)->profile; $user->model()->syncProfileViaHybridAuth($user_profile, $profile); } else { lg('Facebook email: ' . $profile->email); $user = User::model()->findByAttributes(array('email' => $profile->email)); if (!is_null($user)) { // to do - create way to associate facebook account Yii::app()->user->setFlash('email_problem', 'Your email already exists. Please log in to your account with your email.'); Yii::app()->user->setReturnUrl('/user/profile/edit'); $this->redirect('/user/login'); } if ($profile->email == '') { lg('Hybrid: No email, report error & redirect user'); Yii::app()->user->setFlash('email_problem', 'We require your email for registration.'); $this->redirect('/user/registration'); } // we want to create a new user // take new profile info and register user lg('New user'); $user_id = User::model()->registerViaHybridAuth($profile); if ($user_id !== false) { $user = User::model()->findByPk($user_id); $social->yiiuser = $user->id; } // to do - if no new user_id // then social id is 0 and future log in will fail // return with new user id } if ($social->save()) { return $user; } } }
public function afterDelete() { // delete related social records (e.g. notes) $social = Social::model()->findAllByAttributes(array('user' => $this->username)); foreach ($social as $socialItem) { $socialItem->delete(); } $social = Social::model()->findAllByAttributes(array('associationId' => $this->id)); foreach ($social as $socialItem) { $socialItem->delete(); } X2CalendarPermissions::model()->deleteAllByAttributes(array(), 'user_id=:userId OR other_user_id=:userId', array(':userId' => $this->id)); // delete profile $prof = Profile::model()->findByAttributes(array('username' => $this->username)); if ($prof) { $prof->delete(); } // delete associated events Yii::app()->db->createCommand()->delete('x2_events', "user=:username OR (type='feed' AND associationId=" . $this->id . ")", array(':username' => $this->username)); // Delete associated group to user records GroupToUser::model()->deleteAll(array('condition' => 'userId=' . $this->id)); parent::afterDelete(); }
public function actionAddComment(){ $soc=new Social; if(isset($_GET['comment'])){ $soc->data=$_GET['comment']; $id=$_GET['id']; $model=Social::model()->findByPk($id); $soc->user=Yii::app()->user->getName(); $soc->type='comment'; $soc->timestamp=time(); $soc->associationId=$id; $model->lastUpdated=time(); if($soc->save() && $model->save()){ } } if(isset($_GET['redirect'])) { if($_GET['redirect']=="view") $this->redirect(array('view','id'=>$model->associationId)); if($_GET['redirect']=="index") $this->redirect(array('index')); } else $this->redirect(array('index')); }
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED * OF THE POSSIBILITY OF SUCH DAMAGE. ********************************************************************************/ $authorRecord = User::model()->findByAttributes(array('username' => $data->user)); $author = $authorRecord->firstName . ' ' . $authorRecord->lastName; ?> <div class="view"> <div class="deleteButton"> <?php $parent = Social::model()->findByPk($data->associationId); if ($data->user == Yii::app()->user->getName() || $parent->associationId == Yii::app()->user->getId()) { echo CHtml::link('[x]', array('deletePost', 'id' => $data->id, 'redirect' => Yii::app()->controller->action->id)); } //,array('class'=>'x2-button') ?> </div> <?php echo CHtml::link($author, array('profile/view', 'id' => $authorRecord->id)); ?> <span class="comment-age"><?php echo x2base::timestampAge(date("Y-m-d H:i:s", $data->timestamp)); ?> </span><br /> <?php echo $this->convertUrls(CHtml::encode($data->data));
public function actionDeleteMessage($id,$url){ $note=Social::model()->findByPk($id); $note->delete(); $this->redirect($url); }
public function actionAddComment() { $soc = new Social(); if (isset($_GET['comment'])) { $soc->data = $_GET['comment']; $id = $_GET['id']; $model = Social::model()->findByPk($id); $soc->user = Yii::app()->user->getName(); $soc->type = 'comment'; $soc->timestamp = time(); $soc->associationId = $id; $model->lastUpdated = time(); if ($soc->save() && $model->save()) { $notif = new Notifications(); $prof = CActiveRecord::model('ProfileChild')->findByAttributes(array('username' => $soc->user)); $notif->text = "{$prof->fullName} added a comment to a post."; $notif->record = "profile:{$model->associationId}"; $notif->viewed = 0; $notif->createDate = time(); $subject = CActiveRecord::model('ProfileChild')->findByAttributes(array('username' => $model->user)); $notif->user = $subject->username; if ($notif->user != Yii::app()->user->getName()) { $notif->save(); } $notif = new Notifications(); $prof = CActiveRecord::model('ProfileChild')->findByAttributes(array('username' => $soc->user)); $subject = CActiveRecord::model('ProfileChild')->findByPk($model->associationId); $notif->text = "{$prof->fullName} added a comment to a post."; $notif->record = "profile:{$model->associationId}"; $notif->viewed = 0; $notif->createDate = time(); $notif->user = $subject->username; if ($notif->user != Yii::app()->user->getName()) { $notif->save(); } } } if (isset($_GET['redirect'])) { if ($_GET['redirect'] == "view") { $this->redirect(array('view', 'id' => $model->associationId)); } if ($_GET['redirect'] == "index") { $this->redirect(array('index')); } } else { $this->redirect(array('index')); } }
<?php $this->layout = "ajax"; ?> <h4> By connecting a social provider to your account you can use it to login<h4> <?php $socials = Social::model()->findAll('yiiuser='******'<i class="icon-remove icon-white"></i>Delete', array(''), array('class' => 'btn btn-mini btn-danger social_delete', 'id' => $social->id)); echo '* <b>' . $social->provider . '</b>'; echo '<div id="delete_social_' . $social->id . '" style="display:none"></div><br/>'; } } $this->widget('LoginWidget'); //displays the possible providers ?> <script type="text/javascript"> $(".social_delete").click(function(){ deletesocial($(this).attr('id')); }); function deletesocial( id ) { url = '/yiiauth/social/delete'; jQuery.getJSON(url, {id: id}, function(data) { if (data.status == 'success') { $('#delete_social_'+id).html(data.div); $('#delete_social_'+id).fadeIn('slow');