/**
  * @param Guard $auth
  * @param Roles $roles
  * @return bool
  */
 public function authorize(Guard $auth, Roles $roles)
 {
     if ($auth->check() && $roles->isAdmin()) {
         return true;
     }
     return false;
 }
Exemple #2
0
 /**
  * Handle request.
  *
  * @param $request
  * @param callable $next
  * @return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector|\Symfony\Component\HttpFoundation\Response
  */
 public function handle($request, Closure $next)
 {
     if ($this->roles->isModerator() || $this->roles->isAdmin()) {
         return $next($request);
     }
     if ($request->ajax()) {
         return response('Unauthorized.', 401);
     }
     return redirect('/bills');
 }
Exemple #3
0
 /**
  * Create new account.
  *
  * @param CreateAccountRequest $request
  * @return \Illuminate\Contracts\Routing\ResponseFactory|\Symfony\Component\HttpFoundation\Response
  */
 public function register(CreateAccountRequest $request)
 {
     $response = new AjaxResponse();
     $roles = new Roles();
     // Build user data array
     $data = ['email' => $request->get('email'), 'password' => bcrypt($request->get('password')), 'role_id' => $roles->getUserRoleId()];
     // Insert user
     $user = User::create($data);
     // User settings
     UserSetting::insert(['user_id' => $user->id, 'language_id' => Settings::defaultLanguageId()]);
     // Create trial period
     UserTrialPeriod::create(['user_id' => $user->id, 'trial_period_id' => TrialPeriod::where('validity_days', 90)->first()->id]);
     Auth::login($user);
     $response->setSuccessMessage(trans('register.account_created'));
     return response($response->get());
 }
Exemple #4
0
 /**
  * Initialize required stuff.
  */
 public function __construct()
 {
     if (Auth::check()) {
         // Check if admin center should be displayed
         $roles = new Roles();
         $showAdminCenter = false;
         if ($roles->getAdminRoleId() === Auth::user()->role_id || $roles->getModeratorRoleId() === Auth::user()->role_id) {
             $showAdminCenter = true;
         }
         View::share(['showAdminCenter' => $showAdminCenter, 'validSubscription' => UserHelper::validSubscription()]);
         // Set language
         App::setLocale(Settings::language());
         // Check if user subscription is expired
         if (UserHelper::subscriptionLeftDays(Auth::user()->id) < 0) {
             UserTrialPeriod::where('user_id', Auth::user()->id)->update(['expired' => true]);
         }
     }
 }
Exemple #5
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $roles = new Roles();
     $user = new User();
     $user->first_name = $this->argument('first_name');
     $user->last_name = $this->argument('last_name');
     $user->email = $this->argument('email');
     $user->password = bcrypt($this->argument('password'));
     $user->role_id = $roles->getAdminRoleId();
     $user->save();
     // Settings
     $settings = new UserSetting();
     $settings->user_id = $user->id;
     $settings->language_id = 2;
     $settings->save();
     // Trial period
     UserTrialPeriod::create(['user_id' => $user->id, 'trial_period_id' => TrialPeriod::first()->id]);
     $this->info('User with admin privileges was generated');
 }
 /**
  * Allow admin to create new user.
  *
  * @param CreateNewUserRequest $request
  * @return mixed
  */
 public function createNewUser(CreateNewUserRequest $request)
 {
     $roles = new Roles();
     $user = User::create(['email' => $request->get('new_user_email'), 'password' => bcrypt($request->get('new_user_password')), 'special_user' => (bool) $request->get('make_special_user'), 'role_id' => $roles->getUserRoleId()]);
     // Generate user settings
     UserSetting::insert(['user_id' => $user->id, 'language_id' => Settings::defaultLanguageId()]);
     $response = new AjaxResponse();
     $response->setSuccessMessage(trans('users_manager.user_created_successfully'));
     return response($response->get())->header('Content-Type', 'application/json');
 }