public function register() { try { $errors = array(); $success = false; $isPost = $this->request->isPost(); $user = new User(); try { $fb_active = API_Facebook::isActive(); if ($fb_active) { $fb_user = $user->getFacebookUser(ROOT_HTTP . 'register'); if (!empty($fb_user)) { $this->response->redirect(ROOT_HTTP); } } } catch (Exception $e) { $errors['authent'] = $e->getMessage(); } $confirm_email = $this->request->post('confirm_email', ''); $confirm_password = $this->request->post('confirm_password', ''); if ($isPost) { foreach ($user->getFields() as $key => $value) { try { $user->{$key} = $this->request->post($key, ''); } catch (Exception $e) { $errors[$key] = $e->getMessage(); } } if (empty($confirm_email) || strcmp($user->email, $confirm_email) !== 0) { $errors['confirm_email'] = Lang::_('You must confirm your email'); } if (empty($confirm_password) || strcmp($user->password, $confirm_password) !== 0) { $errors['confirm_password'] = Lang::_('You must confirm your password'); } if (empty($errors)) { $user_already_exists = $user->checkAlreadyExists(); if ($user_already_exists === true) { $errors['email'] = Lang::_('Email already in use'); } else { $user->password = password_hash($user->password, PASSWORD_BCRYPT); $user_id = $user->register(); if (!empty($user_id)) { $success = $user->login(); } else { $errors['authent'] = Lang::_('Register failed'); } } } } $form = $user->getRegisterForm('insert', ROOT_HTTP . $this->lang->getUserLang() . '/user/register', $this->request, $isPost, $errors); $vars = array('title' => Lang::_('Register'), 'isPost' => $isPost, 'form' => $form, 'errors' => $errors, 'success' => $success); } catch (Exception $e) { $vars['debug'] = $e->getMessage(); } return $this->render('authent', $vars); }
public function getFacebookUser($register_url) { $fb_user = API_Facebook::getUser($register_url); if (empty($fb_user) || !is_object($fb_user)) { return false; } foreach ($this->getFields() as $key => $value) { if (property_exists($fb_user, $key)) { $this->{$key} = $fb_user->{$key}; } } // @FIXME $this->password = password_hash($this->fb_id . '-' . $this->email, PASSWORD_BCRYPT); $fb_user = Db::selectOne('SELECT * FROM user WHERE fb_id = :fb_id', array('fb_id' => $this->fb_id)); if (!empty($fb_user)) { $user = new User($fb_user); return $user->login(); } $this->id = $this->facebookRegister(); if (!empty($this->id)) { return $this->login(); } }