public function postChangePassword()
 {
     $newPassword = $this->request->input('password');
     $token = $this->request->input('spToken');
     $validator = $this->loginValidator();
     if ($validator->fails()) {
         if ($this->request->wantsJson()) {
             return $this->respondWithError('Validation Failed', 400, ['validatonErrors' => $validator->errors()]);
         }
         return redirect()->to(config('stormpath.web.changePassword.uri') . '?spToken=' . $token)->withErrors($validator);
     }
     $application = app('stormpath.application');
     try {
         $application->resetPassword($token, $newPassword);
         // the password has been changed. Time to fire the
         // `UserHasResetPassword` event
         //
         Event::fire(new UserHasResetPassword());
         if ($this->request->wantsJson()) {
             return $this->respondOk();
         }
         return redirect()->to(config('stormpath.web.changePassword.nextUri'));
     } catch (\Stormpath\Resource\ResourceError $re) {
         if ($this->request->wantsJson()) {
             return $this->respondWithError($re->getMessage(), $re->getStatus());
         }
         return redirect()->to(config('stormpath.web.changePassword.errorUri'))->withErrors(['errors' => [$re->getMessage()]]);
     }
 }
Exemple #2
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     // 404 page when a model is not found
     if ($e instanceof ModelNotFoundException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['error' => 404, 'mensaje' => 'Recurso no encontrado'], 404);
         }
         return response()->view('errors.404', [], 404);
     }
     if ($this->isHttpException($e)) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['error' => 404, 'mensaje' => 'Recurso no encontrado!'], 404);
         }
         return $this->renderHttpException($e);
     } else {
         // Custom error 500 view on production
         if (app()->environment() == 'production') {
             if ($request->ajax() || $request->wantsJson()) {
                 return response()->json(['error' => ['exception' => class_basename($e) . ' in ' . basename($e->getFile()) . ' line ' . $e->getLine() . ': ' . $e->getMessage()]], 500);
             }
             return response()->view('errors.500', [], 500);
         }
         return parent::render($request, $e);
     }
 }
 public function postRegister()
 {
     $validator = $this->registerValidator();
     if ($validator->fails()) {
         if ($this->request->wantsJson()) {
             return $this->respondWithError('Validation Failed', 400, ['validatonErrors' => $validator->errors()]);
         }
         return redirect()->to(config('stormpath.web.register.uri'))->withErrors($validator)->withInput();
     }
     try {
         $registerFields = $this->setRegisterFields();
         $account = \Stormpath\Resource\Account::instantiate($registerFields);
         $application = app('stormpath.application');
         $account = $application->createAccount($account);
         if ($this->request->wantsJson()) {
             return $this->respondWithAccount($account);
         }
         if (config('stormpath.web.verifyEmail.enabled') == true) {
             return redirect()->route('stormpath.login', ['status' => 'unverified']);
         }
         if (config('stormpath.web.register.autoAuthorize') == false) {
             return redirect()->route('stormpath.login', ['status' => 'created']);
         }
         $login = isset($registerFields['username']) ? $registerFields['username'] : null;
         $login = isset($registerFields['email']) ? $registerFields['email'] : $login;
         $result = $this->authenticate($login, $registerFields['password']);
         return redirect()->to(config('stormpath.web.register.nextUri'))->withCookies([config('stormpath.web.accessTokenCookie.name') => cookie(config('stormpath.web.accessTokenCookie.name'), $result->getAccessTokenString(), $result->getExpiresIn(), config('stormpath.web.accessTokenCookie.path'), config('stormpath.web.accessTokenCookie.domain'), config('stormpath.web.accessTokenCookie.secure'), config('stormpath.web.accessTokenCookie.httpOnly')), config('stormpath.web.refreshTokenCookie.name') => cookie(config('stormpath.web.refreshTokenCookie.name'), $result->getRefreshTokenString(), $result->getExpiresIn(), config('stormpath.web.refreshTokenCookie.path'), config('stormpath.web.refreshTokenCookie.domain'), config('stormpath.web.refreshTokenCookie.secure'), config('stormpath.web.refreshTokenCookie.httpOnly'))]);
     } catch (\Stormpath\Resource\ResourceError $re) {
         if ($this->request->wantsJson()) {
             return $this->respondWithError($re->getMessage(), $re->getStatus());
         }
         return redirect()->to(config('stormpath.web.register.uri'))->withErrors(['errors' => [$re->getMessage()]])->withInput();
     }
 }
Exemple #4
0
 /**
  * Handle an incoming request.
  *
  * @param \Illuminate\Http\Request $request
  * @param \Closure                 $next
  *
  * @return mixed
  */
 public function handle($request, Closure $next, $role, $guard = null)
 {
     if (Auth::guard($guard)->guest()) {
         if ($request->ajax() || $request->wantsJson()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect()->guest('login');
         }
     }
     if (user($guard)->new && config('user.verify_email')) {
         if ($request->ajax() || $request->wantsJson()) {
             return response('Unauthorized.', 401);
         } else {
             return redirect('verify');
         }
     }
     if (!user($guard)->active && config('user.verify_email')) {
         throw new InvalidAccountException('Account is not active.');
     }
     $roles = explode('|', $role);
     if (!user($guard)->hasRoles($roles)) {
         throw new RolesDeniedException($roles);
     }
     return $next($request);
 }
Exemple #5
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($e instanceof ModelNotFoundException) {
         return redirect('/');
     }
     if ($e instanceof MethodNotAllowedHttpException) {
         return redirect('/');
     }
     if ($e instanceof NotFoundHttpException) {
         return response(view('errors.404'), 404);
     }
     if ($e instanceof InvalidConfirmationCodeException) {
         Session::flash('flash_message', $e->getMessage());
         return redirect('/');
     }
     if ($e instanceof UserNotOwnerOfProjectException) {
         Session::flash('flash_message', $e->getMessage());
         return redirect(LaravelLocalization::getCurrentLocale() . '/' . trans('routes.create-project'));
     }
     if ($e instanceof ProjectCompletedException) {
         Session::flash('flash_message', $e->getMessage());
         return redirect(LaravelLocalization::getCurrentLocale() . '/' . trans('routes.create-project'));
     }
     if ($e instanceof UserRequiresAuthenticationException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['login' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.login')]);
         } else {
             Session::flash('flash_message', $e->getMessage());
             return redirect('/');
         }
     }
     if ($e instanceof UserHasIncompleteProjectException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['incomplete' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.incomplete')]);
         }
     }
     if ($e instanceof UserAlreadyHasSubmittedProjectException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['pendingProject' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.pending-project')]);
         }
     }
     if ($e instanceof UserHasCurrentLiveProjectException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['liveProject' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.live-project')]);
         }
     }
     if ($e instanceof ProjectNameAlreadyTakenException) {
         if ($request->ajax() || $request->wantsJson()) {
             return response()->json(['duplicateName' => '<i class="fa fa-exclamation-circle fa-lg"></i>' . trans('create-project-form.duplicate-name')]);
         }
     }
     return parent::render($request, $e);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if (!$request->ajax() && !$request->wantsJson()) {
         $response = $next($request);
         $content = $response->getContent();
         $pos = strripos($content, '</body>');
         if (false !== $pos) {
             $components = config('components');
             $newMatches = true;
             $matchedComponents = [];
             while ($newMatches == true) {
                 $renderedContent = '';
                 $newEls = 0;
                 //loop registered components and add templates as needed.
                 foreach ($components as $id => $component) {
                     if (str_contains($content, '<' . $id) && !in_array($id, $matchedComponents)) {
                         $newEls++;
                         $matchedComponents[] = $id;
                         $componentView = view($component['view']);
                         $renderedContent .= $componentView;
                         $this->systemJs->import()->item($component['js']);
                     }
                 }
                 $content = substr($content, 0, $pos) . $renderedContent . substr($content, $pos);
                 if ($newEls === 0) {
                     $newMatches = false;
                 }
             }
             $response->setContent($content);
         }
         return $response;
     }
     return $next($request);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle($request, Closure $next)
 {
     if ($request->wantsJson()) {
         return $next($request);
     }
     abort(401);
 }
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($e instanceof ModelNotFoundException) {
         $e = new NotFoundHttpException($e->getMessage(), $e);
     }
     /**
      * Response Exception as Json
      *
      */
     if ($request->wantsJson()) {
         $error = new \stdclass();
         $error->error = true;
         if ($e instanceof NotFoundHttpException) {
             $error->code = $e->getStatusCode();
         } else {
             $error->code = $e->getCode();
         }
         if ($error->code == 0) {
             $error->code = 400;
         }
         if ($e instanceof ValidatorException) {
             $error->message = $e->getMessageBag();
         } else {
             $error->message = $e->getMessage();
             if (\App::environment('local')) {
                 $error->file = $e->getFile();
                 $error->line = $e->getLine();
             }
         }
         return response()->json($error, $error->code);
     }
     return parent::render($request, $e);
 }
Exemple #9
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($request->wantsJson()) {
         // Define the response
         $response = ['errors' => 'Sorry, something went wrong.'];
         // If the app is in debug mode
         if (config('app.debug')) {
             // Add the exception class name, message and stack trace to response
             $response['exception'] = get_class($e);
             // Reflection might be better here
             $response['message'] = $e->getMessage();
             $response['trace'] = $e->getTrace();
         }
         // Default response of 400
         $status = 400;
         // If this exception is an instance of HttpException
         if ($this->isHttpException($e)) {
             // Grab the HTTP status code from the Exception
             $status = $e->getStatusCode();
         }
         // Return a JSON response with the response array and status code
         return response()->json($response, $status);
     }
     // Default to the parent class' implementation of handler
     return parent::render($request, $e);
 }
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Exception  $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($request->wantsJson()) {
         return response(['success' => false, 'message' => $e->getMessage()], 404);
     }
     return parent::render($request, $e);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     if ($request->ajax() || $request->wantsJson()) {
         return $next($request);
     }
     return new Response('', 400);
 }
 /**
  *	delete key registered (Only this seller)
  *	@param	$id 	int|string 	id the virtual product
  *	@param	$res 	Request 	object to validate the type of request, action
  *	@return	json
  */
 public function deleteKey($id, Request $res)
 {
     if (!$res->wantsJson()) {
         return redirect()->back();
     }
     $VirtualProduct = VirtualProduct::find($id);
     if (!count($VirtualProduct->toArray())) {
         return json_encode(['message' => trans('globals.error_not_available')]);
     }
     $product = Product::find($VirtualProduct->product_id);
     if (!count($product->toArray())) {
         return json_encode(['message' => trans('globals.error_not_available')]);
     }
     if ($product->user_id != \Auth::id()) {
         return json_encode(['message' => trans('globals.not_access')]);
     }
     $VirtualProductOrder = VirtualProductOrder::where('virtual_product_id', $VirtualProduct->id)->get();
     if (count($VirtualProductOrder->toArray()) > 0) {
         return json_encode(['message' => trans('product.virtualProductsController_controller.key_been_sold')]);
     }
     $VirtualProduct->status = 'cancelled';
     $VirtualProduct->save();
     $stock = count(VirtualProduct::where('product_id', $product->id)->where('status', 'open')->get()->toArray());
     $product->stock = $stock;
     if ($stock == 0) {
         $product->status = 0;
     }
     $product->save();
     return json_encode(['success' => trans('product.controller.saved_successfully')]);
 }
 /**
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @return mixed
  *
  * @throws \Symfony\Component\HttpKernel\Exception\HttpException
  */
 public function handle($request, Closure $next)
 {
     if (!$request->ajax() && !$request->wantsJson()) {
         abort(415);
     }
     return $next($request);
 }
 /**
  * Determine if the session and input CSRF tokens match when the request is not a json.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return bool
  */
 protected function tokensMatch($request)
 {
     if ($request->wantsJson()) {
         return true;
     }
     return parent::tokensMatch($request);
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit(Request $request, $id)
 {
     if ($request->wantsJson() || $request->ajax()) {
         throw new \Exception('Editing is not supported by AJAX');
     }
     return view('project.edit')->with(['project' => Project::find($id)]);
 }
 /**
  * Get the failed login response instance.
  *
  * @param \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 protected function sendFailedLoginResponse(Request $request)
 {
     if ($request->wantsJson() || $request->isJson()) {
         return response($this->getFailedLoginMessage(), 401);
     }
     return redirect()->back()->withInput($request->only($this->loginUsername(), 'remember'))->withErrors([$this->loginUsername() => $this->getFailedLoginMessage()]);
 }
Exemple #17
0
 /**
  * Returns response for browser
  */
 public function response($redirect = null)
 {
     if ($this->request->ajax() || $this->request->wantsJson()) {
         return new JsonResponse(['formErrors' => $this->messageBag->toArray()], 422);
     }
     return \Redirect::to($redirect)->withErrors($this->messageBag->toArray());
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     //Auth::loginUsingId(47,true);
     //dc($guard);
     //dc(Auth::user());
     if (Auth::guard($guard)->guest()) {
         if ($request->ajax() || $request->wantsJson()) {
             return response('Unauthorized.', 401);
         } else {
             //dd('Authenticate, redirect guest login');
             //return "view";
             return redirect()->guest('login');
         }
     } elseif ($request->is('backStage/*')) {
         if (Auth::user()->isFrontEndUser()) {
             $test = 'Authenticate MIDDLEWARE: unauthorized action: ' . $request->getRequestUri() . ', ' . $request->user()->name . ' must be \'back-end user\'';
             return response()->view("errors.401", compact('test'), 401);
         }
         //dc('backStage/*');
         //dc($request->user()->isBackEndUser());
         //dc(Auth::user()->isBackEndUser());
     }
     //dc('asdf');
     //if (Auth::check())
     //dc(Auth::check());
     //	    dc($guard);
     //dc(Auth::user());
     //dd((Auth::guard($guard)->guest()));
     //	    if (Auth::user()->hasRole('mijnZD-user')){
     //		    return redirect('/dashboard');
     //return redirect()->route('sitemap.indexDashboard');
     //	    }
     //dd($request);
     return $next($request);
 }
Exemple #19
0
 /**
  * Get the proper failed validation response for the request.
  *
  * @param array $errors
  *
  * @return \Symfony\Component\HttpFoundation\Response
  * @codeCoverageIgnore
  */
 public function response(array $errors)
 {
     if ($this->request->ajax() || $this->request->wantsJson()) {
         return new JsonResponse($errors, 422);
     }
     return $this->redirector->to($this->getRedirectUrl())->withInput($this->request->except($this->dontFlash))->withErrors($errors, $this->errorBag);
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure  $next
  * @param  string|null  $guard
  * @return mixed
  */
 public function handle($request, Closure $next, $guard = null)
 {
     // Check for the guard and redirect accordingly
     if (Auth::guard($guard)->guest()) {
         if ($request->ajax() || $request->wantsJson()) {
             return response('Unauthorized.', 401);
         } elseif ($guard == 'student') {
             return redirect()->guest('/students/login');
         } elseif ($guard == 'teacher') {
             return redirect()->guest('/teachers/login');
         } elseif ($guard == 'hostelStaff') {
             return redirect()->guest('/hostelStaffs/login');
         } elseif ($guard == 'libraryStaff') {
             return redirect()->guest('/libraryStaffs/login');
         } elseif ($guard == 'departmentStaff') {
             return redirect()->guest('/departmentStaffs/login');
         } elseif ($guard == 'chiefWardenStaff') {
             return redirect()->guest('/chiefWardenStaffs/login');
         } elseif ($guard == 'adminStaff') {
             return redirect()->guest('/adminStaffs/login');
         } elseif ($guard == 'admin') {
             return redirect()->guest('/admins/login');
         }
     }
     return $next($request);
 }
 /**
  * Display a listing of the resource.
  *
  * @param Request $request
  * @return Response
  */
 public function index(Request $request)
 {
     if ($request->wantsJson()) {
         return Notification::where('user_id', Auth::id())->get();
     }
     return view('notifications.index');
 }
 /**
  * Create the response for when a request fails validation.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  array  $errors
  * @return \Illuminate\Http\Response
  */
 protected function buildFailedValidationResponse(Request $request, array $errors)
 {
     if ($request->ajax() && !$request->pjax() || $request->wantsJson()) {
         return new JsonResponse($errors, 422);
     }
     return redirect()->to($this->getRedirectUrl())->withInput($request->input())->withErrors($errors, $this->errorBag());
 }
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  \Closure                  $next
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     if ($request->ajax() || $request->wantsJson()) {
         return $next($request);
     }
     return response('Method not allowed', 405);
 }
Exemple #24
0
 /**
  * Render an exception into an HTTP response.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Exception $e
  * @return \Illuminate\Http\Response
  */
 public function render($request, Exception $e)
 {
     if ($request->wantsJson()) {
         return $this->responseFactory->create($e);
     }
     return parent::render($request, $e);
 }
Exemple #25
0
 public function handle(Request $request, Exception $exception)
 {
     if ($request->wantsJson()) {
         return $this->handleJson($request, $exception);
     }
     return $this->handleWeb($request, $exception);
 }
 /**
  * @param Request $request
  * @param User $user
  */
 public function employeeTrainings(Request $request, User $user)
 {
     $employee = $user->employee;
     if ($request->wantsJson() && $employee) {
         return $employee->trainings()->finishedTrainings()->paginate(10);
     }
 }
 public function show(Request $request, $messageGroupID)
 {
     if ($request->wantsJson()) {
         $messageGroup = MessageGroup::findOrFail($messageGroupID);
         $messages = $messageGroup->messages()->with('sender.employee')->get();
         return $messages;
     }
 }
 protected function renderCustomResponseException(Request $request, Exception $e)
 {
     if ($request->wantsJson() || $request->ajax()) {
         return $this->renderCustomApiException($e);
     } else {
         return $this->renderCustomHttpException($e);
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int $id
  * @param Request $request
  * @return \Illuminate\Http\Response
  */
 public function show($id, Request $request)
 {
     if ($request->wantsJson()) {
         $model = Customers::find($id);
         return response()->json($model);
     }
     return redirect('/customers/' . $id . '/edit');
 }
 public function destroy(Request $request, Student $student)
 {
     $student->delete();
     if ($request->ajax() || $request->wantsJson()) {
         return new JsonResponse($student);
     }
     return redirect('students');
 }