/** * @inheritdoc */ public function decode($jwt) { $payload = JWT::decode($jwt, $this->getSigningKey(), [self::SIGNING_ALGORITHM]); $userId = isset($payload->{self::CLAIM_USER_ID}) === true ? $payload->{self::CLAIM_USER_ID} : null; $user = $userId !== null ? User::find($userId) : null; return $user; }
public function testHandle() { $user = User::find(1); $message = '[l giraffes l] hey there boys [l big penis l] what do you feel like doing [l tonight l] [p penis p]'; $ret = $this->dispatch(new ParseMessage($user, $message)); $this->assertTrue($ret); }
private static function addMentions($from) { if (!($targetNames = self::findMentions($from['text']))) { return false; } unset($from['text']); if (!($targets = User::find()->select('id')->where(['in', 'username', $targetNames])->asArray()->all())) { return false; } $topicAuthorNoticed = false; $topicAuthor = false; if (!empty($from['topic_author'])) { $topicAuthor = $from['topic_author']; unset($from['topic_author']); } foreach ($targets as $target) { if ($target['id'] == $from['source_id']) { continue; } if (!$topicAuthorNoticed && $topicAuthor && $target['id'] == $topicAuthor) { $topicAuthorNoticed = true; } $notice = new Notice($from); $notice->target_id = $target['id']; $notice->save(false); } return $topicAuthorNoticed; }
public function getUser() { if ($this->_user == false) { $this->_user = User::find()->where(['telephone' => $this->telephone])->one(); } return $this->_user; }
public function handle(UserDetailsQuery $query) { if (!is_null($query->username)) { return User::where('username', '=', $query->username)->first(); } return User::find($query->userId); }
public function postDeleteFriend($id) { $newUnFriendUser = User::find($id); $this->user->unfriend($newUnFriendUser); Flash::warning('You unfriended ' . $newUnFriendUser->name); return redirect('/'); }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::find()->where("username = :username ", [":username" => $this->username])->one(); } return $this->_user; }
public function actionAvatar() { $model = User::getUserInfo(Yii::$app->user->id); $this->layout = 'left_user_setting'; if (Yii::$app->request->isPost) { $postAvatar = Yii::$app->request->post(); $crop = new CropAvatar($postAvatar['avatar_src'], $postAvatar['avatar_data'], $_FILES['avatar_file']); $result = explode('.', $crop->getResult()); $resultShow = '/' . $result['0'] . '_big.' . $result['1']; /*添加/进行输出*/ $response = array('state' => 200, 'message' => $crop->getMsg(), 'result' => $resultShow); $model->file = $result['0'] . '.' . $result['1']; $model->save(); echo json_encode($response); exit; } $userImage = explode('.', Yii::$app->user->getIdentity()->file); $userMiddleImage = $userImage['0'] . '_middle.' . $userImage['1']; $userBigImage = $userImage['0'] . '_big.' . $userImage['1']; return $this->render('avatarCropper', ['model' => $model, 'userMiddleImage' => $userMiddleImage, 'userBigImage' => $userBigImage]); $model = new CropAvatar(); if (Yii::$app->request->isPost) { var_dump($_POST); exit; //$model->file = UploadedFile::getInstance($model, 'file'); } $model = User::find()->one(); if (empty($model)) { return $this->render('error', ['id' => Yii::$app->user->id]); } $this->layout = 'left_user_setting'; return $this->render('avatar', ['model' => $model]); }
public function postPartisipan($kelasId) { $response = []; $kelas = Kelas::find($kelasId); $gel = Gelombang::getActive(); $response['errors'] = []; $response['kelas'] = $kelas; $response['gelombang'] = $gel; $response['validations'] = []; $response['fields'] = []; $response['actionLabel'] = 'Tambah'; $response['output'] = view('backend.partials.master.kelas.partisipan', $response)->render(); $input = $this->parseInput(request()->all()); $input = $this->normaliseData($input); if (isset($input['_token'])) { $response['status'] = true; if (isset($input['partisipan'])) { foreach ($input['partisipan'] as $id => $useless) { if (!$kelas->siswa->contains($id)) { $kelas->siswa()->attach(User::find($id)); } } } } return $response; }
public function run() { DB::table('roles')->truncate(); DB::table('role_user')->truncate(); DB::table('permissions')->truncate(); DB::table('permission_role')->truncate(); $admin_role = new Role(); $admin_role->name = 'admin'; $admin_role->display_name = 'Administrator'; $admin_role->description = 'manages everything'; $admin_role->save(); $reviewer_role = new Role(); $reviewer_role->name = 'reviewer'; $reviewer_role->display_name = 'Reviewer'; $reviewer_role->description = 'reviews inserted data'; $reviewer_role->save(); $inserter_role = new Role(); $inserter_role->name = 'inserter'; $inserter_role->display_name = 'Inserter'; $inserter_role->description = 'inserts data about billboards'; $inserter_role->save(); $admin = User::find(1); $reviewer = User::find(2); $inserters = User::whereNotIn('id', [$admin->id, $reviewer->id])->get(); $admin->attachRole($admin_role); $reviewer->attachRole($reviewer_role); foreach ($inserters as $user) { $user->attachRole($inserter_role); } }
public function getChat($partner_id) { $user = Auth::user(); $messages = $user->chat($partner_id); $partner = User::find($partner_id); return view('messages.chat')->with('messages', $messages)->with('user', $user)->with('partner', $partner); }
public function user($id) { $user = User::find($id); $prediction = new Prediction(); $data = ["user" => $user, "predictions" => $prediction->make($user), "ratedMovies" => $prediction->getRatedmovies()]; return view('user', $data); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(\App\Http\Requests\UpdateUserRequest $request, $id) { $user = \App\Models\User::find($id); $user->fill($request->all()); $user->save(); return redirect("users/" . $user->id); }
/** * Create a new event instance. * * @return void */ public function __construct($user_id, $game_id) { $user = \App\Models\User::find($user_id); $game_user = \App\Models\Game_User::where('user_id', $user_id)->where('game_id', $game_id)->first(); $game_user['has_left'] = true; $game_user->save(); $game_users = \App\Models\Game_User::where('game_id', $game_id)->get(); $cont = 0; foreach ($game_users as $game_user) { if ($game_user['has_left']) { $cont++; } } $user_list = \App\Models\Game_User::where('game_id', $game_id)->get(); $msg = 'El jugador ' . $user->first_name . ' se ha rendido'; if ($cont == count($user_list) - 1) { $winner = \App\Models\Game_User::where('has_left', '=', false)->where('game_id', $game_id)->first(); $winner['has_won'] = true; $winner->save(); $winner_name = \App\Models\User::find($winner['user_id']); $msg .= ', y El jugador ' . $winner_name->first_name . ' ha ganado'; } $games = \App\Models\Game_User::where('game_id', $game_id)->where('user_id', $user_id)->first(); if (!$games['has_left']) { $letters_user = \App\Models\Letter_User::where('game_id', '=', $game_id)->where('user_id', $user_id)->get(['letter_id']); foreach ($letters_user as $key) { $user_letters_save = \App\Models\Inventory_Letter_Game::where('game_id', $game_id)->where('letter_id', $key->letter_id)->first(); $user_letters_save->quantity++; $user_letters_save->save(); } } $this->data = ['game_id' => $game_id, 'msg' => $msg]; }
/** * Send an email to the user to request his confirmation for being a member of the team * * @return \Illuminate\Http\Response */ public function sendrequest($plan_id, $id, AppMailer $mailer) { // check access rights if (!Auth::user()->ownsPlan($plan_id)) { return redirect('home')->with('error', 'You are unauthorized for this request.'); } // get the resource handle $team = Team::find($id); if ($team) { if ($team->requested) { $error = 'Request Email was already sent to this user!'; return \Redirect::back()->with(['error' => $error]); } $team->requested = True; $team->remember_token = str_random(32); // send internal message to user $message = 'Please open <a href="' . url('cspot/plans/' . $plan_id) . '/team"> this plan </a> and confirm if you accept the given role.'; $thread_id = sendInternalMessage('You have been assigned a role in a Service plan', $message, $team->user_id, false); $team->thread_id = $thread_id; $team->save(); // also send an email to the user $recipient = User::find($team->user_id); $plan = Plan::find($team->plan_id); $mailer->getPlanMemberConfirmation($recipient, $plan, $team); $status = 'Email with membership request was sent to user.'; return \Redirect::route('team.index', ['plan_id' => $plan_id])->with(['status' => $status]); } $error = 'Wrong team member id!'; return \Redirect::back()->with(['error' => $error]); }
/** * Custom setter * Calculate tithe amount based on pool_amount times the user's tithe percentage */ public function setAmount() { $pool_amount = $this->attributes['pool_amount']; $user_id = $this->attributes['user_id']; $tithePercentage = User::find($user_id)->userProperties()->where('key', UserProperty::KEY_TITHE_PERCENTAGE)->first(); $this->attributes['amount'] = $pool_amount * ((double) $tithePercentage->value / 100); }
public function username_existe($attribute, $params) { $table = User::find()->where("username=:username", [":username" => $this->username]); if ($table->count() == 1) { $this->addError($attribute, "El usuario selecbionado existe"); } }
public function postForm(FormAdminRequest $request) { try { $dataAdmin = $request->all(); $password = $request->get('password', null); if (isset($dataAdmin['id']) && $dataAdmin['id'] != '') { $data = $request->except(array('password')); $runtime = User::find($dataAdmin['id']); $runtime->fill($data); $runtime->password = $runtime->password; if (!empty($password)) { $runtime->password = Hash::make($password); } $runtime->save(); $msg = 'Usuario Editado!'; } else { $role = Role::whereName(User::ROL_CONTENIDO_ADMIN)->first(); $dataAdmin['password'] = Hash::make($password); $NewUser = User::create($dataAdmin); $msg = 'Usuario Guardado!'; RoleUser::create(['user_id' => $NewUser->id, 'role_id' => $role->id]); } return redirect(action('Admin\\AdminController@getIndex'))->with('messageSuccess', $msg); } catch (Exception $exc) { dd($exc->getMessage()); } }
/** * Обновляет список команд у всех пользователей */ public function actionUpdateAll() { $users = User::find()->where(['!=', 'profile_url', ''])->all(); foreach ($users as $user) { $user->updateTeams(); } }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::find()->active()->andWhere(['username' => $this->username])->one(); } return $this->_user; }
/** * Contains the testing sample data for the LotController. * * @return void */ private function setVariables() { //Setting the current user $this->be(User::find(1)); $this->input = array('lot_no' => '2015', 'description' => 'kenya yao', 'expiry' => '12-12-2015'); $this->inputUpdate = array('lot_no' => '2015', 'description' => 'Kenya yetu', 'expiry' => '12-05-2020'); }
public function postTraffic($request, $response, $args) { $nodeId = $args['id']; $node = Node::find($nodeId); $rate = $node->traffic_rate; $input = $request->getBody(); $datas = json_decode($input, true); foreach ($datas as $data) { $user = User::find($data['user_id']); $user->t = time(); $user->u = $user->u + $data['u'] * $rate; $user->d = $user->d + $data['d'] * $rate; $user->save(); // log $totalTraffic = Tools::flowAutoShow(($data['u'] + $data['d']) * $rate); $traffic = new TrafficLog(); $traffic->user_id = $data['user_id']; $traffic->u = $data['u']; $traffic->d = $data['d']; $traffic->node_id = $nodeId; $traffic->rate = $rate; $traffic->traffic = $totalTraffic; $traffic->log_time = time(); $traffic->save(); } $res = ["ret" => 1, "msg" => "ok"]; return $this->echoJson($response, $res); }
public function setTheme() { $user = User::find(Auth::user()->id); $user->theme_id = Input::get('theme_id'); $user->save(); return Redirect::to(Input::get('path')); }
protected function findUser($username) { if (($model = User::find(['Username' => $username])->one()) != null) { return $model; } return $this->notFound('Page not found.'); }
/** * This method is called after each cest class test method, even if test failed. * @param \Codeception\Event\TestEvent $event */ public function _after($event) { $user = User::find()->where(['ip' => 'noip'])->one(); $authManager = \Yii::$app->getAuthManager(); $userRole = $authManager->getRole('admin'); $authManager->revoke($userRole, $user->id); }
/** * Finds user by [[username]] * * @return User|null */ public function getUser() { if ($this->_user === false) { $this->_user = User::find($this->username, $this->password); } return $this->_user; }
public function aanmelden_bolker() { $meal = Meal::find((int) Request::input('meal_id')); if (!$meal) { return response()->json(['error' => 'meal_not_found', 'error_details' => 'Maaltijd bestaat niet'], 404); } $user = User::find(Request::input('user_id')); if (!$user) { return response()->json(['error' => 'user_not_found', 'error_details' => 'Gebruiker bestaat niet'], 404); } if ($user->blocked) { return response()->json(['error' => 'user_blocked', 'error_details' => 'Deze gebruiker is geblokkeerd. Je kunt hem/haar niet aanmelden'], 403); } // Create a new registration $registration = new Registration(['name' => $user->name, 'handicap' => $user->handicap]); $registration->confirmed = true; $registration->username = $user->username; $registration->email = $user->email; $registration->meal_id = $meal->id; $registration->user_id = $user->id; if ($registration->save()) { Log::info("Aangemeld: administratie|{$registration->id}|{$registration->name}"); return view('meal/_registration', ['registration' => $registration]); } else { return response()->json(['error' => 'create_registration_admin_unknown_error', 'error_details' => 'Deze registratie kon niet opgeslagen worden, reden onbekend.'], 500); } }
public function testChangeUserName() { $user = User::find()->where(['username' => 'neo'])->one(); $user->username = "******"; $user->save(); expect($user->username)->equals('neozzz'); }
public function getAuthState() { $state = new JobAuthState(); $state->authMechanism = self::AUTH_MECHANISM; if (!Input::has('access_token')) { return $state; } $ownerId = $this->authServer->getResourceOwnerId(); $type = $this->authServer->getResourceOwnerType(); if ($type == 'user') { //oAuth token belongs to a user $user = User::find($ownerId); $actAs = $user->id; if (Input::has('act_as')) { if ($user->hasRole(UserRole::ACTOR_ROLE)) { $actAs = Input::get('act_as'); } else { $bag = new MessageBag(); $bag->add('authorisation', 'The current user cannot act as another user'); throw new AuthorisationException($bag); } } $state->userId = $user->id; $state->rememberMe = false; $state->actingUserId = $actAs; } else { //oAuth token belongs to a client //$client = OAuthClient::find($ownerId); //There is no user context and act_as shouldn't be needed as clients can use //access tokens if they want to execute as a user } return $state; }
public function sendNotification($userID) { $user = User::find($userID); //in $data ci saranno i dati da passare al client $data = array(); Notifier::send($user, "VIP request", "You have been selected to be a VIP", $data); }