protected function createSiteAndAdminUser() { $site = new \Veer\Models\Site(); $site->url = $this->app['config']->get('app.url'); $site->on_off = 1; $site->save(); $user = new \Veer\Models\User(); $user->email = '*****@*****.**'; $user->password = '******'; $user->sites_id = $site->id; $user->save(); $admin = new \Veer\Models\UserAdmin(); $admin->save(); $user->administrator()->save($admin); }
/** * Execute the console command. * * @return mixed */ public function fire() { $this->info(''); $this->info('Veer is starting up...'); $this->info(''); //$this->call('veer:publish'); // Run migrations if ($this->option('migrate') == true) { $this->info('- Setting up database & tables...'); $this->call('migrate'); } $this->info(''); $this->info('- Adding url to sites table...'); $this->info(''); $site = new \Veer\Models\Site(); $site->url = $this->argument('url'); $site->on_off = 1; $site->save(); // @todo default configuration? $this->info('- Registering administrator...'); $this->info(''); $email = $this->argument('email') ?: $this->ask('What is your email?'); $password = $this->argument('password') ?: $this->secret('What is the password?'); $this->info(''); $user = new \Veer\Models\User(); $user->email = $email; $user->password = $password; $user->sites_id = $site->id; $user->save(); $admin = new \Veer\Models\UserAdmin(); $admin->save(); $user->administrator()->save($admin); $this->call('cache:clear'); $this->info('Congratulations. Everything is done.'); $this->info('Continue here: '); $this->info(''); $this->info($this->argument('url') . '/admin/sites'); $this->info(''); }
/** * add New Order * * pin, close_time, type, status_id, cluster, cluster_oid, * users_id, user_type, userdiscount_id, userbook_id, country, city, address, hash * * @param $order * @param $usersId * @return array */ public function addNewOrder($order, $usersId, $book = array(), $pretend = false) { $order->pin = false; $order->close_time = null; $order->type = 'reg'; $firststatus = \Veer\Models\OrderStatus::firststatus()->pluck('id'); $order->status_id = !empty($firststatus) ? $firststatus : 0; $cluster = \Veer\Models\Configuration::where('sites_id', '=', $order->sites_id)->where('conf_key', '=', 'CLUSTER')->pluck('conf_val'); if (empty($cluster)) { $cluster = 0; } $order->cluster = $cluster; $order->cluster_oid = \Veer\Models\Order::where('sites_id', '=', $order->sites_id)->where('cluster', '=', $cluster)->max('cluster_oid') + 1; if (empty($usersId) && !empty($order->email)) { $findUser = \Veer\Models\User::where('sites_id', '=', $order->sites_id)->where('email', '=', $order->email)->first(); if (is_object($findUser)) { $order->users_id = $findUser->id; if (empty($order->phone)) { $order->phone = $findUser->phone; } if (empty($order->name)) { $order->name = $findUser->firstname . " " . $findUser->lastname; } } else { $newUser = new \Veer\Models\User(); $newUser->sites_id = $order->sites_id; $newUser->email = $order->email; $newUser->phone = $order->phone; $password2Email = str_random(16); $newUser->password = $password2Email; $newUser->save(); $order->users_id = $newUser->id; $order->type = 'unreg'; $unregStatus = \Veer\Models\OrderStatus::unregstatus()->pluck('id'); if (!empty($unregStatus)) { $order->status_id = $unregStatus; } } } if (!empty($usersId) && (empty($order->email) || empty($order->phone) || empty($order->name))) { $findUser = \Veer\Models\User::where('id', '=', $usersId)->first(); if (is_object($findUser)) { if (empty($order->email)) { $order->email = $findUser->email; } if (empty($order->phone)) { $order->phone = $findUser->phone; } if (empty($order->name)) { $order->name = $findUser->firstname . " " . $findUser->lastname; } } } $userRole = \Veer\Models\UserRole::whereHas('users', function ($q) use($order) { $q->where('users.id', '=', $order->users_id); })->pluck('role'); $order->user_type = !empty($userRole) ? $userRole : ''; if (!empty($order->userdiscount_id)) { $checkDiscount = \Veer\Models\UserDiscount::where('id', '=', $order->userdiscount_id)->where('sites_id', '=', $order->sites_id)->whereNested(function ($q) use($order) { $q->where('users_id', '=', 0)->orWhere('users_id', '=', $order->users_id); })->whereNested(function ($q) { $q->where('status', '=', 'wait')->orWhere('status', '=', 'active'); })->first(); if (is_object($checkDiscount)) { $checkDiscount->users_id = $order->users_id; $checkDiscount->status = 'active'; $checkDiscount->save(); } else { $order->userdiscount_id = 0; } } if (!empty($book)) { $book['fill']['users_id'] = $order->users_id; $newBook = $this->updateOrNewBook($book, $pretend); } if (isset($newBook) && is_object($newBook)) { $order->userbook_id = $newBook->id; $order->country = !empty($newBook->country) ? $newBook->country : ''; $order->city = !empty($newBook->city) ? $newBook->city : ''; $order->address = trim($newBook->postcode . " " . $newBook->address); } $order->hash = bcrypt($order->cluster . $order->cluster_oid . $order->users_id . $order->sites_id . str_random(16)); if ($pretend == false) { $order->save(); $this->incrementOrdersCount($order->users_id); $secret = new \Veer\Models\Secret(array("secret" => str_random(64))); $order->secrets()->save($secret); } return array($order, isset($checkDiscount) ? $checkDiscount : null); }
/** * register Post */ public function registerPost() { \Event::fire('router.filter: csrf'); $fill = \Input::get('fill'); $fill['sites_id'] = app('veer')->siteId; if (array_has($fill, 'password') && empty($fill['password'])) { array_forget($fill, 'password'); } $rules = array('email' => 'required|email|unique:users,email,NULL,id,deleted_at,NULL,sites_id,' . app('veer')->siteId, 'password' => 'required|min:6'); $validator = \Validator::make($fill, $rules); if ($validator->fails()) { return \Redirect::route('user.register')->withErrors($validator); } \Eloquent::unguard(); $user = new \Veer\Models\User(); $fill['restrict_orders'] = db_parameter('ECOMMERCE_RESTRICT_ORDERS', config('veer.restrict_orders', false)); $fill['newsletter'] = isset($fill['newsletter']) ? true : false; $fill['birth'] = parse_form_date(array_get($fill, 'birth')); $user->fill($fill); $user->save(); \Auth::login($user); return \Redirect::intended(); }