Beispiel #1
0
 /**
  * @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');
 }
Beispiel #2
0
 /**
  * @param $profiles
  * @param $accessToken
  * @return mixed
  */
 public function createUserFromGoogleProfile($profiles, $accessToken)
 {
     $userService = new userService();
     $emailService = new mailService();
     $result['ok'] = 0;
     if (!$profiles) {
         $result['error_code'] = KACANA_AUTH_SIGNUP_BAD_GOOGLE_PROFILE;
         $result['error_message'] = 'google profile is empty';
         return $result;
     }
     if (!$profiles->email) {
         $result['error_code'] = KACANA_AUTH_SIGNUP_BAD_GOOGLE_EMAIL;
         $result['error_message'] = 'google email is empty';
         return $result;
     }
     if (!isset($profiles->name)) {
         $result['error_code'] = KACANA_AUTH_SIGNUP_BAD_GOOGLE_NAME;
         $result['error_message'] = 'google first name is empty';
         return $result;
     }
     if (!isset($profiles->phone)) {
         $profiles->phone = '';
     }
     $data = array('password' => Hash::make(md5(time())), 'email' => $profiles->email, 'name' => $profiles->name, 'role' => KACANA_USER_ROLE_BUYER, 'status' => KACANA_USER_STATUS_ACTIVE, 'phone' => $profiles->phone, 'image' => $profiles->picture);
     $user = $this->getUserByEmail($profiles['email']);
     if ($user) {
         $user = $this->updateItem($user->id, ['status' => KACANA_USER_STATUS_ACTIVE, 'image' => $data['image']]);
     } else {
         $user = $this->createUser($data);
         $emailService->sendEmailNewUser($profiles->email);
     }
     $userSocial = $this->_userSocial->getItem($user->id, KACANA_SOCIAL_TYPE_GOOGLE);
     if ($userSocial) {
         $userSocial = $this->_userSocial->updateItem($user->id, KACANA_SOCIAL_TYPE_GOOGLE, ['token' => $accessToken]);
     } else {
         $userSocial = $this->_userSocial->createItem($user->id, KACANA_SOCIAL_TYPE_GOOGLE, $accessToken, $profiles->id);
     }
     if (Auth::loginUsingId($user->id, true)) {
         $result['ok'] = 1;
         $result['user'] = $user;
         $result['userSocial'] = $userSocial;
     } else {
         $result['error_code'] = KACANA_AUTH_LOGIN_FAILED;
         $result['error_message'] = 'login failed';
     }
     return $result;
 }