예제 #1
0
 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);
 }
 /**
  * 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);
 }
예제 #3
0
 /**
  * Finds user by [[username]]
  *
  * @return Auth|null
  */
 public function getAuth()
 {
     if ($this->_user === false) {
         $this->_user = Auth::findByUsername($this->username);
     }
     return $this->_user;
 }
예제 #4
0
 public function hasLiked()
 {
     if (!\Auth::check()) {
         return false;
     }
     return app('App\\Repositories\\LikeRepository')->hasLiked('comment', $this->id, \Auth::user()->id);
 }
예제 #5
0
 public function scopeSubgudang($query, $req = [])
 {
     $me = \Me::subgudang();
     $user = \Auth::user()->permission;
     $access = $me->access == false && $user > 2 ? 'admin' : 'user';
     $item = $query->join('data_karyawan', 'data_karyawan.id_karyawan', '=', 'data_penyesuaian_stok.id_karyawan')->where('status', 1);
     if ($access == 'admin') {
         $item->whereNotIn('data_penyesuaian_stok.id_gudang', [0]);
     } else {
         $item->where('data_penyesuaian_stok.id_gudang', $me->id_gudang);
     }
     if (count($req) > 0) {
         if (!empty($req['kode'])) {
             $item->where('data_penyesuaian_stok.no_penyesuaian_stok', $req['kode']);
         }
         if (!empty($req['tanggal'])) {
             $item->where('data_penyesuaian_stok.tanggal', $req['tanggal']);
         }
         if (!empty($req['id_gudang'])) {
             $item->where('data_penyesuaian_stok.id_gudang', $req['id_gudang']);
         }
     }
     $akses = \Me::statusGudang();
     if (in_array($akses, [1, 2])) {
         $item->where('tipe', $akses);
     }
     $item->orderby('data_penyesuaian_stok.id_penyesuaian_stok', 'desc')->select('data_penyesuaian_stok.*', 'data_karyawan.nm_depan', 'data_karyawan.nm_belakang');
 }
예제 #6
0
 /**
  * Gets the SSH session using the auth given
  *
  * @param \App\Models\Auth $auth Auth model
  * @param \Ssh\Configuration $configuration SSH configuration object
  */
 protected function getSSHSession($auth, $host)
 {
     $session = new SSH2($host);
     if ($auth->isKeyAuthentication()) {
         $key = new RSA();
         $key->loadKey($auth->credentials->key);
         if (!$session->login($auth->credentials->username, $key)) {
             \log::error('Login Failed');
         }
     } else {
         if (!$session->login($auth->credentials->username, $auth->credentials->password)) {
             \log::error('Login Failed');
         }
     }
     return $session;
 }
예제 #7
0
 /**
  * gets the user id of the current user
  * @return mixed
  */
 public static function userId()
 {
     if (Auth::check()) {
         return Auth::user()->user_id;
     } else {
         return 0;
     }
 }
 /**
  * @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();
         }
     }
 }
예제 #9
0
파일: User.php 프로젝트: gertjanroke/users
 /**
  * Check if a logged in user has a specific rol or one of the given roles
  * 
  * @param  array $roles
  * @return boolean
  */
 public static function hasRoles(array $roles)
 {
     $user = \Auth::user();
     foreach ($roles as $role) {
         if (in_array($role, $user->roles()->lists('name')->toArray())) {
             return true;
         }
     }
     return false;
 }
예제 #10
0
 public static function isSuperAdmin()
 {
     if (\Auth::check()) {
         if (\Auth::user()->role_id == 1) {
             return true;
         }
         return false;
     }
     return false;
 }
예제 #11
0
 public function accountIsActive($code)
 {
     $user = User::where('activation_code', '=', $code)->first();
     $user->active = 1;
     $user->activation_code = '';
     if ($user->save()) {
         \Auth::login($user);
     }
     return true;
 }
예제 #12
0
 public function isOwner()
 {
     if (!\Auth::check()) {
         return false;
     }
     if (\Auth::user()->id == $this->user_id) {
         return true;
     }
     return false;
 }
 /**
  * Регистрирует посещение
  * @param $target_id
  * @param $target_type
  */
 public static function enrol($target_id, $target_type)
 {
     $user_id = 0;
     $user_model = \Auth::user();
     if ($user_model) {
         $user_id = $user_model->id;
     }
     $request = \Request::instance();
     self::create(['user_id' => $user_id, 'user_ip' => $request->getClientIp(), 'target_id' => $target_id, 'target_type' => $target_type]);
 }
예제 #14
0
 public function create($request)
 {
     $validator = $this->validate($request);
     if (!$validator->fails()) {
         Managers::create(['name' => $request['name'], 'email' => $request['email'], 'password' => Hash::make($request['password'])]);
         Auth::sendNewManagerEmail($request['email']);
         return redirect()->away('http://' . config('global.origin.current') . $request['redirectonsuccess'] . '?message=Registro realizado com sucesso! Verifique seu email.');
     } else {
         return redirect()->away('http://' . config('global.origin.current') . $request['redirectonerror'] . '?message=' . $validator->errors()->first());
     }
 }
예제 #15
0
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     LaminatingGsmCheck::creating(function ($laminatingGsmCheck) {
         $laminatingGsmCheck->created_by = \Auth::user()->id;
         $laminatingGsmCheck->updated_by = \Auth::user()->id;
     });
     LaminatingGsmCheck::updating(function ($laminatingGsmCheck) {
         $laminatingGsmCheck->updated_by = \Auth::user()->id;
     });
 }
예제 #16
0
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     PrintStation::creating(function ($printStation) {
         $printStation->tds_ink_link_added_user_fk = \Auth::user()->id;
         $printStation->tds_ink_link_mod_user_fk = \Auth::user()->id;
     });
     PrintStation::updating(function ($printStation) {
         $printStation->tds_ink_link_mod_user_fk = \Auth::user()->id;
     });
 }
예제 #17
0
파일: Ink.php 프로젝트: buys-fran/mtech-mis
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     Ink::creating(function ($ink) {
         $ink->ink_added_user_id_fk = \Auth::user()->id;
         $ink->ink_modified_user_id_fk = \Auth::user()->id;
     });
     Material::updating(function ($ink) {
         $ink->ink_modified_user_id_fk = \Auth::user()->id;
     });
 }
예제 #18
0
파일: Content.php 프로젝트: niefufeng/drip
 protected static function boot()
 {
     static::creating(function (Content $model) {
         $model->user_id = \Auth::user()->id;
         $model->introduction === '' && ($model->introduction = str_limit($model->text_html, 200));
     });
     static::saving(function (Content $model) {
         $model->text_html = \Parsedown::instance()->parse($model->text);
     });
     parent::boot();
 }
예제 #19
0
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     JobCard::creating(function ($jobCard) {
         $jobCard->job_cards_added_user_id_fk = \Auth::user()->id;
         $jobCard->job_cards_modified_user_id_fk = \Auth::user()->id;
     });
     JobCard::updating(function ($jobCard) {
         $jobCard->job_cards_modified_user_id_fk = \Auth::user()->id;
     });
 }
예제 #20
0
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     LaminatingLogSheet::creating(function ($laminatingLogSheet) {
         $laminatingLogSheet->created_by = \Auth::user()->id;
         $laminatingLogSheet->updated_by = \Auth::user()->id;
     });
     LaminatingLogSheet::updating(function ($laminatingLogSheet) {
         $laminatingLogSheet->updated_by = \Auth::user()->id;
     });
 }
예제 #21
0
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     MaterialInventoryItem::creating(function ($materialCostLog) {
         $materialCostLog->mat_inventory_added_user_id_fk = \Auth::user()->id;
         $materialCostLog->mat_inventory_modified_user_id_fk = \Auth::user()->id;
     });
     MaterialInventoryItem::updating(function ($materialCostLog) {
         $materialCostLog->mat_inventory_modified_user_id_fk = \Auth::user()->id;
     });
 }
예제 #22
0
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     AdhesiveCostLog::creating(function ($adhesiveCostLog) {
         $adhesiveCostLog->adhesive_cost_added_user_id_fk = \Auth::user()->id;
         $adhesiveCostLog->adhesive_cost_modified_user_id_fk = \Auth::user()->id;
     });
     AdhesiveCostLog::updating(function ($adhesiveCostLog) {
         $adhesiveCostLog->adhesive_cost_modified_user_id_fk = \Auth::user()->id;
     });
 }
예제 #23
0
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     Material::creating(function ($material) {
         $material->material_added_user_id_fk = \Auth::user()->id;
         $material->material_modified_user_id_fk = \Auth::user()->id;
     });
     Material::updating(function ($material) {
         $material->material_modified_user_id_fk = \Auth::user()->id;
     });
 }
예제 #24
0
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     EfficiencyIssue::creating(function ($efficiencyIssue) {
         $efficiencyIssue->created_by = \Auth::user()->id;
         $efficiencyIssue->updated_by = \Auth::user()->id;
     });
     EfficiencyIssue::updating(function ($efficiencyIssue) {
         $efficiencyIssue->updated_by = \Auth::user()->id;
     });
 }
예제 #25
0
 public static function generate()
 {
     if (!\Auth::check()) {
         return NULL;
     }
     $apiKey = new ApiKey();
     $apiKey->user_id = \Auth::user()->id;
     $apiKey->api_key = \App\Helpers\Text::randomCryptoString();
     $apiKey->save();
     return $apiKey;
 }
예제 #26
0
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     EfficiencyReportLog::creating(function ($efficiencyReportLog) {
         $efficiencyReportLog->created_by = \Auth::user()->id;
         $efficiencyReportLog->updated_by = \Auth::user()->id;
     });
     EfficiencyReportLog::updating(function ($efficiencyReportLog) {
         $efficiencyReportLog->updated_by = \Auth::user()->id;
     });
 }
예제 #27
0
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     WasteCode::creating(function ($wasteCode) {
         $wasteCode->created_by = \Auth::user()->id;
         $wasteCode->updated_by = \Auth::user()->id;
     });
     WasteCode::updating(function ($wasteCode) {
         $wasteCode->updated_by = \Auth::user()->id;
     });
 }
예제 #28
0
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     JobCosting::creating(function ($jobCosting) {
         $jobCosting->jc_user_added_id_fk = \Auth::user()->id;
         $jobCosting->jc_user_modified_id_fk = \Auth::user()->id;
     });
     JobCosting::updating(function ($jobCosting) {
         $jobCosting->jc_user_modified_id_fk = \Auth::user()->id;
     });
 }
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     ConsumablesMinimumLevel::creating(function ($consumablesMinimumLevel) {
         $consumablesMinimumLevel->created_by = \Auth::user()->id;
         $consumablesMinimumLevel->updated_by = \Auth::user()->id;
     });
     ConsumablesMinimumLevel::updating(function ($consumablesMinimumLevel) {
         $consumablesMinimumLevel->updated_by = \Auth::user()->id;
     });
 }
예제 #30
0
 /**
  * Overwrite the parent boot method
  *
  * @return void
  */
 public static function boot()
 {
     parent::boot();
     LogisticsCostLog::creating(function ($logisticsCostLog) {
         $logisticsCostLog->logistic_cost_log_added_user_id_fk = \Auth::user()->id;
         $logisticsCostLog->logistic_cost_log_modified_user_id_fk = \Auth::user()->id;
     });
     LogisticsCostLog::updating(function ($logisticsCostLog) {
         $logisticsCostLog->logistic_cost_log_modified_user_id_fk = \Auth::user()->id;
     });
 }