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 actionNewMessage() { $time=time(); if (isset($_POST['message']) && $_POST['message'] != '') { $user = Yii::app()->user->getName(); $chat = new Social; $chat->data = $_POST['message']; $chat->timestamp = $time; $chat->user = $user; $chat->type = 'chat'; if ($chat->save()) { echo '1'; } } }
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 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')); }
public function actionUpload() { if(isset($_FILES['upload'])) { $model=new Media; $temp = CUploadedFile::getInstanceByName('upload'); $name=$temp->getName(); $name=str_replace(' ','_',$name); $check=Media::model()->findAllByAttributes(array('fileName'=>$name)); if(count($check)!=0) { $count=1; $newName=$name; $arr=explode('.',$name); $name=$arr[0]; while(count($check)!=0){ $newName=$name.'('.$count.').'.$temp->getExtensionName(); $check=Media::model()->findAllByAttributes(array('fileName'=>$newName)); $count++; } $name=$newName; } if($temp->saveAs('uploads/'.$name)) { $model->associationId=$_POST['associationId']; $model->associationType=$_POST['type']; $model->uploadedBy=Yii::app()->user->getName(); $model->createDate=time(); $model->fileName=$name; if($model->save()){ } if($model->associationType=='feed') { $soc = new Social; $soc->user = Yii::app()->user->getName(); $soc->data = Yii::t('app','Attached file: '). $soc->type = 'feed'; $soc->timestamp = time(); $soc->lastUpdated = time(); $soc->associationId = $model->associationId; $soc->data = CHtml::link($model->fileName,array('media/view','id'=>$model->id)); if($soc->save()) { $this->redirect(array('profile/'.$model->associationId)); } else { unlink('uploads/'.$name); } $this->redirect(array($model->associationType.'/'.$model->associationId)); } else if($model->associationType=='bg' || $model->associationType=='bg-private') { $profile=CActiveRecord::model('ProfileChild')->findByPk(Yii::app()->user->getId()); $profile->backgroundImg = $name; $profile->save(); $this->redirect(array('profile/settings','id'=>Yii::app()->user->getId())); } else { $note=new ActionChild; $note->createDate = time(); $note->dueDate = time(); $note->completeDate = time(); $note->complete='Yes'; $note->visibility='1'; $note->completedBy=Yii::app()->user->getName(); $note->assignedTo='Anyone'; $note->type='attachment'; $note->associationId=$_POST['associationId']; $note->associationType=$_POST['type']; $association = $this->getAssociation($note->associationType,$note->associationId); if($association != null) $note->associationName = $association->name; $note->actionDescription = $model->fileName . ':' . $model->id; if($note->save()){ } else { unlink('uploads/'.$name); } $this->redirect(array($model->associationType.'/'.$model->associationId)); } } } }
/** * Add a personal note to the list of notes for the current web user. */ public function actionAddPersonalNote() { if (isset($_POST['note-message']) && $_POST['note-message'] != '') { $user = Yii::app()->user->getName(); $note = new Social(); $note->associationId = Yii::app()->user->getId(); $note->data = $_POST['note-message']; $note->user = $user; $note->visibility = 1; $note->timestamp = time(); $note->type = 'note'; if ($note->save()) { echo "1"; } } }
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')); } }
public function updItem($data) { $this->social->save(); }
/** * * @param $action string * @param $id int * @return nothing * @author Tremor */ public function socialAction($action, $id = 0) { if (isset($id) && !empty($id) && !is_numeric($id)) { return Redirect::to('admin/social'); } switch ($action) { case 'add': $social = new Social(); $social->save(); $newId = $social->id; return Redirect::to('admin/social/' . $newId); break; case 'edit': $post = Input::except('_token'); // $affectedRows = Category::where('id', $categoryId)->update($post); $social = Social::find($id); foreach ($post as $key => $val) { if (isset($social->{$key})) { $social->{$key} = $val; } } $social->save(); return Redirect::to('admin/social/' . $id); break; case 'delete': $social = Social::find($id); $social->delete(); break; default: break; } return Redirect::to('admin/social'); }
/** * Авторизация пользователя * @param string $login Логин или email пользователя * @param string $password Пароль пользователя * @param boolean $remember Чужой компьютер * @return boolean Результат авторизации */ public static function login($login, $password, $remember = true) { if (!empty($login) && !empty($password)) { $field = strpos($login, '@') ? 'email' : 'login'; $user = User::first(array('conditions' => array("{$field}=?", $login))); if ($user && password_verify($password, $user->password)) { if ($remember) { setcookie('id', $user->id, time() + 3600 * 24 * 365, '/', $_SERVER['HTTP_HOST'], null, true); setcookie('pass', md5($user->password . env('APP_KEY')), time() + 3600 * 24 * 365, '/', $_SERVER['HTTP_HOST'], null, true); } $user->update_attribute('reset_code', null); $_SESSION['id'] = $user->id; $_SESSION['pass'] = md5(env('APP_KEY') . $user->password); if (!empty($_SESSION['social'])) { $social = new Social(); $social->user_id = $user->id; $social->network = $_SESSION['social']->network; $social->uid = $_SESSION['social']->uid; $social->save(); } return $user; } } return false; }