Exemple #1
0
 /**
  * @return User
  */
 public function getUser()
 {
     if (empty($this->user) && !empty($this->user_id)) {
         $this->user = User::find($this->user_id);
     }
     return $this->user;
 }
Exemple #2
0
 public function user($id)
 {
     $user = \App\Model\User::find($id);
     $posts = $user->posts()->paginate(25);
     $s = $user->name;
     return view('post/list')->with('posts', $posts)->with('type', ['name' => 'tag', 'title' => "\"{$s}\"发表"]);
 }
Exemple #3
0
 public function send($id, UserMessage $userMessage, User $user)
 {
     $curUserId = $this->current_user->id;
     $userPage = $user->find($id);
     $userMsg = $userMessage->where('user_id', '=', $curUserId)->where('user_send_id', '=', $id)->with('user')->with('userSend')->get();
     return view('pages.messages.send', compact('userPage', 'userMsg'));
 }
Exemple #4
0
 public function index(string $jwt, string $url = '')
 {
     if ($payload = $this->jwtEx->decode($jwt)) {
         if ($user_id = $payload->user_id ?? 0) {
             if ($user = User::find($user_id)) {
                 if (!empty($payload->authorize)) {
                     /** @var User $user */
                     if ($user->verified == 'n') {
                         $user->ip_addr = $this->sniffer->getUserIP();
                         $user->verified = 'y';
                         $user->save();
                     }
                     $this->session->startSession($user_id);
                 }
                 if (!empty($payload->eventName)) {
                     $event = new UserEvent($user_id, $user->toArray());
                     $event->setData($payload->eventData ?? '');
                     $this->dispatcher->fire($payload->eventName, $event);
                 }
             }
         }
     } else {
         $params = ['msg' => 'Sorry this link has expired'];
     }
     return new Redirection($url ?: '/', $params ?? []);
 }
 /**
  * Become a user without having to login.
  */
 public function become($username)
 {
     $user = User::find($username);
     if ($user) {
         $this->user = $user;
         $_SESSION['username'] = $user;
     }
 }
Exemple #6
0
 /**
  * Change user password
  * POST
  *
  * @param Request $request
  * @return Response
  */
 public function changePassword(Request $request)
 {
     $this->validate($request, ['oldPass' => 'required|alpha_num|exists:accounts,pass,guid,' . Auth::user()->guid, 'answer' => 'required|exists:accounts,reponse,guid,' . Auth::user()->guid, 'newPass' => 'required|alpha_num|min:4']);
     $user = UserManager::find(Auth::user()->guid);
     $user->pass = $request->newPass;
     $user->save();
     return redirect()->route('profile');
 }
 public function user_tasks($uid)
 {
     $user = User::find($uid);
     if (empty($user)) {
         abort(404);
     } else {
         var_dump($user->tasks);
     }
 }
 public function show($id = null)
 {
     $user = User::find($id);
     if (!$user->isCurrent()) {
         die;
     }
     $this->viewData['user'] = $user;
     return view('profiles.show', $this->viewData);
 }
Exemple #9
0
 /**
  * Buy points
  * POST
  *
  * @param Request $request
  * @return Response
  */
 public function confirmPaiement(Request $request)
 {
     $this->validate($request, ['code' => 'required|alpha_num']);
     $dedipass = json_decode(file_get_contents('http://api.dedipass.com/v1/pay/?public_key=' . config('config.dedipass.public') . '&private_key=' . config('config.dedipass.private') . '&code=' . $request->code));
     if ($dedipass->status != 'success') {
         return redirect()->back();
     }
     $user = UserManager::find(Auth::user()->guid);
     $user->points += config('config.points.buy');
     $user->save();
     return redirect()->route('home');
 }
Exemple #10
0
 public function update($email, $password)
 {
     if (!empty($email) && !empty($password) && filter_var($email, FILTER_VALIDATE_EMAIL)) {
         if ($user = User::find($this->session->getLoggedInUserId())) {
             $event = new UserUpdateDataEvent($user, ['email' => $email, 'password' => $password]);
             $this->dispatcher->fire(UserUpdateDataEvent::USER_UPDATE_DATA, $event);
             if ($event->isHandled()) {
                 return 'pass';
             }
         }
     }
     throw new UserUpdateDataError("Unable to update credentials");
 }
Exemple #11
0
 /**
  * php artisan queue:listen --queue=TestQue
  */
 public function iron()
 {
     // $ironmq = new IronMQ(array(
     //     'project_id' => env('IRON_PROJECT_ID'),
     //     'token' => env('IRON_TOJEN'),
     //     'host' => env('IRON_HOST')
     // ));
     // $ironmq->ssl_verifypeer = false;
     // $ironmq->postMessage(env('IRON_QUEUE'), "Test Message FROM " . __CLASS__ . ':' . __FUNCTION__);
     $job = with(new SendReminderEmail(User::find(89)))->onQueue(env('IRON_QUEUE'))->delay(15);
     $this->dispatch($job);
     return __CLASS__ . ':' . __FUNCTION__ . ':' . env('IRON_QUEUE');
 }
 public function userData($userData, $userId)
 {
     $user = User::find($userId);
     //Check if user exist
     if (!$user) {
         $user = new User();
     }
     $user->name = $userData['name'];
     $user->email = $userData['email'];
     $user->password = Hash::make($userData['password']);
     $user->save();
     return $user;
 }
Exemple #13
0
 /**
  * Confirm code and give reward
  * POST
  *
  * @param Request $request
  * @param string $key
  * @return Response
  */
 public function confirmCode(Request $request, $key)
 {
     $user = UserManager::find(Auth::user()->guid);
     $code = CodeManager::find($key);
     $code->use -= 1;
     $code->accounts .= $user->guid . '|';
     $code->save();
     switch ($code->action) {
         case 1:
             //Give points
             $user->points += $code->param;
             $user->save();
             break;
         case 2:
             //Give tokens
             $token = \App\Model\TokensAccount::where('guid', $user->guid)->where('token', $code->param)->first();
             if (!$token) {
                 $token = new \App\Model\TokensAccount();
                 $token->guid = $user->guid;
                 $token->token = $code->param;
                 $token->quantity = 1;
             } else {
                 $token->quantity += 1;
             }
             $token->save();
             break;
         case 3:
             //Give item
             $this->validate($request, ['player' => 'required|numeric|exists:personnages,guid']);
             $this->GiveObject($request->player, $code->param);
             break;
         case 4:
             //Give itemsets
             $this->validate($request, ['player' => 'required|numeric|exists:personnages,guid']);
             $itemset = \App\Model\Itemset::find($code->param);
             $exp = explode(',', $itemset->items);
             foreach ($exp as $id) {
                 $this->_giveObject($request->player, $id);
             }
             break;
     }
     if ($code->use == 0) {
         $code->delete();
     }
     return redirect()->route('gift.code');
 }
 public function index($_params)
 {
     if (!empty($_params['password'])) {
         if ($user = User::find($this->session->getLoggedInUserId())) {
             $event = new UserUpdateDataEvent($user, ['password' => $_params['password']]);
             $this->dispatcher->fire(UserUpdateDataEvent::USER_UPDATE_DATA, $event);
             if ($event->isHandled()) {
                 return json_encode(['update' => 'PASSWORD_RESET']);
             } else {
                 throw new UserUpdateDataError($event->getError() ?: 'UNKNOWN_ERROR');
             }
         } else {
             throw new UserUpdateDataError('UNKNOWN_USER');
         }
     } else {
         throw new UserUpdateDataError('INVALID_DATA');
     }
 }
Exemple #15
0
 public function index(int $ar_list_id)
 {
     $user_ids = $this->listManager->getTargetUserIds($ar_list_id);
     $out = fopen('php://output', 'w');
     $this->response->asFile(sprintf('ar_download_list_%d.csv', $ar_list_id), 'text/csv');
     /** @var User $user */
     foreach (User::find($user_ids ?? [0]) as $user) {
         $attrs = $user->attributesToArray();
         unset($attrs['password']);
         unset($attrs['ident']);
         if (empty($header)) {
             $header = true;
             fputcsv($out, array_keys($attrs));
         }
         fputcsv($out, $attrs);
     }
     fclose($out);
 }
Exemple #16
0
 /**
  * Give reward to user
  * POST
  *
  * @param App\Library\Reward $rewardLib
  * @param Request $request
  * @param int $id
  * @param string $name
  * @return Response
  */
 public function giveObject(Reward $rewardLib, Request $request, $id, $name)
 {
     $reward = RewardManager::join('item_template', 'item_template.id', '=', 'item')->where('item', $id)->first();
     $user = UserManager::find(Auth::user()->guid);
     $this->validate($request, ['player' => 'required|numeric|exists:personnages,guid']);
     if ($user->votes < $reward->votes) {
         return redirect()->back();
     } elseif ($rewardLib->checkReward($user->rewards, $reward->item)) {
         return redirect()->back();
     }
     $user->rewards .= $reward->item . '|';
     $user->save();
     $live = new \App\Model\Action();
     $live->PlayerID = $request->player;
     $live->Action = 21;
     $live->Nombre = $reward->item;
     $live->save();
     return redirect()->route('rewards.home');
 }
Exemple #17
0
 public function getCallback()
 {
     $type = $this->request()->segment(3);
     $info = Socialite::driver($type)->user();
     dd($info);
     //已经在本站注册
     if ($bind = UserBind::openId($info->getId())->first()) {
         $user = User::find($bind->user_id);
         //更新accessToken和过期时间
         $bind->update(array('access_token' => $info->token));
         //登录成功,跳转到登录前页面
         Auth::login($user);
         return $this->redirect()->intended('/');
     } else {
         //还没有在本站注册,跳转到账号绑定页面
         $info->from = $type;
         Session::put('social-info', $info);
         return $this->redirect('/socialite/bind');
     }
 }
 public function updateUser(Request $request, $userId)
 {
     $user = User::find($userId);
     if ($request->method() == 'POST') {
         //Get data form post
         $userData = $request->all();
         //Validate data before add
         $validate = $user->isValid($userData, $user);
         if ($validate->fails()) {
             session()->flash('errors', $validate->errors()->all());
             return redirect()->back()->withInput();
         }
         try {
             $this->UserBusiness->userData($userData, $userId);
             return redirect()->back()->with('success', ['You have added new user success']);
         } catch (\ErrorException $e) {
             return redirect()->back()->with('errors', ["You can't add new user now!"]);
         }
     }
     return view('backend/user/update', ['user' => $user]);
 }
Exemple #19
0
 /**
  * Buy token
  * POST
  *
  * @param Request $request
  * @param int $id
  * @param string $name
  * @return Response
  */
 public function buyToken(Request $request, $id, $name)
 {
     $user = UserManager::find(Auth::user()->guid);
     $token = TokensManager::find($id);
     if ($user->points < $token->price) {
         return redirect()->back();
     }
     $user->points -= $token->price;
     $user->save();
     $tokensAccount = TokensAccountManager::where('guid', Auth::user()->guid)->where('token', $token->id)->first();
     if ($tokensAccount) {
         $tokensAccount->quantity += 1;
     } else {
         $tokensAccount = new TokensAccountManager();
         $tokensAccount->guid = Auth::user()->guid;
         $tokensAccount->token = $token->id;
         $tokensAccount->quantity = 1;
     }
     $tokensAccount->save();
     return redirect()->route('gift.tokens');
 }
Exemple #20
0
 /**
  * Buy an object on shop
  * POST
  *
  * @param Request $request
  * @param int $id
  * @param string $name
  * @return Response
  */
 public function buyObject(Request $request, $id, $name)
 {
     $this->validate($request, ['player' => 'required|numeric|exists:personnages,guid', 'cgu' => 'required']);
     $item = ItemManager::find($id);
     $user = \App\Model\User::find(Auth::user()->guid);
     if ($item->stock == 0) {
         return redirect()->back();
     } elseif ($item->price > $user->points) {
         return redirect()->back();
     }
     $user->points -= $item->price;
     $user->save();
     $item->stock -= 1;
     $item->save();
     $action = new \App\Model\Action();
     $action->PlayerID = $request->player;
     $action->Action = 21;
     $action->Nombre = $item->id;
     $action->save();
     return redirect()->route('shop.home');
 }
Exemple #21
0
 /**
  * Returns true if a given desk is empty
  *
  * @return boolean
  */
 protected function checkEmptyDesk(Desk $desk)
 {
     if ($desk->users_id == 0) {
         return true;
     }
     // Return true if the user sitting at the desk has been fired
     if ($desk->users_id > 0 && User::find($desk->users_id)->departmant_id == 21) {
         return true;
     }
     return false;
 }
Exemple #22
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function edit($id)
 {
     //
     return backendView('edit', array('user' => User::find($id)));
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $user = User::find($id);
     $user->delete();
 }
Exemple #24
0
 public function singlePhotoAction(Request $request, Application $app)
 {
     $photo = Photo::where('photo_id', $request->get('id'))->first();
     $user = User::find($photo->user_id);
     return $app['twig']->render('photo.html.twig', $this->getParamsTwig(['photo' => $photo, 'user' => $user]));
 }
Exemple #25
0
 /**
  * Play lotery
  * POST
  *
  * @param Request $request
  * @return Response
  */
 public function playLotery(Request $request)
 {
     $this->validate($request, ['player' => 'required|numeric|exists:personnages,guid']);
     $item = ItemManager::where('lotery', 1)->orderByRaw('RAND()')->first();
     $user = UserManager::find(Auth::user()->guid);
     if ($user->points < config('config.points.lotery')) {
         return redirect()->back();
     }
     $user->points -= config('config.points.lotery');
     $user->save();
     $action = new \App\Model\Action();
     $action->PlayerID = $request->player;
     $action->Action = 21;
     $action->Nombre = $item->id;
     $action->save();
     return view('points.success', compact('item'));
 }
Exemple #26
0
 /**
  * Buy itemset on shop
  * POST
  *
  * @param Request $request
  * @param int $id
  * @param string $name
  * @return Response
  */
 public function buyItemset(Request $request, $id, $name)
 {
     $itemset = ItemsetManager::find($id);
     $user = UserManager::find(Auth::user()->guid);
     $this->validate($request, ['player' => 'required|numeric|exists:personnages,guid']);
     if ($user->points < $itemset->price) {
         return redirect()->back();
     }
     $user->points -= $itemset->price;
     $user->save();
     $objects = explode(',', $itemset->items);
     foreach ($objects as $id) {
         if (!empty($id)) {
             $this->_giveObject($request->player, $id);
         }
     }
     return redirect()->route('shop.itemsets');
 }
 public function profile()
 {
     $user = User::find($this->session->get('user_id'));
     return $user;
 }
Exemple #28
0
 public function getUser()
 {
     $user = User::find($_SESSION['user']);
     return $user;
 }
Exemple #29
0
 public function queueMails(string $now = '')
 {
     MArSummary::unguard();
     MArQueue::unguard();
     $campaigns = MArCampaign::where('enabled', '=', 'true')->where('type', '=', 'autoresponder')->orderBy('priority', 'desc')->get();
     $now_time = !empty($now) ? Carbon::parse($now) : Carbon::now();
     /** @var CollectionEx $pending_ids */
     $yesterday = Carbon::now()->subHours(12);
     $excluded_ids = [];
     foreach (['pass', 'pending'] as $status) {
         //if combined into 1 query or status <> 'fail' then mysql does not use index :/ this way is 100x faster
         $pending_ids = MArQueue::select('user_id')->distinct()->where('send_at', '>', $yesterday)->where('status', '=', $status)->get();
         $excluded_ids = array_unique(array_merge($excluded_ids, $pending_ids->pluck('user_id')->toArray()));
         //exclude ids which got mail less than 12 hours ago (probably from a broadcast)
     }
     foreach ($campaigns as $campaign) {
         /** @var Collection $messages */
         $ar_camp_id = $campaign->ar_campaign_id;
         //$exclusive =
         $messages = MArMessage::where('ar_campaign_id', '=', $ar_camp_id)->orderBy('sequence', 'asc')->get();
         $mail_ids = $messages->pluck('mail_id');
         $target_user_ids = $this->listManager->getTargetUserIds($campaign->ar_list_id);
         if (!empty($target_user_ids) && !empty($excluded_ids)) {
             $target_user_ids = array_diff($target_user_ids, $excluded_ids);
         }
         if (!empty($target_user_ids)) {
             /** @var Collection $completed - get user_ids of all users on the last mail of this Ar */
             $six_hrs = Carbon::parse((string) $now_time)->subHours(6);
             $completed = MArSummary::where('ar_campaign_id', '=', $ar_camp_id)->where('last_mail_id', $mail_ids->last())->where('last_send_date', '<', $six_hrs)->select('user_id')->get();
             if ($completed_user_ids = $completed->pluck('user_id')->all()) {
                 $target_user_ids = array_diff($target_user_ids, $completed_user_ids);
             }
             /** @var Collection $summaries - contains details of last mail sent by user_id */
             $summaries = MArSummary::where('ar_campaign_id', '=', $ar_camp_id)->whereIn('user_id', $target_user_ids)->get();
             foreach ($target_user_ids as $user_id) {
                 $mail_to_send = 0;
                 if ($summary = $summaries->where('user_id', $user_id)->first()) {
                     if (($current_mail_index = array_search($summary->last_mail_id, $mail_ids->all())) !== false) {
                         $message = $messages->get($current_mail_index + 1);
                         $last_sent = Carbon::parse($summary->last_send_date);
                         if ($now_time > $last_sent) {
                             $time_diff = $now_time->diffInHours($last_sent);
                             $wait_hrs = $message->sequence > 0 ? $message->wait_hrs : 0;
                             if ($time_diff > $wait_hrs) {
                                 $mail_to_send = $message->mail_id;
                             }
                         }
                     }
                 } else {
                     $summary = new MArSummary(['user_id' => $user_id, 'ar_campaign_id' => $ar_camp_id]);
                     $mail_to_send = $mail_ids->first();
                 }
                 if ($campaign->priority > 0) {
                     //if the Ar has priority > 0, temporarily bar this user from getting emails from other ars until this Ar is complete
                     $excluded_ids[] = $user_id;
                 }
                 if (!empty($mail_to_send)) {
                     $schedule = json_decode($campaign->schedule_json, true);
                     if (!empty($schedule)) {
                         $user = User::find($user_id);
                         $timezone = !empty($user->tz_offset) ? timezone_name_from_abbr("", $user->tz_offset * -60, 0) : 'America/Chicago';
                         $send_time = $this->getQueueDate($schedule, $timezone);
                     } else {
                         $send_time = $now_time;
                     }
                     try {
                         if (MArQueue::create(['send_at' => $send_time, 'user_id' => $user_id, 'mail_id' => $mail_to_send, 'status' => 'pending'])) {
                             printf("Inserted mail %d into mail queue for user %d to send at: %s\n", $mail_to_send, $user_id, $send_time);
                             $insertions[] = ['mail_id' => $mail_to_send, 'user_id' => $user_id];
                             $summary->last_send_date = $send_time;
                             $summary->last_mail_id = $mail_to_send;
                             $summary->save();
                         }
                     } catch (\Exception $e) {
                         echo '';
                     }
                 }
             }
         }
     }
     return $insertions ?? [];
 }
 /**
 Method to reset the password
 @param void
 @return int
 */
 public function resetPassword()
 {
     $userID = Input::get('id');
     $pass = Input::get('password');
     $userEmail = Input::get('resetemail');
     if (!empty($userID)) {
         $user = new User();
         $user = User::find($userID);
         $user->id = $userID;
         $user->password = Hash::make($pass);
         if ($user->save()) {
             try {
                 Mail::send('emails.resetpassd', ['newpass' => $pass], function ($m) use($userEmail) {
                     $m->to($userEmail)->subject('Express Rental');
                 });
             } catch (Exception $ex) {
             }
             echo 1;
         } else {
             echo 0;
         }
     }
     exit;
 }