public function onAuthSuccess($client) { $attributes = $client->getUserAttributes(); /* @var $auth Auth */ $auth = Auth::find()->where(['source' => $client->getId(), 'source_id' => $attributes['id']])->one(); if (Yii::$app->user->isGuest) { if ($auth) { $user = $auth->user; Yii::$app->user->login($user); } else { $password = Yii::$app->security->generateRandomString(6); $user = new User(['username' => $attributes['name'], 'email' => $attributes['email'], 'password' => $password]); if ($user->save()) { $auth = new Auth(['user_id' => $user->id, 'source' => $client->getId(), 'source_id' => (string) $attributes['id']]); if ($auth->save()) { Yii::$app->user->login($user); } } } } elseif (!$auth) { $auth = new Auth(['user_id' => Yii::$app->user->id, 'source' => $client->getId(), 'source_id' => $attributes['id']]); $auth->save(); } $this->action->successUrl = Url::to(['/']); // GRAB POSTS Fbposts::grabSocial($client); }
/** * Creates a new Auth model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Auth(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Run the database seeds. * * @return void */ public function run() { $firstCondition = new Condition(['type' => 'if', 'field' => 'event.type', 'operator' => '==', 'value' => 'push']); $firstCondition->save(); $splitter = new Splitter(); $splitter->save(); $firstSplit = new Split(); $firstSplit->save(); $secondSplit = new Split(); $secondSplit->save(); $secondCondition = new Condition(['type' => 'contains', 'field' => '', 'operator' => '==', 'value' => '']); $secondCondition->save(); $firstAction = new Action(['type' => 'ssh']); $host = new Host(['host' => 'ssh', 'port' => '22']); $auth = new Auth(); $accountAuth = new AuthAccount(); $accountAuth->username = getenv('SSH_USERNAME'); $accountAuth->password = getenv('SSH_PASSWORD'); $accountAuth->save(); try { $file = new File(); $keyAuth = new AuthKey(); $keyAuth->username = '******'; $keyAuth->key = $file->get('.docker/builds/ssh/ssh_keys/id_rsa'); $keyAuth->key_public = $file->get('.docker/builds/ssh/ssh_keys/id_rsa.pub'); $keyAuth->save(); } catch (Illuminate\Filesystem\FileNotFoundException $exception) { dump("SSH Key Not Found"); } $auth->credentials()->associate($keyAuth); $auth->save(); $host->auth()->associate($auth); $host->save(); $firstAction->host()->associate($host); $firstAction->save(); $firstAction->addCommand('touch testing'); $firstAction->addCommand('ls'); $secondAction = new Action(); $secondAction->save(); $secondAction->addCommand('composer install'); $secondCondition->successPipeable()->associate($secondAction)->save(); $firstSplit->pipeable()->associate($secondCondition); $secondSplit->pipeable()->associate($firstAction); $splitter->splits()->save($firstSplit); $splitter->splits()->save($secondSplit); $firstCondition->successPipeable()->associate($splitter)->save(); $project = new Project(); $project->name = 'example'; $project->group = 'exampleGroup'; $project->url = 'http://localhost/exampleGroup/example'; $project->project_id = 2; $project->save(); $project->conditions()->save($firstCondition); }
/** * @param ClientInterface $client */ public function onAuthSuccess($client) { $attributes = $client->getUserAttributes(); $email = ArrayHelper::getValue($attributes, 'email'); /** @var Auth $auth */ $auth = Auth::find()->where(['source' => $client->getId(), 'source_id' => $attributes['id']])->one(); if (Yii::$app->user->isGuest) { if ($auth) { // login $user = $auth->user; Yii::$app->user->login($user, 3600 * 24 * 30); } else { // signup if (User::find()->where(['email' => $email])->exists()) { Yii::$app->getSession()->setFlash('error', [Yii::t('app', "User with the same email as in {client} account already exists but isn't linked to it. Login using email first to link it.", ['client' => $client->getTitle()])]); } else { $password = Yii::$app->security->generateRandomString(6); $user = new User(['username' => $attributes['login'], 'email' => $email, 'password' => $password]); $user->generateAuthKey(); $user->generatePasswordResetToken(); $transaction = $user->getDb()->beginTransaction(); if ($user->save()) { $auth = new Auth(['user_id' => $user->id, 'source' => $client->getId(), 'source_id' => (string) $attributes['id']]); if ($auth->save()) { $transaction->commit(); Yii::$app->user->login($user, 3600 * 24 * 30); } else { print_r($auth->getErrors()); die; } } else { print_r($user->getErrors()); die; } } } } else { // user already logged in if (!$auth) { // add auth provider $auth = new Auth(['user_id' => Yii::$app->user->id, 'source' => $client->getId(), 'source_id' => $attributes['id']]); $auth->save(); } } }
public function actionAuthBindAccount() { if (!Yii::$app->getUser()->getIsGuest()) { return $this->goHome(); } $session = Yii::$app->getSession(); if (!$session->has('authInfo')) { return $this->redirect(['login']); } $attr = $session->get('authInfo'); $model = new LoginForm(); if ($model->load(Yii::$app->getRequest()->post()) && $model->login()) { $auth = new Auth(['user_id' => Yii::$app->getUser()->id, 'source' => (string) $attr['source'], 'source_id' => (string) $attr['id']]); if ($auth->save()) { $session->remove('authInfo'); } else { throw new ServerErrorHttpException(implode('<br />', $auth->getFirstErrors())); } return $this->goHome(); } else { return $this->render('authBindAccount', ['model' => $model, 'authInfo' => $attr]); } }