Ejemplo n.º 1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     factory(App\QuestionCategory::class)->create(['name' => 'first category']);
     factory(App\QuestionCategory::class)->create(['name' => 'second category']);
     // Generate users
     factory(App\User::class, 2)->create()->each(function ($user) {
         // Generate trial period
         \App\UserTrialPeriod::create(['user_id' => $user->id, 'trial_period_id' => \App\TrialPeriod::first()->id]);
         // Settings
         $user->settings()->save(factory(App\UserSetting::class)->make(['user_id' => $user->id, 'language_id' => 1]));
         // Generate notifications
         $notifications = \App\Notification::all();
         foreach ($notifications as $notification) {
             $user->notifications()->save(factory(\App\UserNotification::class)->make(['user_id' => $user->id, 'notification_id' => $notification->id]));
         }
         // Bills per user
         $rows = 12;
         // Products per bill
         $productsPerBill = 5;
         for ($i = 0; $i < $rows; $i++) {
             // Generate client
             $client = $user->clients()->save(factory(App\Client::class)->make());
             // Generate bill for that client
             $bill = $user->bills()->save(factory(App\Bill::class)->make(['client_id' => $client->id]));
             // Generate products
             for ($j = 0; $j < $productsPerBill; $j++) {
                 $product = $user->products()->save(factory(App\Product::class)->make());
                 $bill->products()->save(factory(App\BillProduct::class)->make(['product_id' => $product->id]));
                 $applicationProduct = factory(App\ApplicationProduct::class)->create();
                 $bill->applicationProducts()->save(factory(App\BillApplicationProduct::class)->make(['product_id' => $applicationProduct->id]));
             }
         }
     });
 }
Ejemplo n.º 2
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());
 }
Ejemplo n.º 3
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]);
         }
     }
 }
Ejemplo n.º 4
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');
 }
Ejemplo n.º 5
0
 /**
  * Return trial period of given user.
  *
  * @param int|bool $userId Optional. If not given the id of current logged in user will be used.
  * @return array
  *      'validity_days' int Number of validity days.
  *      'start' string Trial start date
  */
 private static function _userTrialPeriodQuery($userId = false)
 {
     if (!$userId) {
         $userId = \Auth::user()->id;
     }
     $userTrial = UserTrialPeriod::where('user_id', $userId)->select('user_trial_periods.created_at as start', 'trial_periods.validity_days as validity_days')->leftJoin('trial_periods', 'user_trial_periods.trial_period_id', '=', 'trial_periods.id')->groupBy('trial_periods.id')->first();
     return $userTrial;
 }