/**
  * Overrides the action when a user is authenticated.
  * If the user authenticated but does not exist in the user table we create them.
  * @param Request $request
  * @param Authenticatable $user
  * @return \Illuminate\Http\RedirectResponse
  * @throws AuthException
  */
 protected function authenticated(Request $request, Authenticatable $user)
 {
     // Explicitly log them out for now if they do no exist.
     if (!$user->exists) {
         auth()->logout($user);
     }
     if (!$user->exists && $user->email === null && !$request->has('email')) {
         $request->flash();
         session()->flash('request-email', true);
         return redirect('/login');
     }
     if (!$user->exists && $user->email === null && $request->has('email')) {
         $user->email = $request->get('email');
     }
     if (!$user->exists) {
         // Check for users with same email already
         $alreadyUser = $user->newQuery()->where('email', '=', $user->email)->count() > 0;
         if ($alreadyUser) {
             throw new AuthException('A user with the email ' . $user->email . ' already exists but with different credentials.');
         }
         $user->save();
         $this->userRepo->attachDefaultRole($user);
         auth()->login($user);
     }
     $path = session()->pull('url.intended', '/');
     $path = baseUrl($path, true);
     return redirect($path);
 }
Example #2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     $data = Items::find($id);
     if ($data) {
         if ($request->has('name')) {
             $data->name = $request->input('name');
         }
         if ($request->has('status') && ($status = States::find($request->input('status')))) {
             $data->status = $status->id;
         }
         if ($request->has('user_id') && ($person = Persons::find($request->input('user_id')))) {
             $data->user_id = $person->id;
         }
         if ($request->has('title')) {
             $data->title = $request->input('title');
         }
         if ($request->has('description')) {
             $data->description = $request->input('description');
         }
         if ($data->save()) {
             return $this->success($data);
         } else {
             return $this->error("failed to save");
         }
     } else {
         return $this->error("No person with this id");
     }
 }
Example #3
0
 public function index(Request $request)
 {
     $scope = [];
     if ($request->has('title')) {
         $scope['title'] = ['LIKE', '%' . $request->input('title') . '%'];
     }
     if ($request->has('host')) {
         $scope['host'] = ['LIKE', '%' . $request->input('host') . '%'];
     }
     if ($request->has('introduction')) {
         $scope['introduction'] = ['LIKE', '%' . $request->input('introduction') . '%'];
     }
     $params = $request->except('page');
     if ($request->has('sort')) {
         $params['sort'] = $request->input('sort');
     } else {
         $params['sort'] = 'id';
     }
     if ($request->has('order')) {
         $params['order'] = $request->input('order');
     } else {
         $params['order'] = 'desc';
     }
     $fts = Ft::select('id', 'title', 'host', 'poster_url', 'introduction')->multiwhere($scope)->orderBy($params['sort'], $params['order'])->paginate(30);
     return view('ft.index', ['params' => $params, 'fts' => $fts]);
 }
 /**
  * @param  Illuminate\Http\Request $request
  * @param  string $device
  * @return json events
  */
 public function getEvents(Request $request, $device)
 {
     /**
      * Limit events
      * @var integer
      */
     $limit = 10;
     /**
      * Start at timestamp
      * @var integer
      */
     $start = 0;
     /**
      * End at string
      * @var string
      */
     $end = "";
     // Set query params based on request params
     if ($request->has('limit')) {
         $limit = $request->get('limit');
     }
     if ($request->has('start')) {
         $start = $request->get('start');
     }
     if ($request->has('end')) {
         $end = "&end=" . $request->get('end');
     }
     try {
         $thingsee = new \Thingsee\ThingseeAPI();
     } catch (\GuzzleHttp\Exception\ClientException $e) {
         dd($e);
     }
     // Return events in json
     return $thingsee->getEvents($device, "?senses=0x00060100,0x00060200,0x00060400,0x00060300&limit=" . $limit . "&start=" . $start . $end);
 }
 public function agendaJson(Request $request)
 {
     // load of actions between start and stop provided by calendar js
     if ($request->has('start') && $request->has('end')) {
         $actions = \App\Action::with('group')->where('start', '>', Carbon::parse($request->get('start')))->where('stop', '<', Carbon::parse($request->get('end')))->orderBy('start', 'asc')->get();
     } else {
         $actions = \App\Action::with('group')->orderBy('start', 'asc')->get();
     }
     $event = '';
     $events = '';
     foreach ($actions as $action) {
         $event['id'] = $action->id;
         $event['title'] = $action->name;
         $event['description'] = $action->body . ' <br/> ' . $action->location;
         $event['body'] = filter($action->body);
         $event['summary'] = summary($action->body);
         $event['location'] = $action->location;
         $event['start'] = $action->start->toIso8601String();
         $event['end'] = $action->stop->toIso8601String();
         $event['url'] = action('ActionController@show', [$action->group->id, $action->id]);
         $event['group_url'] = action('ActionController@index', [$action->group->id]);
         $event['group_name'] = $action->group->name;
         $event['color'] = $action->group->color();
         $events[] = $event;
     }
     return $events;
 }
 public function addToCart(Request $request)
 {
     $id = $request->has('id') ? $request->input('id') : 0;
     $quantity = $request->has('quantity') && $request->input('quantity') > 0 ? $request->input('quantity') : 0;
     $product = Product::where(['id' => $id, 'active' => 1])->first();
     if (null === $product) {
         return response()->json(false);
     }
     $cart = $this->getCart($request);
     if (!array_key_exists($id, $cart) && $quantity > 0) {
         $cart[$id] = $quantity;
     } elseif ($quantity > 0) {
         $cart[$id] += $quantity;
     }
     $request->session()->put('cart', $cart);
     // return product info
     $product = Product::find($id);
     if (sizeof($product->images) > 0 && is_file("images/{$product->images[0]->image}")) {
         $image = "images/{$product->images[0]->image}";
     } else {
         $image = 'images/noImage.jpg';
     }
     $pro = array('id' => $id, 'name' => $product->name, 'qty' => $cart[$id], 'url' => url("{$id}/{$product->alias}"), 'image' => url($image), 'price' => $product->price);
     $cart_data = $this->getCartData($cart);
     return response()->json(['product' => $pro, 'items' => $cart_data['items'], 'total' => $cart_data['total'], 'cart_url' => url('cart')]);
 }
Example #7
0
 /**
  * Display a listing of the resource.
  * @return Response
  */
 public function index(Request $request)
 {
     $posts = CommunityPost::select('community_posts.id', 'community_posts.subject', 'community_posts.content', 'community_posts.created_at', 'community_posts.owner_type', 'community_posts.owner_id')->selectRaw("CASE community_posts.owner_type WHEN 'students' THEN 'student' END as type, COUNT(cp.id) as totalReplies")->whereNull('community_posts.parent_id')->leftJoin('community_posts as cp', 'cp.parent_id', '=', 'community_posts.id')->groupBy('community_posts.id')->with(['likes', 'replies', 'replies.owner', 'owner' => function ($query) {
         return $query->select('name', 'id');
     }])->join('students', function ($query) {
         $query->on('students.id', '=', 'community_posts.owner_id')->where('students.gender', '=', $this->student->gender);
     });
     // ->groupBy('community_posts.id');
     if ($request->has('postable')) {
         switch ($request->input('postable')) {
             case 'element':
                 $posts->where('community_posts.postable_type', 'subject_elements')->where('community_posts.postable_id', $request->input('id'));
                 break;
             default:
                 $posts->whereNull('community_posts.postable_id');
                 break;
         }
     }
     if ($request->has('my')) {
         $posts->where('community_posts.owner_id', $this->student->id)->where('community_posts.owner_type', 'students');
     }
     if ($request->has('query')) {
         $posts->where('community_posts.subject', 'LIKE', '%' . $request->input('query') . '%');
     }
     $posts->orderBy('community_posts.' . $request->input('orderBy', 'id'), 'DESC');
     $posts = $posts->paginate(10);
     foreach ($posts as $post) {
         $post->old = $post->replies->sum(function ($reply) {
             return $reply->created_at->diffInMonths(\Carbon\Carbon::now());
         });
     }
     return response()->json($posts, 200, [], JSON_NUMERIC_CHECK);
 }
 /**
  * Fetch properties from the request.
  *
  * @param  string $property
  *
  * @return array|string
  */
 public function __get($property)
 {
     if ($this->request->has($property)) {
         return $this->request->input($property);
     }
     return false;
 }
 /**
  * UPDATE /api/favouritesTransactions/{favouriteTransactions}
  * @param Request $request
  * @param FavouriteTransaction $favourite
  * @return Response
  */
 public function update(Request $request, FavouriteTransaction $favourite)
 {
     // Create an array with the new fields merged
     $data = array_compare($favourite->toArray(), $request->only(['name', 'type', 'description', 'merchant', 'total']));
     $favourite->update($data);
     if ($request->has('account_id')) {
         $favourite->account()->associate(Account::findOrFail($request->get('account_id')));
         $favourite->fromAccount()->dissociate();
         $favourite->toAccount()->dissociate();
         $favourite->save();
     }
     if ($request->has('from_account_id')) {
         $favourite->fromAccount()->associate(Account::findOrFail($request->get('from_account_id')));
         $favourite->account()->dissociate();
         $favourite->save();
     }
     if ($request->has('to_account_id')) {
         $favourite->toAccount()->associate(Account::findOrFail($request->get('to_account_id')));
         $favourite->account()->dissociate();
         $favourite->save();
     }
     if ($request->has('budget_ids')) {
         $favourite->budgets()->sync($request->get('budget_ids'));
     }
     $favourite = $this->transform($this->createItem($favourite, new FavouriteTransactionTransformer()))['data'];
     return response($favourite, Response::HTTP_OK);
 }
Example #10
0
 public function index(Request $request)
 {
     $args = ['orderby' => $request->has('orderby') ? $request->get('orderby') : 'created_at', 'order' => $request->has('order') ? $request->get('order') : 'desc', 'key' => $request->has('key') ? $request->get('key') : null, 'parent' => $request->has('parent') ? $request->get('parent') : null];
     $items = $this->province->all(current_lang(), $args);
     $data = ['title' => 'Quốc gia', 'items' => $items, 'countries' => $this->country->listAll(true, current_lang())];
     return view('backend.province.index', $data);
 }
 /**
  * @return array
  */
 public function processDataOfBirth()
 {
     // Get the date of birth that the user submitted
     $dob = null;
     if ($this->request->has('dob')) {
         // field name is dob when using input type date
         $dob = $this->request->get('dob');
     } elseif ($this->request->has('dob_year') && $this->request->has('dob_month') && $this->request->has('dob_day')) {
         // field name has _year, _month and _day components if input type select
         $dob = $this->request->get('dob_year') . '-' . $this->request->get('dob_month') . '-' . $this->request->get('dob_day');
     }
     $remember_me = false;
     if ($this->request->get('remember_me') == "on") {
         $this->session->set('remembered_day', $this->request->get('dob_day'));
         $this->session->set('remembered_month', $this->request->get('dob_month'));
         $this->session->set('remembered_year', $this->request->get('dob_year'));
         $this->session->set('remember_me', "on");
         $remember_me = true;
     } else {
         $this->session->remove('remembered_day');
         $this->session->remove('remembered_month');
         $this->session->remove('remembered_year');
         $this->session->remove('remember_me');
     }
     // return in an array for validator
     return ['dob' => $dob, 'remember' => $remember_me];
 }
 public function retrieve(Request $request, Weather $weather)
 {
     if (!$request->has('lat') || !$request->has('lon')) {
         return response('Please provide a lat and lon', 400);
     }
     $input = $request->all();
     // We grab the lat and lon
     $lat = $input['lat'];
     $lon = $input['lon'];
     // We grab the latest data from this lat and long
     $rawData = file_get_contents('http://api.openweathermap.org/data/2.5/weather?lat=' . $lat . '&lon=' . $lon);
     if (!$rawData) {
         // We failed to retrieve data from the webservice
         // Just return the stuff we have
         return $weather->where('lat', $lat)->where('lon', $lon)->limit(10)->get();
     }
     $jsonData = json_decode($rawData, true);
     // We transform this data
     $data = ['dt' => $jsonData['dt'], 'lat' => $lat, 'lon' => $lon, 'type' => $jsonData['weather'][0]['main'], 'temp' => $jsonData['main']['temp'] - 273.15];
     // Check if we already have a record with same lat/lon and dt in our database
     $weatherCheck = $weather->where('lat', $lat)->where('lon', $lon)->where('dt', Carbon::createFromTimeStamp($data['dt']))->limit(1)->get();
     // Record isn't in our db yet
     if ($weatherCheck->isEmpty()) {
         // We store the data in our database
         $weather->create($data);
     }
     // We grab the last 10 weather report from given lat/lon and return it
     return $weather->where('lat', $lat)->where('lon', $lon)->limit(10)->get();
 }
Example #13
0
 public function getCartList(Request $request)
 {
     if (!$request->has('uid')) {
         return response()->json(Message::setResponseInfo('PARAMETER_ERROR'));
     }
     $page = $request->get('page', 1);
     $uid = $request->get('uid');
     $sid = 0;
     if ($request->has('sid')) {
         $sid = $request->get('sid');
     }
     $totalNum = $this->_model->getCartTolalNum($uid, $sid);
     $pagedata = $this->getPageData($page, $this->_length, $totalNum);
     $this->_response['page'] = $pagedata;
     if ($totalNum <= 0) {
         return response()->json(Message::setResponseInfo('DATA_EMPTY'));
     }
     $list = $this->_model->getCartList($uid, $sid, $pagedata->offset, $this->_length);
     if ($list) {
         $this->_response['cart'] = $list;
         return response()->json(Message::setResponseInfo('SUCCESS', $this->_response));
     } else {
         return response()->json(Message::setResponseInfo('FAILED'));
     }
 }
 public function updateProfile(Request $request)
 {
     $user = User::find(Auth::user()->id);
     if ($request->has('first')) {
         $user->first = $request->input('first');
     }
     if ($request->has('last')) {
         $user->last = $request->input('last');
     }
     if ($request->has('email')) {
         $user->email = $request->input('email');
     }
     if ($request->has('phone')) {
         $user->phone = $request->input('phone');
     }
     if ($request->hasFile('resume')) {
         $request->file('resume')->move(public_path('resumes'), $user->first . '_' . $user->last . '_' . $user->id . '.' . $request->file('resume')->getClientOriginalExtension());
         $user->resume = '/resumes/' . $user->first . '_' . $user->last . '_' . $user->id . '.' . $request->file('resume')->getClientOriginalExtension();
     }
     if ($request->hasFile('headshot')) {
         $request->file('headshot')->move(public_path('headshots'), $user->first . '_' . $user->last . '_' . $user->id . '.' . $request->file('headshot')->getClientOriginalExtension());
         $user->headshot = '/headshots/' . $user->first . '_' . $user->last . '_' . $user->id . '.' . $request->file('headshot')->getClientOriginalExtension();
     }
     $user->save();
     $request->session()->flash('success', 'Profile Updated!');
     return view('editProfile', ['user' => $user]);
 }
Example #15
0
 public function browse(Request $request, $category = null)
 {
     // get categories
     $categories = Category::orderBy('id', 'desc')->get();
     // get jobs
     if ($category != null) {
         $cat = Category::where('name', '=', $category)->first();
         $jobs = $cat->jobs;
     } else {
         $jobs = Jobs::query();
         // set condition category
         if ($request->has('category')) {
             $cat = Category::where('name', '=', $request->get('category'))->first();
             $jobs = $cat->jobs();
         }
         // set condition state
         if ($request->has('state')) {
             $jobs->where('state', '=', $request->get('state'));
         }
         // set condition keywords
         if ($request->has('keywords')) {
             $searchWords = explode(' ', $request->get('keywords'));
             foreach ($searchWords as $word) {
                 $jobs->orWhere('description', 'LIKE', '%' . $word . '%');
             }
         }
         $jobs = $jobs->orderBy('id', 'desc')->get();
     }
     return view('jobs.browse')->with('jobs', $jobs)->with('jobsCount', Jobs::count())->with('categories', $categories);
 }
Example #16
0
 public function interact(Request $request)
 {
     if ($request->has('text') && $request->has('channel_id') && $request->has('user_name')) {
         $slack = new Slack();
         $slack->respond($request->input('text'), $request->input('channel_id'), $request->input('user_name'));
     }
 }
Example #17
0
 public function twitterOauthCallback(Request $request)
 {
     if (!$request->has('oauth_token') || !$request->has('oauth_verifier')) {
         return redirect("/login");
     }
     // get data from request
     $token = $request->get('oauth_token');
     $verify = $request->get('oauth_verifier');
     $profile = $this->oauth->handleTwitterRedirectAndGetProfile($token, $verify);
     // no email available in twitter
     $user = $this->auth->getUserByTwitterId($profile["id_str"]);
     $isNewUser = false;
     if (is_null($user)) {
         // Register account if there is not exists
         $profileImage = $this->oauth->downloadTwitterProfileImage($profile["profile_image_url"]);
         $user = $this->auth->registerUser($profile["name"], null, null, \Cv\Model\Profile::GENDER_UNISEX, null, $profile["id_str"], $profileImage);
         $isNewUser = true;
     }
     $this->auth->loginWithUser($user, true);
     // redirect to application
     if ($isNewUser) {
         return redirect("/tutorial");
     }
     return redirect("/");
 }
Example #18
0
 public function loginPost(Request $request)
 {
     $redirectTarget = $request->has('target') ? $request->get('target') : 'root-index';
     $email = trim($request->get('email', ''));
     $password = trim($request->get('password', ''));
     $isRemember = $request->has('remember');
     $user = Users::where('email', $email)->first();
     if (empty($user)) {
         Notifications::add('User not registered', 'danger', 'login');
         return Redirect::route('login', ['target' => $redirectTarget])->withInput();
     }
     if (!Hash::check($password, $user->password)) {
         Notifications::add('Wrong password', 'danger', 'login');
         return Redirect::route('login', ['target' => $redirectTarget])->withInput();
     }
     if ($user->active != '1') {
         Notifications::add('User is not allowed to log in', 'danger', 'login');
         return Redirect::route('login', ['target' => $redirectTarget])->withInput();
     }
     try {
         Auth::login($user, $isRemember);
     } catch (QueryException $e) {
         //just for demo purposes
     }
     return Redirect::route($redirectTarget);
 }
Example #19
0
 public function store(Request $request)
 {
     $user = Auth::user();
     if ($user->is('admin|groupadmin')) {
         if ($request->hasFile('file')) {
             $filename = $request->file('file')->getClientOriginalName();
             if ($request->file('file')->move(sys_get_temp_dir(), $filename)) {
                 $path = sys_get_temp_dir() . '/' . $filename;
                 if ($request->has('user_id')) {
                     $target = User::findOrFail($request->input('user_id'));
                     $folder = $target->username;
                     $ret = redirect(url('admin/show/' . $target->id));
                 } else {
                     if ($request->has('group_id')) {
                         $group = Group::findOrFail($request->input('group_id'));
                         $folder = $group->name;
                         $ret = redirect(url('admin/groups/'));
                     }
                 }
                 if ($user->testAccess($folder)) {
                     Cloud::loadFile($path, $folder, $filename);
                 } else {
                     abort(403);
                 }
                 unlink($path);
             }
         }
         return $ret;
     } else {
         abort(403);
     }
 }
Example #20
0
 /**
  * Return grid data
  *
  * @param $request \Illuminate\Http\Request
  * @return Response
  */
 public function grid(Request $request)
 {
     $take = $request->has('rowCount') ? $request->get('rowCount') : 10;
     $skip = $request->get('current') - 1;
     $searchPhrase = $request->has('searchPhrase') ? $request->get('searchPhrase') : '';
     $sort = $request->has('sort') ? $request->get('sort') : false;
     //        $results = $this->user->search($searchPhrase);
     if ($searchPhrase) {
         $results = $this->user->select('id', 'email', 'role', 'status', 'last_login', 'created_at', 'updated_at')->where('first_name', 'like', '%' . $searchPhrase . '%')->orWhere('last_name', 'like', '%' . $searchPhrase . '%')->orWhere('email', 'like', '%' . $searchPhrase . '%')->orWhere('p_title', 'like', '%' . $searchPhrase . '%')->orWhere('landline', 'like', '%' . $searchPhrase . '%')->orWhere('mobile', 'like', '%' . $searchPhrase . '%');
     } else {
         $results = $this->user->select('id', 'email', 'role', 'status', 'last_login', 'created_at', 'updated_at');
     }
     $count_results = $results->count();
     $results = $results->take($take)->skip($take * $skip);
     if (is_array($sort)) {
         if (key($sort) == 'state') {
             $results = $results->orderBy('status', $sort[key($sort)]);
         } else {
             $results = $results->orderBy(key($sort), $sort[key($sort)]);
         }
     }
     $results = $results->get();
     $rows = [];
     foreach ($results as $row) {
         $rows[] = ['id' => $row->id, 'email' => $row->email, 'role' => $row->role, 'state' => $row->status, 'last_login' => !empty($row->last_login) ? $row->last_login->format('d-m-Y') : '---', 'created_at' => $row->created_at->format('d-m-Y')];
     }
     $data = array('current' => (int) $request->get('current'), 'rowCount' => $take, 'rows' => $rows, 'total' => $count_results);
     return response($data);
 }
 /**
  * Insert new crud
  *
  * @param Request $request
  *
  * @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function insert(Request $request)
 {
     $validation = Validator::make($request->all(), ['name' => 'required', 'title' => 'required', 'soft' => 'required']);
     if ($validation->fails()) {
         return redirect()->back()->withInput()->withErrors($validation);
     }
     // Get model names
     $cruds = Crud::all();
     $models = [];
     foreach ($cruds as $crud) {
         $tableName = strtolower($crud->name);
         $models[$crud->id] = $tableName;
     }
     // Init QuickCache
     $cache = new QuickCache();
     $cached = [];
     $cached['relationships'] = 0;
     $cached['files'] = 0;
     $cached['password'] = 0;
     $cached['date'] = 0;
     $fields = [];
     foreach ($request->f_type as $index => $field) {
         $fields[$index] = ['type' => $field, 'title' => $request->f_title[$index], 'label' => $request->f_label[$index], 'validation' => $request->f_validation[$index], 'value' => $request->f_value[$index], 'default' => $request->f_default[$index], 'relationship_id' => $request->has('f_relationship.' . $index) ? $request->f_relationship[$index] : '', 'relationship_name' => $request->has('f_relationship.' . $index) ? $models[$request->f_relationship[$index]] : '', 'relationship_field' => $request->has('f_relationship_field.' . $request->f_relationship[$index]) ? $request->f_relationship_field[$request->f_relationship[$index]] : '', 'texteditor' => $request->f_texteditor[$index], 'size' => $request->f_size[$index] * 1024, 'show' => $request->f_show[$index]];
         if ($field == 'relationship') {
             $cached['relationships']++;
         } elseif ($field == 'file') {
             $cached['files']++;
         } elseif ($field == 'password') {
             $cached['password']++;
         } elseif ($field == 'date') {
             $cached['date']++;
         }
     }
     $cached['fields'] = $fields;
     $cached['name'] = $request->name;
     $cached['soft_delete'] = $request->soft;
     $cache->put('fieldsinfo', $cached);
     // Create crud entry
     Crud::create(['position' => 0, 'icon' => $request->icon != '' ? $request->icon : 'fa-database', 'name' => $request->name, 'title' => $request->title, 'parent_id' => null, 'roles' => '1']);
     // Create migrations
     $migrationBuilder = new MigrationBuilder();
     $migrationBuilder->build();
     // Create model
     $modelBuilder = new ModelBuilder();
     $modelBuilder->build();
     // Create request
     $requestBuilder = new RequestBuilder();
     $requestBuilder->build();
     // Create controller
     $controllerBuilder = new ControllerBuilder();
     $controllerBuilder->build();
     // Create views
     $viewsBuilder = new ViewsBuilder();
     $viewsBuilder->build();
     // Call migrations
     Artisan::call('migrate');
     // Destroy our cache file
     $cache->destroy('fieldsinfo');
     return redirect(config('laragenerators.route'));
 }
Example #22
0
 /**
  * Получение пользователя и его авторизация
  * @return \Illuminate\Http\RedirectResponse
  */
 public function getAuthenticate()
 {
     if (!$this->request->has('code')) {
         return redirect()->intended('/')->with('oauth', 'Ошибка авторизации');
     }
     //Получаем access_token
     $accessToken = $this->provider->access($this->request->input('code'));
     //Если данные не получены
     if (!$accessToken) {
         return redirect()->intended('/')->with('oauth', 'Ошибка авторизации');
     }
     //Получаем данные пользователя
     $userData = $this->provider->userData($accessToken);
     //Если данные не получены
     if (!$userData) {
         return redirect()->intended('/')->with('oauth', 'Ошибка получения данных пользователя');
     }
     //Создаем массив с пользовательскими данными
     $userArray = $this->provider->userArray($accessToken, $userData);
     //Создаем нового пользователя или обновляем существующего
     $user = $this->userCreateUpdate($userArray);
     //Если пользователь не создался, или дублирование email алреса
     if (!$user) {
         return redirect()->intended('/')->with('oauth', 'Ошибка или пользователь с таким email существует!');
     }
     //Авторизация и запоминание пользователя в системе
     \Auth::login($user, true);
     return redirect()->intended('/');
 }
Example #23
0
 /**
  * Checks the steam login
  *
  * @return bool
  */
 public function validate()
 {
     if ($this->request->has('openid_assoc_handle') && $this->request->has('openid_signed') && $this->request->has('openid_sig')) {
         $get = $this->request->all();
         try {
             $params = array('openid.assoc_handle' => $get['openid_assoc_handle'], 'openid.signed' => $get['openid_signed'], 'openid.sig' => $get['openid_sig'], 'openid.ns' => 'http://specs.openid.net/auth/2.0');
             $signed = explode(',', $get['openid_signed']);
             foreach ($signed as $item) {
                 $val = $get['openid_' . str_replace('.', '_', $item)];
                 $params['openid.' . $item] = get_magic_quotes_gpc() ? stripslashes($val) : $val;
             }
             $params['openid.mode'] = 'check_authentication';
             $data = http_build_query($params);
             $context = stream_context_create(array('http' => array('method' => 'POST', 'header' => "Accept-language: en\r\n" . "Content-type: application/x-www-form-urlencoded\r\n" . "Content-Length: " . strlen($data) . "\r\n", 'content' => $data)));
             $result = file_get_contents(self::OPENID_URL, false, $context);
             preg_match("#^http://steamcommunity.com/openid/id/([0-9]{17,25})#", $get['openid_claimed_id'], $matches);
             $this->steamId = is_numeric($matches[1]) ? $matches[1] : 0;
             $this->parseInfo();
             $response = preg_match("#is_valid\\s*:\\s*true#i", $result) == 1 ? true : false;
         } catch (Exception $e) {
             $response = false;
         }
         if (is_null($response)) {
             throw new Exception('The Steam login request timed out or was invalid');
         }
         return $response;
     } else {
         return false;
     }
 }
Example #24
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function add(Request $request)
 {
     // Declare a new instance of the Schedule Model
     $entry = new Schedule();
     // Before we add the route, lets check to see if the airport exists.
     if (!Airport::findorfail($request->input('depicao'))) {
         AirportsAPI::addFromDB($request->input('depicao'));
     }
     if (!Airport::findorfail($request->input('arricao'))) {
         AirportsAPI::addFromDB($request->input('arricao'));
     }
     // add the form elements
     $entry->code = $request->input('code');
     $entry->flightnum = $request->input('flightnum');
     $entry->depicao = $request->input('depicao');
     $entry->arricao = $request->input('arricao');
     if ($request->has('alticao')) {
         $entry->alticao = $request->input('alticao');
     }
     if ($request->has('route')) {
         $entry->route = $request->input('route');
     }
     if ($request->has('aircraft')) {
         $entry->alticao = $request->input('aircraft');
     }
     $entry->daysofweek = "0123456";
     $entry->type = $request->input('type');
     if ($request->has('enabled')) {
         $entry->enabled = $request->input('enabled');
     } else {
         $entry->enabled = 1;
     }
     $entry->save();
 }
 /**
  * Return grid data
  *
  * @param $request \Illuminate\Http\Request
  * @return Response
  */
 public function grid(Request $request)
 {
     $take = $request->has('rowCount') ? $request->get('rowCount') : 10;
     $skip = $request->get('current') - 1;
     $searchPhrase = $request->has('searchPhrase') ? $request->get('searchPhrase') : '';
     $sort = $request->has('sort') ? $request->get('sort') : false;
     //        $results = $this->page->search($searchPhrase);
     if ($searchPhrase) {
         $results = $this->setting->select('id', 'name', 'key', 'default', 'user_editable', 'created_at', 'updated_at')->where('name', 'like', '%' . $searchPhrase . '%')->orWhere('key', 'like', '%' . $searchPhrase . '%');
     } else {
         $results = $this->setting->select('id', 'name', 'key', 'default', 'user_editable', 'created_at', 'updated_at');
     }
     $count_results = $results->count();
     $results = $results->take($take)->skip($take * $skip);
     if (is_array($sort)) {
         $results = $results->orderBy(key($sort), $sort[key($sort)]);
     }
     $results = $results->get();
     $rows = [];
     foreach ($results as $row) {
         $rows[] = ['id' => $row->id, 'name' => $row->name, 'key' => $row->key, 'default' => $row->default, 'user_editable' => $row->user_editable];
     }
     $data = array('current' => (int) $request->get('current'), 'rowCount' => $take, 'rows' => $rows, 'total' => $count_results);
     return response($data);
 }
 /**
  * @param $mod
  * @param Request $request
  */
 public function articleSearch($mod, $request)
 {
     $title = $author = $article_type = $update_at_start = $update_at_end = '';
     if ($request->has('title')) {
         $title = $request->input('title');
         $mod->where('title', 'LIKE', "%{$title}%");
     }
     if ($request->has('author')) {
         $author = $request->input('author');
         $mod->where('author', 'LIKE', "%{$author}%");
     }
     if ($request->has('article_type')) {
         $article_type = $request->input('article_type');
         $mod->where('article_type', '=', $article_type);
     }
     if ($request->has('update_at_start')) {
         $update_at_start = $request->input('update_at_start');
         $mod->where('update_at', '>=', $update_at_start);
     }
     if ($request->has('update_at_end')) {
         $update_at_end = $request->input('update_at_end');
         $mod->where('update_at', '<=', $update_at_end);
     }
     $this->assign('title', $title);
     $this->assign('author', $author);
     $this->assign('article_type', $article_type);
     $this->assign('update_at_start', $update_at_start);
     $this->assign('update_at_end', $update_at_end);
 }
 /**
  * Register/login user via social network app.
  *
  * @param AuthenticateUser $authenticateUser
  * @param SocialiteProvider $socialiteProvider
  * @param Request $request
  * @param $provider Socialite provider name.
  * @return mixed
  */
 public function loginWithProvider(AuthenticateUser $authenticateUser, SocialiteProvider $socialiteProvider, Request $request, $provider)
 {
     if (!$socialiteProvider->isValid($provider)) {
         abort(404);
     }
     return $authenticateUser->execute($request->has('code') || $request->has('oauth_token'), $provider, $this);
 }
 /**
  * 一覧表示
  *
  * @param Request $request
  * @return \Illuminate\View\View
  */
 public function index(Request $request)
 {
     // 作物一覧を取得
     $crops = Crop::orderBy('display_order')->get();
     // 未選択の場合、先頭の作物を選択
     $crop = Crop::findOrFail($request->input('crop_id') ?: $crops->first()->id);
     // 作物に紐付く作業内容を取得
     $works = $crop->works()->orderBy('works.display_order')->get();
     if ($request->ajax()) {
         return compact('works');
     }
     // 圃場一覧を取得
     $workFields = WorkField::orderBy('display_order')->get();
     // 検索
     $workRecordsQuery = WorkRecord::with(['workSeeding', 'workPestControls', 'workDiaries' => function ($query) use($request) {
         if (!$request->has('archive')) {
             $query->where('archive', false);
         }
     }, 'workDiaries.workField', 'work'])->whereExists(function ($query) use($request, $crop) {
         $query->select(DB::raw(1))->from('work_diaries')->join('work_diary_work_record', 'work_diary_work_record.work_diary_id', '=', 'work_diaries.id')->whereNull('work_diaries.deleted_at')->whereRaw('work_diary_work_record.work_record_id = work_records.id');
         if (!$request->has('archive')) {
             $query->where('archive', false);
         }
         if ($request->has('field_ids')) {
             // 圃場を絞込
             $query->whereIn('work_diaries.work_field_id', $request->input('field_ids'));
         }
     })->where('crop_id', $crop->id);
     if ($request->has('work_ids')) {
         // 作業内容を絞込
         $workRecordsQuery->whereIn('work_id', $request->input('work_ids'));
     }
     $workRecords = $workRecordsQuery->latest()->paginate(config('const.max_work_record'));
     return view('workRecord.index', compact('crops', 'works', 'workFields', 'workRecords'));
 }
Example #29
0
 /**
  * Edit page
  *
  * @param Request $request
  * @param int $id
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
  */
 public function edit(Request $request, $id = 0)
 {
     if ($request->isMethod('post')) {
         $rules = ['name' => 'required|unique:categories,name,' . $id, 'alias' => 'required|unique:categories,alias,' . $id, 'content' => 'required'];
         Validator::make($request->all(), $rules)->validate();
         $page = Category::find($id);
         $page->name = $request->input('name');
         $page->alias = $request->input('alias');
         $page->meta_keys = $request->input('meta_keys');
         $page->meta_desc = $request->input('meta_desc');
         if ($request->has('parent')) {
             $page->parent_id = $request->input('parent');
             $page->type = 2;
         } else {
             $page->type = 1;
         }
         $page->publish = $request->has('publish');
         $page->save();
         $page_content = $page->content;
         $page_content->content = $request->input('content');
         $page_content->save();
         return redirect()->route('pages');
     } else {
         $page = Category::getCategoryById($id);
         if (empty($page)) {
             return redirect()->back();
         } else {
             $pages = Category::getParentCategories($id);
             return view('admin.page.edit', compact('pages', 'page'));
         }
     }
 }
Example #30
0
 /**
  * 动作:发送邮件
  *
  * @param Request $request
  */
 public function postSendEmailForPassword(Request $request)
 {
     if ($request->has('userEmail')) {
         $pattern = "/^([a-zA-Z0-9_\\.\\-])+\\@(([a-zA-Z0-9_-])+\\.)+([a-zA-Z0-9]{2,4})+\$/";
         if (preg_match($pattern, Input::get('userEmail'))) {
             if (!$request->has('username')) {
                 $this->exitJson(Core_Comm_Modret::RET_MISS_ARG, '请先填写用户名', 'username');
             }
             if (!User::where('username', '=', $request->input('username'))->first()) {
             }
             $userEmail = $request->input('userEmail');
             $data = array('username' => $request->input('username'));
             Mail::send('auth.emailForPassword', $data, function ($message) {
                 $userEmail = Input::get('userEmail');
                 $message->to($userEmail)->subject('修改后台登录密码');
             });
             //写入缓存
             // Cache::put("dynamicPassword_".Input::get('userEmail'), $dynamicPassword,5);
             // $this->exitJson(Core_Comm_Modret::RET_SUCC, '口令发送成功请查看');
             return redirect()->intended('auth/login');
         } else {
             $this->exitJson(Core_Comm_Modret::RET_MISS_ARG, '请填写正确邮箱地址', 'userEmail');
         }
     }
 }