protected function execute(array $arguments) { if (isset($arguments[0]) && ($user_id = (int) $GLOBALS['user_id'])) { $oauth = \UserOauth::findFirst(["user_id = :user_id: and app='pushbullet'", 'bind' => ['user_id' => $user_id]]); if ($oauth) { $token = $oauth->access_token; $pushbullet = new Pushbullet($token); $pushbullet->pushNote('', $arguments[0]); } return ''; } throw new InvalidArgumentException('strings invalid'); }
/** * Pocket * * @return \Phalcon\Http\ResponseInterface * @throws \Workflow\Exception\PocketException */ public function pocketAction() { $request_token = $this->request->get('request_token'); $pocket = new \Workflow\Api\Pocket(''); $pocket->setConfig($this->config); $access_token = $pocket->authorizeCode($request_token); $pocket_oauth = UserOauth::findFirst(["user_id = :user_id: and app = 'pocket'", 'bind' => ['user_id' => $this->current_user->id]]); if ($pocket_oauth) { $pocket_oauth->access_token = $access_token; $pocket_oauth->save(); // active UserActive::record('oauth-edit', $this->current_user->id); } else { $oauth = new UserOauth(); $oauth->user_id = $this->current_user->id; $oauth->app = 'pocket'; $oauth->access_token = $access_token; $oauth->create(); // active UserActive::record('oauth-create', $this->current_user->id); } return $this->response->redirect('user/app'); }
protected function execute(array $arguments) { if (isset($arguments[0]) && ($user_id = (int) $GLOBALS['user_id'])) { $oauth = \UserOauth::findFirst(["user_id = :user_id: and app='pocket'", 'bind' => ['user_id' => $user_id]]); if ($oauth) { global $config; $token = $oauth->access_token; $pocket = new Pocket($token); $pocket->setConfig($config); $pocket->addItem($arguments[0]); } return ''; } throw new InvalidArgumentException('strings invalid'); }
/** * Displays the login page */ public function actionLogin($service = null) { if ($service && isset(Yii::app()->eauth)) { /** @var EAuth $eauth */ $eauth = Yii::app()->eauth; $serviceIdentity = $eauth->getIdentity($service); $serviceIdentity->redirectUrl = Yii::app()->user->returnUrl; $serviceIdentity->cancelUrl = $this->createAbsoluteUrl('/login'); try { if ($serviceIdentity->authenticate() && $serviceIdentity->getIsAuthenticated()) { if (Yii::app()->user->isGuest) { $userOauth = UserOauth::model()->find('service = :service AND foreign_id = :id', array('service' => $service, 'id' => $serviceIdentity->getId())); if ($userOauth) { /** @var User $user */ $user = $userOauth->user; $userIdentity = new EAuthUserIdentity($serviceIdentity, $user); Yii::app()->user->login($userIdentity); $serviceIdentity->redirect(); } else { $eauthSession = isset(Yii::app()->session['eauth']) ? Yii::app()->session['eauth'] : array(); $eauthSession[$service] = $serviceIdentity->getAttributes(); Yii::app()->session['eauth'] = $eauthSession; $this->redirect(Yii::app()->getModule('user')->registrationUrl); } } else { /** @var User $user */ $exists = false; $user = User::model()->findByPk(Yii::app()->user->id); foreach ($user->userOauths as $userOauth) { if ($userOauth->service == $service && $userOauth->foreign_id == $serviceIdentity->getId()) { $exists = true; } } if (!$exists) { $userOauth = new UserOauth(); $userOauth->service = $service; $userOauth->foreign_id = $serviceIdentity->getId(); $userOauth->user_id = $user->id; $userOauth->save(); $user->resetCache(); } } } // Something went wrong, redirect to login page $this->redirect(array('/login')); } catch (EAuthException $e) { // save authentication error to session Yii::app()->user->setFlash('error', 'EAuthException: ' . $e->getMessage()); // close popup window and redirect to cancelUrl $serviceIdentity->redirect($serviceIdentity->getCancelUrl()); } } if (Yii::app()->user->isGuest) { $model = new UserLogin(); // collect user input data if (isset($_POST['UserLogin'])) { $model->attributes = $_POST['UserLogin']; // validate user input and redirect to previous page if valid if ($model->validate()) { $user = $this->lastViset(); if (Yii::app()->request->isAjaxRequest) { echo json_encode($user->getUserData); exit; } if (Yii::app()->user->returnUrl == '/index.php') { $this->redirect(Yii::app()->controller->module->returnUrl); } else { $this->redirect(Yii::app()->user->returnUrl); } } } // display the login form $this->render('/user/login', array('model' => $model)); } else { $this->redirect(Yii::app()->controller->module->returnUrl); } }
/** * Registration user */ public function actionRegistration() { $model = new RegistrationForm(); if (isset(Yii::app()->eauth)) { //Yii::app()->eauth->popup = true; $services = array_keys(Yii::app()->eauth->services); if (isset(Yii::app()->session['eauth'])) { $services = array_diff($services, array_keys(Yii::app()->session['eauth'])); foreach (Yii::app()->session['eauth'] as $data) { foreach ($data as $property => $value) { if (array_key_exists($property, $model->attributes)) { $model->{$property} = $value; } } } } } $model->id = null; $model->superuser = 0; $model->status = 1; if (!$model->username) { $model->username = $model->nickname; } // ajax validator if (isset($_POST['ajax']) && $_POST['ajax'] === 'registration-form') { echo UActiveForm::validate($model); Yii::app()->end(); } if (Yii::app()->user->id) { $this->redirect(Yii::app()->controller->module->profileUrl); } else { if (isset($_POST['RegistrationForm'])) { $model->attributes = $_POST['RegistrationForm']; if ($model->validate()) { $soucePassword = $model->password; $model->activkey = UserModule::encrypting(microtime() . $model->password); $model->password = UserModule::encrypting($model->password); $model->verifyPassword = UserModule::encrypting($model->verifyPassword); $model->superuser = 0; $model->status = Yii::app()->controller->module->activeAfterRegister ? User::STATUS_ACTIVE : User::STATUS_NOACTIVE; if ($model->save()) { if (Yii::app()->controller->module->sendActivationMail) { $activation_url = $this->createAbsoluteUrl('/user/activation/activation', array("activkey" => $model->activkey, "email" => $model->email)); UserModule::sendMail($model->email, UserModule::t("You registered from {site_name}", array('{site_name}' => Yii::app()->name)), UserModule::t("Please activate you account go to {activation_url}", array('{activation_url}' => $activation_url))); } if (isset(Yii::app()->session['eauth'])) { foreach (Yii::app()->session['eauth'] as $service => $info) { $userOauth = new UserOauth(); $userOauth->service = $service; $userOauth->foreign_id = $info['id']; $userOauth->user_id = $model->id; $userOauth->save(); } } if ((Yii::app()->controller->module->loginNotActiv || Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) && Yii::app()->controller->module->autoLogin) { $identity = new UserIdentity($model->username, $soucePassword); $identity->authenticate(); Yii::app()->user->login($identity, 0); $this->redirect(Yii::app()->controller->module->returnUrl); } else { if (!Yii::app()->controller->module->activeAfterRegister && !Yii::app()->controller->module->sendActivationMail) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Contact Admin to activate your account.")); } elseif (Yii::app()->controller->module->activeAfterRegister && Yii::app()->controller->module->sendActivationMail == false) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please {{login}}.", array('{{login}}' => CHtml::link(UserModule::t('Login'), Yii::app()->controller->module->loginUrl)))); } elseif (Yii::app()->controller->module->loginNotActiv) { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email or login.")); } else { Yii::app()->user->setFlash('registration', UserModule::t("Thank you for your registration. Please check your email.")); } $this->refresh(); } } } } $this->render('/user/registration', array('model' => $model, 'services' => isset($services) ? $services : array())); } }
/** * @throws \Workflow\Exception\PocketException */ public function appAction() { $oauth = UserOauth::find(["user_id = :user_id: and access_token <> ''", 'bind' => ['user_id' => $this->current_user->id]]); $app = []; foreach ($oauth as $item) { $app[$item->app] = 'auth'; } $pushbullet = new Pushbullet(''); $pushbullet->setConfig($this->config); $pock = new Pocket(''); $pock->setConfig($this->config); $request_token = $pock->requestToken(); $this->view->setVar('pushbullet_authorize_uri', $pushbullet->authorizeUrl()); $this->view->setVar('pocket_authorize_uri', $pock->authorizeUrl($request_token)); $this->view->setVar('app', $app); }