Exemplo n.º 1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $access_token = generate_access_token();
     $email = 'a1t1-' . generate_email() . '@telegramlogin.com';
     $user = new User();
     $user->name = 'david pichsenmeister';
     $user->username = '******';
     $user->email = $email;
     $user->telegram_id = 41478911;
     $user->access_token = $access_token;
     $user->save();
     $app = new App();
     $app->user_id = $user->id;
     $app->name = 'Telegram Login';
     $app->client_id = 314159265;
     $app->client_secret = generate_client_secret();
     $app->website = env('URL');
     $app->redirect_url = env('URL') . '/login';
     $app->save();
     $tg = new TelegramUser();
     $tg->telegram_id = 41478911;
     $tg->name = 'david pichsenmeister';
     $tg->username = '******';
     $tg->save();
     $auth = new Auth();
     $auth->app_id = $app->id;
     $auth->telegram_user_id = $tg->id;
     $auth->email = $email;
     $auth->access_token = $access_token;
     $auth->save();
 }
 private function post($endpoint, array $data)
 {
     $client = new Client();
     $response = $client->post($this->getUrl($endpoint), ['auth' => $this->auth->getBasicHeaderArray(), 'headers' => ['Accept' => 'application/vnd.github.v3+json'], 'json' => $data]);
     $this->rateLimitRemaining = (int) $response->getHeaderLine('X-RateLimit-Remaining');
     return json_decode($response->getBody()->getContents(), true);
 }
Exemplo n.º 3
0
 public static function uploadBeerImg_callback($request, $fileimage)
 {
     $image_unique_id = date('Ymdhis') . rand(0, 9999);
     $beer_meta = new BeerImg();
     $beer_meta->beer_id = $request['beer_id'];
     $beer_meta->description = !empty($request['img_description']) ? $request['img_description'] : null;
     $beer_name = !empty($request['img_description']) ? $request['img_description'] : null;
     $imageName = "beerhit.com_" . strtolower($beer_name) . $request['beer_id'] . $image_unique_id . '.' . $fileimage->getClientOriginalExtension();
     $path = public_path('/images/catalog/' . $imageName);
     $img = ImageManagerStatic::make($fileimage);
     // resize the image to a width of 960
     // and constrain aspect ratio (auto width)
     $img->resize(960, null, function ($constraint) {
         $constraint->aspectRatio();
         $constraint->upsize();
     });
     $img->save($path);
     //Save image information to database
     $beer_meta->img_id = $image_unique_id;
     $beer_meta->filename = $imageName;
     $beer_meta->path = '/images/catalog/' . $imageName;
     $beer_meta->user_id = \Auth::user()->id;
     $beer_meta->place_id = $request['fb_place_id'];
     $beer_meta->save();
     \UserBeerHelper::userLog(\Auth::user()->id, $request['beer_id'], 200, $request['fb_place_id'], $image_unique_id);
 }
Exemplo n.º 4
0
 public function getNotReadMessagesById($id)
 {
     $count = $this->where('id_receive', \Auth::user()->id)->where('read', NULL)->where('dialog_id', $id)->count();
     if ($count) {
         return '(' . $count . ')';
     }
 }
Exemplo n.º 5
0
 public static function totalMonthlyCoverage()
 {
     $visitClass = Customer::select('class')->where('mr_id', \Auth::user()->id)->get()->toArray();
     $totalVisitsCount = VisitClass::whereIn('name', $visitClass)->sum('visits_count');
     $actualVisitsCount = Report::where('mr_id', \Auth::user()->id)->where('month', date('M') . '-' . date('Y'))->count();
     return number_format($actualVisitsCount / $totalVisitsCount * 100, 2);
 }
Exemplo n.º 6
0
 public function scopeClient($query, $request)
 {
     //$query->join('projects','claim.project_id','=','projects.id');
     if (!empty($request['created_at_from']) && !empty($request['created_at_to'])) {
         $dtFrom = new \DateTime($request['created_at_from']);
         $dtTo = new \DateTime($request['created_at_to']);
         $query->whereBetween('claims.created_at', [$dtFrom->format('Y-m-d 00:00:00'), $dtTo->format('Y-m-d 23:59:59')]);
     } elseif (!empty($request['created_at_from']) && empty($request['created_at_to'])) {
         $dtFrom = new \DateTime($request['created_at_from']);
         $dtTo = new \DateTime();
         $query->whereBetween('claims.created_at', [$dtFrom->format('Y-m-d 00:00:00'), $dtTo->format('Y-m-d 23:59:59')]);
     } elseif (empty($request['created_at_from']) && !empty($request['created_at_to'])) {
         $dtFrom = new \DateTime($request['created_at_to']);
         $dtTo = new \DateTime('created_at_to');
         $query->whereBetween('claims.created_at', [$dtFrom->format('Y-m-d 00:00:00'), $dtTo->format('Y-m-d 23:59:59')]);
     }
     if (!empty($request['status'])) {
         $query->where('claims.status', $request['status']);
     }
     if (!empty($request['id'])) {
         $query->where('claims.id', (int) $request['id']);
     }
     if (!empty($request['name'])) {
         $query->where('claims.name', 'like', "%" . $request['name'] . "%");
     }
     if (!empty($request['phone'])) {
         $query->where('claims.phone', 'like', "%" . $request['phone'] . "%");
     }
     $query->join('projects', function ($join) {
         $join->on('claims.project_id', '=', 'projects.id')->where('projects.client_id', '=', \Auth::user()->id);
     });
     $query->orderBy('claims.id', 'desc')->get(["claims.*"]);
 }
Exemplo n.º 7
0
 public function post()
 {
     $file = array('users' => Request::all());
     // setting up rules
     $rules = array('users' => 'required', 'mimes' => 'jpeg,jpg,png', 'max' => '200px');
     //mimes:jpeg,bmp,png and for max size max:10000
     // doing the validation, passing post data, rules and the messages
     $validator = Validator::make($file, $rules);
     if ($validator->fails()) {
         // send back to the page with the input data and errors
         return redirect('settings')->withInput()->withErrors($validator);
     } else {
         // checking file is valid.
         if (Input::file('user_image')->isValid()) {
             $extension = Input::file('user_image')->getClientOriginalExtension();
             // getting image extension
             $fileName = rand(11111, 99999) . '.' . $extension;
             // renaming image
             Input::file('user_image')->move('uploads/', $fileName);
             // uploading file to given path
             $file->user_image = $fileName;
             \Auth::user()->post->save();
             // sending back with message
             \Session::flash('flash_message', 'You have successfully updated your codename!');
             return redirect('settings');
         } else {
             // sending back with error message.
             \Session::flash('error', 'uploaded file is not valid');
             return redirect('home');
         }
     }
 }
Exemplo n.º 8
0
 /**
  * Saving and Database Recording Users Default Picture
  * @param UploadedFile $file Library for Uploading Files Locally or Cloud
  * @param User         $user Users Model
  */
 public function UserProfilePicture(UploadedFile $file, User $user)
 {
     $Image = $file->getClientOriginalName();
     $Imagename = 'DP_' . $Image;
     $file->move(\Auth::User()->username . '/profile_images/', $Imagename);
     $user->userData()->update(['profile_picture' => '/' . \Auth::User()->username . '/profile_images/' . $Imagename, 'picture_name' => $Imagename]);
 }
Exemplo n.º 9
0
 public static function getNiveauPrice($niveau)
 {
     if (\Auth::user()->pricebills()->where('niveau', $niveau)->first()) {
         $price = \Auth::user()->pricebills()->where('niveau', $niveau)->first();
         return $price->prix;
     }
 }
Exemplo n.º 10
0
 public static function customCreate(CreateConversationRequest $request)
 {
     $conv = new Conversation();
     $conv->Title = $request->Title;
     // if nothing specified in the request
     if (!$request->has('user_id')) {
         // if we are not even logged ( happen while seeding base)
         if (!\Auth::check()) {
             $conv->user_id = User::first()->id;
         } else {
             $conv->user_id = \Auth::id();
         }
     }
     // if Pending status is specified we take it, if not default value will be applied (false)
     if (!$request->has('Pending')) {
         $conv->Pending = $request->Pending;
     }
     $conv->created_at = Carbon::now();
     $conv->save();
     // When conversation is settled the Thread can be created
     $thread = new Thread();
     $thread->user_id = $conv->user_id;
     $thread->Content = $request->Content;
     $thread->conversation_id = $conv->id;
     $thread->created_at = Carbon::now();
     $thread->Pending = $conv->Pending;
     $thread->save();
     return true;
 }
Exemplo n.º 11
0
 public function send(Request $request)
 {
     $accessToken = $request->input('access_token');
     try {
         $auth = \App\Auth::findByAccessToken($accessToken);
         $auth->telegram_user = $auth->telegramUser()->first();
         $app = $auth->app()->first();
         $text = 'Send on behalf of: [' . $app->client_id . '] ' . $app->name . PHP_EOL . PHP_EOL;
         $text .= 'Message: ' . PHP_EOL;
         $text .= $request->input('text') . PHP_EOL . PHP_EOL;
         $text .= 'Note: If you don\'t want to receive further updates from [' . $app->client_id . '] ' . $app->name;
         $text .= ', you can revoke access via the /revoke command';
         $params = array('chat_id' => $auth->telegram_user->telegram_id, 'text' => $text);
         $ch = curl_init();
         curl_setopt($ch, CURLOPT_URL, 'https://api.telegram.org/bot' . env('BOT_TOKEN') . '/sendMessage');
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
         $json = curl_exec($ch);
         $result = json_decode($json, true);
         if ($result['ok']) {
             return response()->json(array('ok' => true));
         } else {
             return response()->json($result);
         }
     } catch (ModelNotFoundException $e) {
         return response()->json(['error' => 'No active user found.'], 404);
     }
 }
Exemplo n.º 12
0
 public function put($data)
 {
     $this->fill($data);
     $this->user_id = \Auth::user()->id;
     $this->save();
     return $this;
 }
Exemplo n.º 13
0
Arquivo: User.php Projeto: anthon94/p4
 public function isAdmin()
 {
     $user = \Auth::user();
     $role_id = $user->roles->pluck('id');
     if (in_array(1, $role_id->toArray())) {
         return TRUE;
     }
 }
Exemplo n.º 14
0
 public function userReadDiscussion()
 {
     if (\Auth::check()) {
         return $this->hasMany('App\\UserReadDiscussion')->where('user_id', '=', \Auth::user()->id);
     } else {
         abort(500, 'Need to be logged in to access this userReadDiscussion relation');
     }
 }
Exemplo n.º 15
0
 public function isBingoPlayer()
 {
     if (\Auth::user()->role->role == 'bp') {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 16
0
 public function myWatchlist()
 {
     if (Auth::check() && Watchlist::where('user_id', Auth::user()->id)->where('art_id', $this->id)->exists()) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 17
0
 public function isAdmin()
 {
     $user = \Auth::user()->toArray();
     if ($user['isAdmin'] == 1) {
         return true;
     }
     return false;
 }
Exemplo n.º 18
0
 /**
  * @return boolean returns <b>true</b> if this User model is the user we logged in as.
  */
 public function isLoggedUser()
 {
     $authUser = \Auth::user();
     if (!empty($authUser) && $authUser->id == $this->id) {
         return true;
     }
     return false;
 }
Exemplo n.º 19
0
 public function is($role)
 {
     if ($role == Auth::user()->role) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 20
0
 public function isMe()
 {
     if ($this->id == \Auth::user()->id) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 21
0
 public function isSkrbnik()
 {
     if (\Auth::user()->type == 4) {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 22
0
 public static function checkSua($chucnang)
 {
     $rolechucnangs = RoleChucnang::join('danhmucchucnangs', 'role_chucnangs.danhmucchucnang_id', '=', 'danhmucchucnangs.id')->where('role_id', \Auth::user()->role_id)->where('danhmucchucnangs.chucnang_id', $chucnang)->first();
     if ($rolechucnangs->Sua == 1) {
         return TRUE;
     }
     return FALSE;
 }
Exemplo n.º 23
0
 public function getUser(Request $request)
 {
     if (Auth::user()) {
         return Auth::user();
     } else {
         return false;
     }
 }
Exemplo n.º 24
0
 public function complete()
 {
     if ($this->completed_at != null) {
         throw new \Exception('Task already completed');
     }
     $this->completed_at = new Carbon();
     $this->completed_by = \Auth::user()->id;
 }
Exemplo n.º 25
0
 public static function action($name, array $data = [])
 {
     $user_id = 0;
     $user = \Auth::user();
     if ($user) {
         $user_id = $user->id;
     }
     return self::create(['user_id' => $user_id, 'action' => $name, 'json_data' => json_encode($data)]);
 }
Exemplo n.º 26
0
 public static function addNew($description, $total_cost)
 {
     $invoice = new Invoice();
     $invoice->description = $description;
     $invoice->total_cost = $total_cost;
     $invoice->creator_id = \Auth::user()->id;
     $invoice->save();
     return $invoice;
 }
Exemplo n.º 27
0
 public function isAdmin()
 {
     $user = \Auth::user();
     if ($user->userType == 'Admin') {
         return true;
     } else {
         return false;
     }
 }
Exemplo n.º 28
0
 /**
  * @param boolean $hasCode
  * @param AuthenticateUserListener $listener
  * @return \Symfony\Component\HttpFoundation\RedirectResponse
  */
 public function execute($hasCode, AuthenticateUserListener $listener, $provider)
 {
     if (!$hasCode) {
         return $this->getAuthorizationFirst($provider);
     }
     $user = $this->users->findByEmailOrCreate($this->getSocialUser($provider));
     \Auth::login($user, true);
     return $listener->userHasLoggedIn($user);
 }
Exemplo n.º 29
0
 public function activateAccount($code)
 {
     $user = User::where('activation_code', $code)->first();
     if ($user) {
         $user->update(['active' => 1, 'activation_code' => NULL]);
         \Auth::login($user);
         return true;
     }
 }
Exemplo n.º 30
0
 public function scopeAccess($query)
 {
     $user = \Auth::user()->get();
     // manager
     if ($user->role_id == 2) {
         $query->where('users.branch_id', $user->branch_id);
     }
     return $query;
 }