/** * @param Request $request * @return \BladeView|bool|\Illuminate\Http\RedirectResponse|\Illuminate\View\View|\Symfony\Component\HttpFoundation\Response */ public function signup(Request $request) { $authService = new authService(); $emailService = new mailService(); $name = $request->input('name', ''); $email = $request->input('email', ''); $phone = $request->input('phone', ''); $password = $request->input('password', ''); $confirmPassword = $request->input('confirmPassword', ''); $postAjax = $request->ajax(); $host = explode('.', $request->getHttpHost()); $roleLink = $host[0]; try { if ($request->isMethod('post')) { $results = $authService->signup($name, $email, $phone, $password, $confirmPassword); if ($results['ok']) { $user = $results['data']; if ($roleLink != KACANA_AUTH_ADMIN_NAME) { \Auth::loginUsingId($user->id, true); } $emailService->sendEmailNewUser($email); } if ($postAjax) { return response()->json($results); } else { if ($results['ok']) { return redirect()->intended('/'); } else { return view('auth.signup', $results); } } } } catch (\Exception $e) { // @codeCoverageIgnoreStart $return['error'] = $e->getMessage(); // @codeCoverageIgnoreEnd } return view('auth.signup'); }
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; }
/** * @param $email * @return bool|mixed * @throws \Exception */ public function forgotPassword($email) { $userModel = new User(); $emailService = new mailService(); if (!Validator::make(['email' => $email], ['email' => 'required|email'])) { throw new \Exception('Email is not format'); } $user = $this->getUserByEmail($email); $data = array(); $data['temp_password'] = md5($user->password . time()); $data['temp_password_expire'] = date('Y-m-d H:i:s', strtotime('+1 day')); // expire 1 day $user = $userModel->updateItem($user->id, $data); if ($user) { $emailService->sendEmailForgotPassword($email); return $user; } return false; }