Example #1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param StoreSessionRequest $request
  *
  * @return Response
  */
 public function store(StoreSessionRequest $request)
 {
     if ($this->userRepository->attemptToSignIn($request->only('email', 'password'), $request->has('remember_me'))) {
         Flash::success('Welcome!');
         return redirect()->intended(route('cms.dashboard'));
     }
     Flash::error('Those credentials do not match our data set.');
     return redirect()->back();
 }
 /**
  * @param Requests\Ahk\SignInRequest $request
  *
  * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  */
 public function postLogin(Requests\Ahk\SignInRequest $request)
 {
     if ($this->userRepository->attemptToSignIn($request->only('email', 'password'), $request->has('remember_me')) && $this->userRepository->hasCompanyRepresentativeRole(Auth::user())) {
         Flash::success(trans('ahk_messages.successful_sign_in'));
         return redirect()->intended(route('home_path'));
     }
     Auth::logout();
     Flash::error(trans('ahk_messages.you_do_not_have_the_necessary_privileges'));
     return redirect()->back();
 }
Example #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param StoreUserRequest $request
  *
  * @return \Illuminate\Http\Response
  */
 public function store(StoreUserRequest $request)
 {
     $userStored = $this->userRepository->store($request->all());
     if (!$userStored) {
         Flash::error(trans('ahk_messages.unable_to_store_user'));
         return redirect()->back();
     }
     Flash::success(trans('ahk_messages.user_created'));
     return redirect()->route('home_path');
 }
Example #4
0
 /**
  * @param array $data
  * @param bool $rememberMe
  * @param bool $login
  *
  * @return User|false
  */
 public function attemptToSignIn(array $data, $rememberMe = false, $login = false)
 {
     if (!Auth::validate(array_only($data, ['email', 'password']))) {
         Flash::error(trans('ahk_messages.credentials_mismatch'));
         return false;
     }
     $user = $this->findByEmail($data['email']);
     if (!$user->verified) {
         Flash::error(trans('ahk_messages.please_validate_your_email_first'));
         return false;
     }
     Auth::login($user);
     return $user;
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param Requests\Ahk\StoreUserRequest $request
  *
  * @return Response
  */
 public function postRegistration(Requests\Ahk\StoreUserRequest $request)
 {
     $userIsStored = $this->userRepository->storeCompanyRepresentativeAccount($request->only('email', 'password'));
     if (!$userIsStored) {
         Flash::error(trans('ahk_messages.unable_to_store_user'));
         return redirect()->back();
     }
     Flash::success(trans('ahk_messages.user_created'));
     if (!$this->appMailer->sendEmailConfirmation($userIsStored)) {
         return redirect()->back();
     }
     Flash::success(trans('ahk_messages.check_your_email_and_complete_registration'));
     return redirect()->route('auth.sign_in');
 }
Example #6
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  * @param Guard                     $guard
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next, Guard $guard = null)
 {
     if (Auth::guard($guard)->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         }
         Flash::error(trans('cms.you_need_to_sign_in_first'));
         return redirect()->guest(route('cms.sessions.create'));
     }
     $user = Auth::user();
     if (!$user->verified) {
         Flash::error('Please visit your email to validate your account.');
         return redirect()->route('cms.sessions.create');
     }
     if (!$this->userRepository->hasAdministratorRole($user)) {
         Flash::error(trans('cms.missing_required_role'));
         return redirect()->route('cms.sessions.create');
     }
     return $next($request);
 }
Example #7
0
 /**
  * Handle an incoming request.
  *
  * @param  \Illuminate\Http\Request $request
  * @param  \Closure                 $next
  * @param Guard|null                $guard
  *
  * @return mixed
  */
 public function handle(Request $request, Closure $next, Guard $guard = null)
 {
     if (Auth::guard($guard)->guest()) {
         if ($request->ajax()) {
             return response('Unauthorized.', 401);
         } else {
             Flash::error(trans('ahk_messages.you_need_to_sign_in'));
             return redirect()->guest(route('auth.sign_in'));
         }
     }
     $user = Auth::user();
     if (!$user->verified) {
         Flash::error(trans('cms.missing_required_role'));
         return redirect()->route('cms.sessions.create');
     }
     if (!$this->userRepository->hasCompanyRepresentativeRole($user)) {
         Flash::error(trans('ahk_messages.you_do_not_have_the_necessary_privileges'));
         return redirect()->route('auth.sign_in');
     }
     return $next($request);
 }
Example #8
0
 /**
  * Update the specified resource in storage.
  *
  * @param UpdateArticleRequest $request
  * @param  int $id
  *
  * @return \Illuminate\Http\Response
  */
 public function update($id, UpdateArticleRequest $request)
 {
     $article = $this->articleRepository->getById($id);
     if ($article === null) {
         Flash::error('cms.article_does_not_exists');
         return redirect()->back();
     }
     $category = $this->categoryRepository->getById($request->get('category_id'));
     $articleUpdated = $this->articleRepository->updateById($id, $request->only(['title', 'description', 'publish', 'source', 'content', 'img_url']), $category);
     if (!$articleUpdated) {
         Flash::error(trans('cms.unable_to_update_article'));
         return redirect()->back();
     }
     Flash::success(trans('cms.article_updated'));
     $tagsUpdated = $this->articleRepository->updateTagsById($articleUpdated->id, $request->get('tagIds', []));
     if (!$tagsUpdated) {
         Flash::error(trans('cms.unable_to_update_tags'));
     }
     return redirect()->route('cms.articles.edit', $articleUpdated);
 }
Example #9
0
 public function response(array $messages)
 {
     Flash::error(trans('ahk_messages.validation_error_occurred'));
     return parent::response($messages);
 }
 /**
  * @param                      $slug
  * @param                      $recovery_token
  * @param ResetPasswordRequest $request
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function postReset($slug, $recovery_token, ResetPasswordRequest $request)
 {
     $user = $this->userRepository->findBySlugAndRecoveryToken($slug, $recovery_token);
     if (!$user) {
         Flash::error('ahk_messages.validation_error_occurred');
         return redirect()->back();
     }
     $user = $this->userRepository->updatePassword($user, $request->get(User::PASSWORD));
     if (!$user) {
         Flash::error(trans('ahk_messages.unknown_error_occurred'));
     } else {
         Flash::success(trans('ahk_messages.you_updated_your_accounts_password'));
     }
     return redirect()->route('auth.sign_in');
 }
Example #11
0
 /**
  * Update the specified category in storage.
  *
  * @param                       $id
  * @param UpdateCategoryRequest $request
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function update($id, UpdateCategoryRequest $request)
 {
     $categorySaved = $this->categoryRepository->updateById($id, $request->only('name'));
     if (!$categorySaved) {
         Flash::error(trans('cms.something_went_wrong'));
         return redirect()->back();
     }
     Flash::success(trans('cms.category_updated'));
     return redirect()->route('cms.articles.categories.edit', $categorySaved);
 }
Example #12
0
 /**
  * Update the specified resource in storage.
  *
  * @param UpdateCompanyRequest $request
  * @param Company              $company
  *
  * @return \Illuminate\Http\Response
  */
 public function update(UpdateCompanyRequest $request, Company $company)
 {
     $user = Auth::user();
     if (!$this->userRepository->hasCompany($user, $company)) {
         Flash::error(trans('ahk_messages.you_do_not_have_the_necessary_privileges'));
         return back()->withInput();
     }
     $file = $request->file('logo_path');
     if (null !== $file) {
         $this->fileRepository->update($company->logo, [File::CLIENT_ORIGINAL_NAME => $file->getClientOriginalName(), File::TEMPORARY_PATH => $file->getRealPath()]);
     }
     if (!($company = $this->companyRepository->update($company, $request->all()))) {
         Flash::error(trans('ahk_messages.unknown_error_occurred'));
         return redirect()->back();
     }
     Flash::success(trans('ahk_messages.company_successfully_updated'));
     return redirect()->route('my.companies.edit', ['slug' => $company->slug]);
 }