Example #1
0
 /**
  * 用户登录
  *
  * @param SignInRequest $request
  * @return \Illuminate\Http\JsonResponse
  * @throws \App\Exceptions\SignInException
  */
 public function doSignIn(SignInRequest $request)
 {
     $loginId = $request->get('login_id');
     $username = $request->get('username');
     $email = $request->get('email');
     $phone = $request->get('phone');
     $password = $request->get('password');
     $remember = $request->get('remember');
     if ($phone) {
         $user = UserManager::signInByPhone($phone, $password, $remember);
     } else {
         if ($email) {
             $user = UserManager::signInByEmail($email, $password, $remember);
         } else {
             if ($username) {
                 $user = UserManager::signInByUsername($username, $password, $remember);
             } else {
                 if (Tools::isEmail($loginId)) {
                     $user = UserManager::signInByEmail($loginId, $password, $remember);
                 } else {
                     if (Tools::isPhone($loginId)) {
                         $user = UserManager::signInByPhone($loginId, $password, $remember);
                     } else {
                         $user = UserManager::signInByUsername($loginId, $password, $remember);
                     }
                 }
             }
         }
     }
     return $this->buildResponse(trans('api.auth.sign_in.success'), Tools::toArray($user));
 }
 /**
  * @param User $user
  * @param $proofOfTransfer
  * @param array $products
  * @param array $quantityHash
  * @param $status
  * @param $customer
  * @param $isHq
  * @param bool $isPickup
  * @param $ipAddress
  * @return Order
  */
 private function createOrder(User $user, $proofOfTransfer, array $products, array $quantityHash, $status, $customer, $isHq, $isPickup = false, $ipAddress)
 {
     assert($user);
     assert($user->id);
     if ($customer) {
         assert($customer->referral_id == $user->id);
     }
     if (empty($products)) {
         \App::abort(500, 'invalid');
     }
     if (empty($quantityHash)) {
         \App::abort(500, 'invalid');
     }
     $allowedProducts = $this->productManager->getAvailableProductList($user, (bool) $customer)->pluck('id')->all();
     assert(!empty($allowedProducts));
     $organizationId = null;
     $hq = Organization::HQ();
     $organizationId = $isHq ? $hq->id : $user->organization_id;
     $orderModel = config('order.order_model');
     $order = new $orderModel();
     $order->fill(['order_status_id' => $status, 'proof_of_transfer_id' => $proofOfTransfer->id, 'customer_id' => $customer ? $customer->id : null, 'organization_id' => $organizationId, 'user_id' => $user->id, 'is_hq' => $isHq, 'is_pickup' => $isPickup, 'created_by_id' => $this->userManager->getRealUserId(), 'ip_address' => $ipAddress]);
     if ($this->date) {
         $order->created_at = $this->date;
     }
     $order->save();
     $index = 0;
     foreach ($products as $key => $product) {
         if (!config('order.allow_quantity') && $quantityHash[$key] != 1) {
             \App::abort(500, 'invalid');
         }
         if (env('APP_ENV') != 'production') {
             if (!in_array($product->id, $allowedProducts)) {
                 ddd([$user, (bool) $customer, $product, $allowedProducts]);
             }
         }
         assert(in_array($product->id, $allowedProducts));
         $product->getPriceAndDelivery($user, $customer, $price, $delivery);
         $organizationId = $product->is_hq ? $hq->id : $user->organization_id;
         assert($organizationId == $order->organization_id, 'organization_id');
         assert($isHq == $product->is_hq, 'is_hq');
         $quantity = $quantityHash[$key];
         assert($product->max_quantity >= $quantity);
         // by default awarded_user_id is auth user
         $awardedUserId = $user->id;
         // if product->awarded_parent is true the set referral id as awarded
         // Only applies to new system
         if ($product->award_parent) {
             assert($user->new_referral_id);
             $awardedUserId = $user->new_referral_id;
         }
         $orderItem = new OrderItem();
         $orderItem->fill(['product_id' => $product->id, 'order_id' => $order->id, 'quantity' => $quantity, 'product_price' => $product->isOtherProduct() ? $proofOfTransfer->amount : $price, 'delivery' => $delivery, 'index' => $index++, 'organization_id' => $organizationId, 'awarded_user_id' => $awardedUserId]);
         if ($this->date) {
             $orderItem->created_at = $this->date;
         }
         $orderItem->save();
     }
     $this->orderCreated($order);
     return $order;
 }
Example #3
0
 public function fire()
 {
     App::setLocale('en');
     try {
         \DB::table('options')->get();
     } catch (QueryException $exception) {
         $this->error('Run artisan migrate before app install.');
         return;
     }
     if (System::isInstalled()) {
         $this->error('App is already installed.');
         return;
     }
     $siteName = $this->ask('Site Name?');
     $masterUsername = $this->ask('Master Username?');
     $masterEmail = $this->ask('Master Email?');
     $masterPassword = $this->secret('Master Password?');
     $confirmPassword = $this->secret('Confirm Password?');
     $validator = Validator::make(['username' => $masterUsername, 'email' => $masterEmail, 'password' => $masterPassword, 'password_confirmation' => $confirmPassword, 'verification_code_for_username' => '-', 'verification_code_for_email' => '-'], (new SignUpRequest())->rules());
     if ($validator->fails()) {
         foreach ($validator->errors()->all() as $error) {
             $this->error($error);
         }
         return;
     }
     System::setSiteName($siteName);
     $masterRole = new App\Role();
     $masterRole->name = 'Master';
     $masterRole->save();
     System::setMasterRoleId($masterRole->id);
     $adminRole = new App\Role();
     $adminRole->name = 'Administrator';
     $adminRole->save();
     System::setAdministratorRoleId($adminRole->id);
     $editorRole = new App\Role();
     $editorRole->name = 'Editor';
     $editorRole->save();
     System::setEditorRoleId($editorRole->id);
     $defaultRole = new App\Role();
     $defaultRole->name = 'User';
     $defaultRole->save();
     System::setDefaultRoleId($defaultRole->id);
     $user = UserManager::signUp($masterUsername, $masterEmail, null, $masterPassword);
     $user->save();
     $user->roles()->attach($masterRole);
     $user->roles()->attach($adminRole);
     $user->roles()->attach($editorRole);
     $user->roles()->attach($defaultRole);
     Option::setValueByKey('installed', true);
     $this->info('Install success!');
 }
Example #4
0
 /**
  * 以 手机号码 登录
  *
  * @param $phone
  * @param $password
  * @param bool $remember
  * @return \Illuminate\Contracts\Auth\Authenticatable|null
  * @throws SignInException
  */
 public static function signInByPhone($phone, $password, $remember = false)
 {
     if (!UserManager::isPhoneExists($phone)) {
         throw new SignInException(SignInException::PhoneNotExists);
     }
     if (Auth::attempt(['phone' => $phone, 'password' => $password], $remember)) {
         return Auth::user();
     }
     throw new SignInException(SignInException::PasswordNotMatch);
 }