예제 #1
0
 public function index(Request $request)
 {
     $userService = new userService();
     $user = Auth::user();
     $facebookAccountBusiness = $userService->getUserAccountBusinessSocial($user->id, KACANA_SOCIAL_TYPE_FACEBOOK);
     return view('partner.product.index', ['facebookAccountBusiness' => $facebookAccountBusiness, 'user' => $user]);
 }
예제 #2
0
 public function detail($domain, Request $request, $userId)
 {
     $commissionService = new commissionService();
     $userService = new userService();
     $commissions = $commissionService->informationCommission($userId);
     $user = $userService->getUserById($userId);
     return view('admin.partner.detail', ['commissions' => $commissions, 'user' => $user]);
 }
예제 #3
0
 public function sendEmailNewUser($email)
 {
     $userService = new userService();
     $subject = "Kacana.com - Chào mừng bạn đến với Kacana";
     $viewBlade = 'client.emails.send-email-new-user';
     $bcc = KACANA_EMAIL_ADMIN;
     $dataView = ['user' => $userService->getUserByEmail($email)];
     return $this->send($email, $subject, $viewBlade, $dataView, $bcc);
 }
예제 #4
0
파일: Util.php 프로젝트: kacana/kacana.com
 public static function hasSocial($type = KACANA_SOCIAL_TYPE_FACEBOOK)
 {
     $userService = new userService();
     $user = Auth::user();
     if (Auth::check()) {
         $user = $userService->getUserByEmail($user->email);
         foreach ($user->userSocial as $userSocial) {
             if ($userSocial->type == $type && $type != KACANA_SOCIAL_TYPE_FACEBOOK) {
                 return true;
             } elseif ($userSocial->type == $type && $type == KACANA_SOCIAL_TYPE_FACEBOOK && $userSocial->ref == 1) {
                 return true;
             }
         }
     }
     return false;
 }
예제 #5
0
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($domain, $id, UserRequest $request)
 {
     $userService = new userService();
     if ($request->isMethod('POST')) {
         $name = $request->input('name');
         $email = $request->input('email');
         $phone = $request->input('phone');
         $role = $request->input('role');
         $password = $request->input('password');
         $dataUser = ['name' => $name, 'email' => $email, 'phone' => $phone, 'role' => $role];
         if ($password) {
             $password = Hash::make(md5($password));
             array_add($dataUser, 'password', $password);
         }
         $userService->updateItem($id, $dataUser);
     }
     $user = $userService->getUserById($id);
     return view('admin.user.edit', array('item' => $user));
 }
예제 #6
0
 /**
  * @param Request $request
  * @return \BladeView|bool|\Illuminate\View\View|\Symfony\Component\HttpFoundation\Response
  */
 public function deleteSocialItem(Request $request)
 {
     $userService = new userService();
     $type = $request->input('type', 0);
     $socialId = $request->input('socialId', 0);
     $result['ok'] = 0;
     try {
         $result['data'] = $userService->deleteBusinessSocialAccount($socialId, $type, $this->_user->id);
         $result['ok'] = 1;
     } catch (\Facebook\Exceptions\FacebookResponseException $e) {
         if ($request->ajax()) {
             $result['error_message'] = $e->getMessage();
             return $result;
         } else {
             return view('errors.404', ['error_message' => $e->getMessage()]);
         }
     }
     return response()->json($result);
 }
예제 #7
0
 public function facebookCallbackAllowPost(Request $request)
 {
     $util = new Util();
     $userService = new userService();
     $accessToken = $request->input('accessToken', '');
     $result['ok'] = 0;
     $result['accessToken'] = $accessToken;
     try {
         if (Auth::check()) {
             $user = Auth::user();
             $facebook = $util->initFacebook();
             // OAuth 2.0 client handler
             $oAuth2Client = $facebook->getOAuth2Client();
             // Exchanges a short-lived access token for a long-lived one
             $longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
             $facebook->setDefaultAccessToken($longLivedAccessToken);
             $profile = $facebook->getProfile();
             $result = $userService->updateFacebookAccessToken($profile, $longLivedAccessToken, $user);
         }
     } catch (\Facebook\Exceptions\FacebookResponseException $e) {
         if ($request->ajax()) {
             $result['error_message'] = $e->getMessage();
             return $result;
         } else {
             return view('errors.404', ['error_message' => $e->getMessage()]);
         }
     }
     return response()->json($result);
 }
예제 #8
0
 public function processCartWithAddressId($userEmail, $addressId)
 {
     $addressService = new addressService();
     $userService = new userService();
     $orderService = new orderService();
     $cart = $this->cartInformation();
     if (!$cart) {
         throw new \Exception('bad Cart items');
     }
     $checkAddressUser = false;
     $user = $userService->getUserByEmail($userEmail);
     foreach ($user->userAddress as $userAddres) {
         if ($userAddres->id == $addressId) {
             $checkAddressUser = true;
         }
     }
     if (!$checkAddressUser) {
         throw new \Exception('bad address id');
     }
     // create new order for user
     $order = $orderService->createOrder($user->id, $addressId, $cart->total, $cart->quantity, $cart->originTotal, $cart->discount);
     $items = $cart->items;
     foreach ($items as $item) {
         $orderService->createOrderDetail($order->id, $item);
     }
     // destroy CART
     Cart::destroy();
     //send email for user
     $mailService = new mailService();
     if ($mailService->sendEmailOrder($user->email, $order->id)) {
         return $order;
     } else {
         throw new \Exception('Bị lỗi trong quá trình gửi mail');
     }
     // send zalo message for user
     return $order;
 }
예제 #9
0
 public function reportDetailTableUser(Request $request)
 {
     $params = $request->all();
     $userService = new userService();
     try {
         $return = $userService->reportDetailTableUser($params);
     } catch (\Exception $e) {
         // @codeCoverageIgnoreStart
         $return['error'] = $e->getMessage();
         $return['errorMsg'] = $e->getMessage();
         // @codeCoverageIgnoreEnd
     }
     return response()->json($return);
 }
예제 #10
0
 /**
  * @param $name
  * @param $email
  * @param $phone
  * @param $password
  * @param $confirmPassword
  * @param string $role
  * @return mixed
  */
 public function signup($name, $email, $phone, $password, $confirmPassword, $role = KACANA_AUTH_BUYER_NAME)
 {
     $userService = new userService();
     $result['ok'] = 0;
     $permissions = [KACANA_AUTH_ADMIN_NAME, KACANA_AUTH_CUS_NAME, KACANA_AUTH_BUYER_NAME];
     if ($this->_user) {
         return false;
     }
     if (!in_array($role, $permissions)) {
         $result['error_code'] = KACANA_AUTH_SIGNUP_ERROR_NOT_EXISTS_PERMISSION;
         $result['error_message'] = 'Không tồn tại role ' . $role . ' trong hệ thống !';
         return $result;
     }
     if ($password != $confirmPassword) {
         $result['error_code'] = KACANA_AUTH_SIGNUP_ERROR_PASSWORD_NOT_MATCH;
         $result['error_message'] = 'password và confirm password không giống nhau !';
         return $result;
     }
     if (!Validator::make(['email' => $email], ['email' => 'required|email'])) {
         $result['error_code'] = KACANA_AUTH_ERROR_BAD_EMAIL;
         $result['error_message'] = 'email không đúng định dạng !';
         return $result;
     }
     if (!Validator::make(['name' => $name], ['name' => 'required|min:2'])) {
         $result['error_code'] = KACANA_AUTH_ERROR_BAD_NAME;
         $result['error_message'] = 'name không đúng định dạng !';
         return $result;
     }
     //Validate phone
     $userModel = new userService();
     $user = $userModel->getUserByEmail($email);
     if ($user && $user->status == KACANA_USER_STATUS_ACTIVE) {
         $result['error_code'] = KACANA_AUTH_SIGNUP_ERROR_EMAIL_EXISTS;
         $result['error_message'] = 'email "' . $email . '" đã tồn tại trong hệ thống !';
         return $result;
     } else {
         if ($user && $user->status == KACANA_USER_STATUS_CREATE_BY_SYSTEM) {
             // user is created when user buy product on system - so update it when they sign up
             $userData = array();
             $userData['name'] = $name;
             $userData['phone'] = $phone;
             $userData['password'] = Hash::make(md5($password));
             $userData['role'] = $role;
             $userData['status'] = KACANA_USER_STATUS_ACTIVE;
             $user = $userService->updateItem($user->id, $userData);
             $result['ok'] = 1;
             $result['data'] = $user;
             return $result;
         } else {
             // create new user
             $userData = array();
             $userData['name'] = $name;
             $userData['email'] = $email;
             $userData['phone'] = $phone;
             $userData['password'] = Hash::make(md5($password));
             $userData['role'] = $role;
             $userData['status'] = KACANA_USER_STATUS_ACTIVE;
             $user = $userService->createUser($userData);
             if ($user) {
                 $result['ok'] = 1;
                 $result['data'] = $user;
                 return $result;
             }
         }
     }
 }
예제 #11
0
 public function newPassword(Request $request)
 {
     if (\Auth::check()) {
         return redirect('/');
     }
     $userService = new userService();
     $at = $request->input('at');
     $param = explode('--', base64_decode($at));
     $email = $param[0];
     $password = $param[1];
     $data = array();
     try {
         $check = $userService->checkResetPassword($email, $password);
         if ($check && $request->isMethod('post')) {
             $password = $request->input('password');
             $confirmPassword = $request->input('confirmPassword');
             $result = $userService->accountResetPassword($userService->getUserByEmail($email), $password, $confirmPassword);
             if ($result['ok']) {
                 $data['updated'] = $result['ok'];
             }
         }
         $data['check'] = $check;
     } catch (\Exception $e) {
         if ($request->ajax()) {
             $result['error'] = $e->getMessage();
             return $result;
         } else {
             return view('errors.404', ['error_message' => $e->getMessage()]);
         }
     }
     return view('client.customer.new-password', $data);
 }
예제 #12
0
 public function index(Request $request)
 {
     $cartService = new cartService();
     $addressService = new addressService();
     $userService = new userService();
     $step = $request->get('step', 'login');
     $data = array();
     try {
         $key = '__kacana_user_order__';
         if (\Kacana\Util::isLoggedIn()) {
             $user = $userService->getUserByEmail($this->_user->email);
             if ($step != 'address' && count($user->userAddress)) {
                 $step = 'choose-address';
             } else {
                 $step = 'address';
             }
             \Session::set($key, ['email' => $this->_user->email]);
             $data['user'] = $user;
         }
         $data['step'] = $step;
         $cart = $cartService->cartInformation();
         if (!$cart) {
             return redirect('/thanh-toan');
         }
         $data['cart'] = $cart;
         $key = '__kacana_user_order__';
         $userOrder = \Session::get($key);
         if ($userOrder) {
             $data['userOrder'] = $userOrder;
         }
         if ($step == 'address' && ($request->isMethod('post') || isset($userOrder['email']))) {
             $data['listCity'] = $addressService->getListCity();
             $data['listDistrict'] = $addressService->getListDistrict();
             $data['listWard'] = $addressService->getListWard();
             $email = $request->input('email', false);
             if (isset($userOrder['email']) && !$email) {
                 // if refresh page - will check session userOrder
                 $email = $userOrder['email'];
             }
             $password = $request->input('password', false);
             if ($password && isEmailAdress($email)) {
                 return view('client.checkout.checkout', $data);
             } elseif ($email && isEmailAdress($email)) {
                 if (!isset($userOrder)) {
                     $userOrder = array();
                 }
                 $userOrder['email'] = $email;
                 \Session::set($key, $userOrder);
             } else {
                 $data['errorMessage'] = 'Email không đúng định dạng';
             }
         }
     } catch (\Exception $e) {
         if ($request->ajax()) {
             $result['error'] = $e->getMessage();
             return $result;
         } else {
             return view('errors.404', ['error_message' => $e]);
         }
     }
     return view('client.checkout.checkout', $data);
 }