/** * Write into base and check data. Also work for additional fields. */ public function add() { if (!empty($_SESSION['user']['id'])) { redirect('/'); } // Обрезаем переменные до длины, указанной в параметре maxlength тега input $fields = array('name', 'password', 'confirm', 'email', 'icq', 'jabber', 'pol', 'city', 'telephone', 'byear', 'bmonth', 'bday', 'url', 'about', 'signature', 'keystring'); $fields_settings = (array) $this->Register['Config']->read('fields', 'users'); $fields_settings = array_merge($fields_settings, array('email', 'login', 'password', 'confirm')); foreach ($fields as $field) { ${$field} = isset($_POST[$field]) ? trim($_POST[$field]) : ''; } if ('1' === $pol) { $pol = 'm'; } else { if ('2' === $pol) { $pol = 'f'; } else { $pol = ''; } } // Обрезаем переменные до длины, указанной в параметре maxlength тега input $name = mb_substr($name, 0, 30); $password = mb_substr($password, 0, 30); $confirm = mb_substr($confirm, 0, 30); $email = mb_substr($email, 0, 60); $icq = mb_substr($icq, 0, 12); $jabber = mb_substr($jabber, 0, 100); $city = mb_substr($city, 0, 50); $telephone = !empty($telephone) ? number_format(mb_substr($telephone, 0, 20), 0, '', '') : ''; $byear = intval(mb_substr($byear, 0, 4)); $bmonth = intval(mb_substr($bmonth, 0, 2)); $bday = intval(mb_substr($bday, 0, 2)); $url = mb_substr($url, 0, 60); $about = mb_substr($about, 0, 1000); $signature = mb_substr($signature, 0, 500); $errors = $this->Register['Validate']->check($this->Register['action']); // Проверяем, заполнены ли обязательные поля // Additional fields checker if (is_object($this->AddFields)) { try { $_addFields = $this->AddFields->checkFields(); } catch (Exception $e) { $errors[] = $this->AddFields->getErrors(); } } // Проверяем поле "код" if (!empty($keystring)) { if (!$this->Register['Protector']->checkCaptcha('reguser', $keystring)) { $errors[] = __('Wrong protection code'); } } $this->Register['Protector']->cleanCaptcha('reguser'); $new_name = preg_replace("#[^- _0-9a-zА-Яа-я]#i", "", $name); // Формируем SQL-запрос $res = $this->Model->getSameNics($new_name); if ($res) { $errors[] = sprintf(__('Name already exists'), $new_name); } /* check avatar */ $tmp_key = rand(0, 9999999); if (!empty($_FILES['avatar']['name'])) { $path = ROOT . '/sys/tmp/images/' . $tmp_key . '.jpg'; if (move_uploaded_file($_FILES['avatar']['tmp_name'], $path)) { chmod($path, 0644); @($sizes = resampleImage($path, $path, 100)); if (!$sizes) { @unlink($path); $errors[] = __('Some error in avatar'); } } } $timezone = (int) $_POST['timezone']; if ($timezone < -12 or $timezone > 12) { $timezone = 0; } // Если были допущены ошибки при заполнении формы - перенаправляем посетителя на страницу регистрации if (!empty($errors)) { $_SESSION['FpsForm'] = array_merge(array('name' => null, 'email' => null, 'timezone' => null, 'icq' => null, 'url' => null, 'about' => null, 'signature' => null, 'pol' => $pol, 'telephone' => null, 'city' => null, 'jabber' => null, 'byear' => null, 'bmonth' => null, 'bday' => null), $_POST); $_SESSION['FpsForm']['errors'] = $errors; redirect('/users/add_form/yes'); } if (!empty($url) and substr($url, 0, 7) != 'http://') { $url = 'http://' . $url; } // Уникальный код для активации учетной записи $email_activate = $this->Register['Config']->read('email_activate'); $code = !empty($email_activate) ? md5(uniqid(rand(), true)) : ''; // Все поля заполнены правильно - продолжаем регистрацию $data = array('name' => $name, 'passw' => md5($password), 'email' => $email, 'timezone' => $timezone, 'url' => $url, 'icq' => $icq, 'jabber' => $jabber, 'city' => $city, 'telephone' => $telephone, 'pol' => $pol, 'byear' => $byear, 'bmonth' => $bmonth, 'bday' => $bday, 'about' => $about, 'signature' => $signature, 'photo' => '', 'puttime' => new Expr('NOW()'), 'last_visit' => new Expr('NOW()'), 'themes' => 0, 'status' => 1, 'activation' => $code); $entity = new UsersEntity($data); $id = $entity->save(); // Additional fields saver if (is_object($this->AddFields)) { $this->AddFields->save($id, $_addFields); } if (file_exists(ROOT . '/sys/tmp/images/' . $tmp_key . '.jpg')) { if (copy(ROOT . '/sys/tmp/images/' . $tmp_key . '.jpg', ROOT . '/sys/avatars/' . $id . '.jpg')) { chmod(ROOT . '/sys/avatars/' . $id . '.jpg', 0644); } unlink(ROOT . '/sys/tmp/images/' . $tmp_key . '.jpg'); } /* clean DB cache */ $this->DB->cleanSqlCache(); cleanAllUsersCount(); // Activate by Email if (!empty($email_activate)) { $entity->setPassw($password); $context = array('activation_link' => 'http://' . $_SERVER['SERVER_NAME'] . '/users/activate/' . $code, 'user' => $entity); $subject = 'Регистрация на форуме ' . $_SERVER['SERVER_NAME']; $mailer = new AtmMail(ROOT . '/sys/settings/email_templates/'); $mailer->prepare('registration'); $mailer->sendMail($email, $subject, $context); if ($this->Log) { $this->Log->write('adding user', 'user id(' . $id . ')'); } $msg = 'На Ваш e-mail выслано письмо с просьбой подтвердить регистрацию. Чтобы завершить регистрацию и активировать учетную запись, зайдите по адресу, указанному в письме.'; } else { // Activate without Email $msg = __('Registration complete'); } $source = $this->render('infomessage.html', array('info_message' => $msg)); return $this->_view($source); }
public function doAction() { $out = ''; $idActiveGroupe = ''; $groupes = $this->doorGets->loadGroupesSubscriber(); $countGroupes = count($groupes); $Params = $this->doorGets->Params(); if (array_key_exists('groupe', $Params['GET'])) { $idActiveGroupe = $Params['GET']['groupe']; } $backUrl = '/'; if ($this->Action !== 'logout') { $backUrl = $_SERVER['REQUEST_URI']; } if (array_key_exists('back', $Params['GET'])) { $backUrl = urldecode($Params['GET']['back']); $_SESSION['backurl'] = $backUrl; } switch ($this->Action) { case 'index': $UserGoogleEntity = null; $isUserGoogle = false; $isEmptyUserGoogle = true; $userId = 0; // Connect Auto with google if (isset($_SESSION['oauth2']) && isset($_SESSION['oauth2']['google'])) { //$LogineExist = $this->doorGets->dbQS($_SESSION['oauth2']['google']) $token = $_SESSION['oauth2']['google']; $UserGoogleQuery = new UserGoogleQuery($this->doorGets); $UserGoogleQuery->filterByAccessToken($token); $UserGoogleQuery->find(); $UserGoogleEntity = $UserGoogleQuery->_getEntity(); if ($UserGoogleEntity) { $isUserGoogle = true; $userId = $UserGoogleEntity->getIdUser(); } } if ($isUserGoogle) { $LogineExist = $this->doorGets->dbQS($userId, '_users'); if (!empty($LogineExist)) { $isUserInfos = $this->doorGets->dbQS($LogineExist['id'], '_users_info', 'id_user'); if (!empty($isUserInfos) && ($isUserInfos['active'] == '2' or $isUserInfos['active'] == '5')) { $this->doorGets->clearFireWallIp(); $_token = md5(uniqid(mt_rand(), true)); $_SESSION['doorgets_user']['id'] = $isUserInfos['id_user']; $_SESSION['doorgets_user']['groupe'] = $isUserInfos['network']; $_SESSION['doorgets_user']['login'] = $LogineExist['login']; $_SESSION['doorgets_user']['password'] = ''; $_SESSION['doorgets_user']['langue'] = $isUserInfos['langue']; $_SESSION['doorgets_user']['token'] = $_token; // Users tracking $this->doorGets->_trackMe($LogineExist['id'], $isUserInfos['network']); $this->doorGets->dbQU($LogineExist['id'], array('token' => $_token), '_users'); FlashInfo::set($this->doorGets->__("Connexion réussie")); if ($isUserInfos['active'] == '5') { $this->doorGets->dbQU($LogineExist['id'], array('active' => '2'), '_users_info'); FlashInfo::set($this->doorGets->__("Connexion réussie") . ', ' . $this->doorGets->__("Votre compte est maintenant ouvert")); } header('Location:' . $backUrl); exit; } } } $UserFacebookEntity = null; $isUserFacebook = false; $isEmptyUserFacebook = true; // Connect Auto with facebook if (isset($_SESSION['oauth2']) && isset($_SESSION['oauth2']['facebook'])) { //$LogineExist = $this->doorGets->dbQS($_SESSION['oauth2']['facebook']) $token = $_SESSION['oauth2']['facebook']; $UserFacebookQuery = new UserFacebookQuery($this->doorGets); $UserFacebookQuery->filterByAccessToken($token); $UserFacebookQuery->find(); $UserFacebookEntity = $UserFacebookQuery->_getEntity(); if ($UserFacebookEntity) { $isUserFacebook = true; $userId = $UserFacebookEntity->getIdUser(); } } if ($isUserFacebook) { $LogineExist = $this->doorGets->dbQS($userId, '_users'); if (!empty($LogineExist)) { $isUserInfos = $this->doorGets->dbQS($LogineExist['id'], '_users_info', 'id_user'); if (!empty($isUserInfos) && ($isUserInfos['active'] == '2' or $isUserInfos['active'] == '5')) { $this->doorGets->clearFireWallIp(); $_token = md5(uniqid(mt_rand(), true)); $_SESSION['doorgets_user']['id'] = $isUserInfos['id_user']; $_SESSION['doorgets_user']['groupe'] = $isUserInfos['network']; $_SESSION['doorgets_user']['login'] = $LogineExist['login']; $_SESSION['doorgets_user']['password'] = ''; $_SESSION['doorgets_user']['langue'] = $isUserInfos['langue']; $_SESSION['doorgets_user']['token'] = $_token; // Users tracking $this->doorGets->_trackMe($LogineExist['id'], $isUserInfos['network']); $this->doorGets->dbQU($LogineExist['id'], array('token' => $_token), '_users'); FlashInfo::set($this->doorGets->__("Connexion réussie")); if ($isUserInfos['active'] == '5') { $this->doorGets->dbQU($LogineExist['id'], array('active' => '2'), '_users_info'); FlashInfo::set($this->doorGets->__("Connexion réussie") . ', ' . $this->doorGets->__("Votre compte est maintenant ouvert")); } header('Location:' . $backUrl); exit; } } } // Normal Auth if (!empty($this->doorGets->Form->i)) { // vérification champ vide foreach ($this->doorGets->Form->i as $k => $v) { if (empty($v)) { $this->doorGets->Form->e['authentification_login'] = '******'; $this->doorGets->Form->e['authentification_password'] = '******'; } } // verification de la taille du password if (strlen($this->doorGets->Form->i['password']) < 4) { $this->doorGets->Form->e['authentification_login'] = '******'; $this->doorGets->Form->e['authentification_password'] = '******'; } if (!empty($this->doorGets->Form->e)) { $this->doorGets->fireWallIp(); } else { $LogineExist = $this->doorGets->dbQS($this->doorGets->Form->i['login'], '_users', 'login'); if (!empty($LogineExist)) { $hasPassword = $this->doorGets->_decryptMe($this->doorGets->Form->i['password'], $LogineExist['salt'], $LogineExist['password']); if ($hasPassword) { $isUserInfos = $this->doorGets->dbQS($LogineExist['id'], '_users_info', 'id_user'); if (!empty($isUserInfos) && ($isUserInfos['active'] == '2' or $isUserInfos['active'] == '5')) { $this->doorGets->clearFireWallIp(); $_token = md5(uniqid(mt_rand(), true)); $_SESSION['doorgets_user']['id'] = $isUserInfos['id_user']; $_SESSION['doorgets_user']['groupe'] = $isUserInfos['network']; $_SESSION['doorgets_user']['login'] = $LogineExist['login']; $_SESSION['doorgets_user']['password'] = $LogineExist['password']; $_SESSION['doorgets_user']['langue'] = $isUserInfos['langue']; $_SESSION['doorgets_user']['token'] = $_token; // Users tracking $this->doorGets->_trackMe($LogineExist['id'], $isUserInfos['network']); $this->doorGets->dbQU($LogineExist['id'], array('token' => $_token), '_users'); FlashInfo::set($this->doorGets->__("Connexion réussie")); if ($isUserInfos['active'] == '5') { $this->doorGets->dbQU($LogineExist['id'], array('active' => '2'), '_users_info'); FlashInfo::set($this->doorGets->__("Connexion réussie") . ', ' . $this->doorGets->__("Votre compte est maintenant ouvert")); } header('Location:' . $backUrl); exit; } else { $this->doorGets->fireWallIp(); } } } else { $this->doorGets->fireWallIp(); } $this->doorGets->Form->e['authentification_login'] = '******'; $this->doorGets->Form->e['authentification_password'] = '******'; } } break; case 'register': $idGroupe = null; $hasVerification = true; $errorMsg = ''; if (empty($idActiveGroupe) && $countGroupes === 1) { foreach ($groupes as $key => $value) { $idGroupe = $groupes[$key]['id']; $hasVerfication = $groupes[$key]['verification']; } } elseif (array_key_exists($idActiveGroupe, $groupes)) { $idGroupe = $groupes[$idActiveGroupe]['id']; $hasVerfication = $groupes[$idActiveGroupe]['verification']; } // Oauth2 google if (!empty($this->doorGets->Form['google']->i) && $countGroupes > 0) { // vérification champ vide foreach ($this->doorGets->Form['google']->i as $k => $v) { if (empty($v)) { $this->doorGets->Form['google']->e['subscribe_google_' . $k] = 'Vide !'; } } // verification du pseudo if (empty($this->doorGets->Form['google']->e['subscribe_login'])) { if (strlen($this->doorGets->Form['google']->i['login']) < 3) { $this->doorGets->Form['google']->e['subscribe_google_login'] = '******'; } if (empty($this->doorGets->Form['google']->e['subscribe_login'])) { $this->doorGets->Form['google']->i['login'] = trim(strtolower($this->doorGets->Form['google']->i['login'])); $login = $this->doorGets->Form['google']->i['login']; $login = str_replace('-', '', $login); $login = str_replace('_', '', $login); $login = ctype_alnum($login); if (empty($login)) { $this->doorGets->Form['google']->e['subscribe_google_login'] = '******'; } $isPseudo = $this->doorGets->dbQS($this->doorGets->Form['google']->i['login'], '_users_info', 'pseudo'); if (!empty($isPseudo)) { $this->doorGets->Form['google']->e['subscribe_google_login'] = '******'; } } } if (isset($_SESSION['oauth2']) && isset($_SESSION['oauth2']['google']) && empty($this->doorGets->Form['google']->e)) { $token = $_SESSION['oauth2']['google']; $UserGoogleQuery = new UserGoogleQuery($this->doorGets); $UserGoogleQuery->filterByAccessToken($token); $UserGoogleQuery->find(); $UserGoogleEntity = $UserGoogleQuery->_getEntity(); $UserGoogle = $UserGoogleEntity->getData(); if ($UserGoogle) { $userId = (int) $UserGoogle['id_user']; if ($userId == 0) { try { $avatar = $this->doorGets->copyGravatar($UserGoogle['email']); $dataLogin['login'] = $UserGoogle['email']; $dataLogin['password'] = $this->doorGets->_crypt(time() + mt_rand(100000, 100000000)); $dataLogin['salt'] = $this->doorGets->_crypt(time() + mt_rand(100000, 100000000)); $dataInfo['langue'] = $this->doorGets->myLanguage; $dataInfo['network'] = $idGroupe; $dataInfo['active'] = '2'; $dataInfo['pseudo'] = $this->doorGets->Form['google']->i['login']; $dataInfo['horaire'] = $this->doorGets->Form['google']->i['horaire']; $dataInfo['email'] = $UserGoogle['email']; $dataInfo['last_name'] = $this->doorGets->Form['google']->i['subscribe_lastname']; $dataInfo['first_name'] = $this->doorGets->Form['google']->i['subscribe_firstname']; $dataInfo['editor_html'] = ''; $dataInfo['notification_mail'] = 1; $dataInfo['notification_newsletter'] = array_key_exists('registerNewsletter', $this->doorGets->Form['google']->i) ? 1 : 0; $dataInfo['date_creation'] = time(); $dataInfo['avatar'] = $avatar; $UsersLog = new UsersEntity(); $UsersLog->setData($dataLogin); $UsersLog->save(false); $dataInfo['id_user'] = $UsersLog->getId(); $UsersInfo = new UsersInfoEntity(); $UsersInfo->setData($dataInfo); $UsersInfo->save(false); $UserGoogleEntity->setIdUser($dataInfo['id_user']); $UserGoogleEntity->save(false); } catch (PDOException $e) { new PrintErrorException($e); exit; } catch (Exception $e) { echo $e->getMessage(); exit; } $this->doorGets->createFolderUser($dataInfo['pseudo'], $dataInfo['id_user']); FlashInfo::set($this->doorGets->__("Connexion réussie") . ', ' . $this->doorGets->__("Votre compte est maintenant ouvert")); header('Location:./?controller=authentification'); exit; } } } } // Oauth2 facebook if (!empty($this->doorGets->Form['facebook']->i) && $countGroupes > 0) { // vérification champ vide foreach ($this->doorGets->Form['facebook']->i as $k => $v) { if (empty($v)) { $this->doorGets->Form['facebook']->e['subscribe_facebook_' . $k] = 'Vide !'; } } // verification du pseudo if (empty($this->doorGets->Form['facebook']->e['subscribe_login'])) { if (strlen($this->doorGets->Form['facebook']->i['login']) < 3) { $this->doorGets->Form['facebook']->e['subscribe_facebook_login'] = '******'; } if (empty($this->doorGets->Form['facebook']->e['subscribe_login'])) { $this->doorGets->Form['facebook']->i['login'] = trim(strtolower($this->doorGets->Form['facebook']->i['login'])); $login = $this->doorGets->Form['facebook']->i['login']; $login = str_replace('-', '', $login); $login = str_replace('_', '', $login); $login = ctype_alnum($login); if (empty($login)) { $this->doorGets->Form['facebook']->e['subscribe_facebook_login'] = '******'; } $isPseudo = $this->doorGets->dbQS($this->doorGets->Form['facebook']->i['login'], '_users_info', 'pseudo'); if (!empty($isPseudo)) { $this->doorGets->Form['facebook']->e['subscribe_facebook_login'] = '******'; } } } if (isset($_SESSION['oauth2']) && isset($_SESSION['oauth2']['facebook']) && empty($this->doorGets->Form['facebook']->e)) { $token = $_SESSION['oauth2']['facebook']; $UserFacebookQuery = new UserFacebookQuery($this->doorGets); $UserFacebookQuery->filterByAccessToken($token); $UserFacebookQuery->find(); $UserFacebookEntity = $UserFacebookQuery->_getEntity(); $UserFacebook = $UserFacebookEntity->getData(); if ($UserFacebook) { $userId = (int) $UserFacebook['id_user']; if ($userId == 0) { $avatar = $this->doorGets->copyGravatar($UserFacebook['email']); $dataLogin['login'] = $UserFacebook['email']; $dataLogin['salt'] = $this->doorGets->_crypt(time() + mt_rand(100000, 100000000)); $dataLogin['password'] = $this->doorGets->_crypt(time() + mt_rand(100000, 100000000)); $dataInfo['langue'] = $this->doorGets->myLanguage; $dataInfo['network'] = $idGroupe; $dataInfo['active'] = '2'; $dataInfo['horaire'] = $this->doorGets->Form['facebook']->i['horaire']; $dataInfo['pseudo'] = $this->doorGets->Form['facebook']->i['login']; $dataInfo['email'] = $UserFacebook['email']; $dataInfo['last_name'] = $this->doorGets->Form['facebook']->i['subscribe_lastname']; $dataInfo['first_name'] = $this->doorGets->Form['facebook']->i['subscribe_firstname']; $dataInfo['editor_html'] = ''; $dataInfo['notification_mail'] = 1; $dataInfo['notification_newsletter'] = array_key_exists('registerNewsletter', $this->doorGets->Form['facebook']->i) ? 1 : 0; $dataInfo['date_creation'] = time(); $dataInfo['avatar'] = $avatar; $UsersLog = new UsersEntity(); $UsersLog->setData($dataLogin); $UsersLog->save(false); $dataInfo['id_user'] = $UsersLog->getId(); $UsersInfo = new UsersInfoEntity(); $UsersInfo->setData($dataInfo); $UsersInfo->save(false); $UserFacebookEntity->setIdUser($dataInfo['id_user']); $UserFacebookEntity->save(false); $this->doorGets->createFolderUser($dataInfo['pseudo'], $dataInfo['id_user']); FlashInfo::set($this->doorGets->__("Connexion réussie") . ', ' . $this->doorGets->__("Votre compte est maintenant ouvert")); header('Location:./?controller=authentification'); exit; } } } } // doorGets Auth if (!empty($this->doorGets->Form['doorgets']->i) && $countGroupes > 0) { // vérification champ vide foreach ($this->doorGets->Form['doorgets']->i as $k => $v) { if (empty($v)) { $this->doorGets->Form['doorgets']->e['subscribe_' . $k] = 'Vide !'; } } // verification adresse email if (empty($this->doorGets->Form['doorgets']->e['subscribe_email'])) { // verification du format mail $email = filter_var($this->doorGets->Form['doorgets']->i['email'], FILTER_VALIDATE_EMAIL); if (empty($email)) { $this->doorGets->Form['doorgets']->e['subscribe_email'] = 'Format email invalid'; } // verification de l'existance de l'adresse email if (empty($this->doorGets->Form['doorgets']->e['subscribe_email'])) { $isEmail = $this->doorGets->dbQS($this->doorGets->Form['doorgets']->i['email'], '_users_info', 'email'); $isEmailLogin = $this->doorGets->dbQS($this->doorGets->Form['doorgets']->i['email'], '_users', 'login'); if (!empty($isEmail) || !empty($isEmailLogin)) { $this->doorGets->Form['doorgets']->e['subscribe_email'] = 'Email deja ulisise'; } } } // verification du pseudo if (empty($this->doorGets->Form['doorgets']->e['subscribe_login'])) { if (strlen($this->doorGets->Form['doorgets']->i['login']) < 3) { $this->doorGets->Form['doorgets']->e['subscribe_login'] = '******'; } if (empty($this->doorGets->Form['doorgets']->e['subscribe_login'])) { $this->doorGets->Form['doorgets']->i['login'] = trim(strtolower($this->doorGets->Form['doorgets']->i['login'])); $login = $this->doorGets->Form['doorgets']->i['login']; $login = str_replace('-', '', $login); $login = str_replace('_', '', $login); $login = ctype_alnum($login); if (empty($login)) { $this->doorGets->Form['doorgets']->e['subscribe_login'] = '******'; } $isPseudo = $this->doorGets->dbQS($this->doorGets->Form['doorgets']->i['login'], '_users_info', 'pseudo'); if (!empty($isPseudo)) { $this->doorGets->Form['doorgets']->e['subscribe_login'] = '******'; } } } // verification du mot de passe if (empty($this->doorGets->Form['doorgets']->e['subscribe_password'])) { if (strlen($this->doorGets->Form['doorgets']->i['password']) < 8) { $this->doorGets->Form['doorgets']->e['subscribe_password'] = '******'; $this->doorGets->Form['doorgets']->e['subscribe_re-password'] = '******'; } if (empty($this->doorGets->Form['doorgets']->e['subscribe_password'])) { if ($this->doorGets->Form['doorgets']->i['password'] !== $this->doorGets->Form['doorgets']->i['re-password']) { $this->doorGets->Form['doorgets']->e['subscribe_password'] = '******'; $this->doorGets->Form['doorgets']->e['subscribe_re-password'] = '******'; } } } if (empty($this->doorGets->Form['doorgets']->e) && $countGroupes > 0) { if ($idGroupe) { $avatar = $this->doorGets->copyGravatar($this->doorGets->Form['doorgets']->i['email']); $crypto = $this->doorGets->_cryptMe($this->doorGets->Form['doorgets']->i['password']); $dataLogin['login'] = $this->doorGets->Form['doorgets']->i['email']; $dataLogin['password'] = $crypto['password']; $dataLogin['salt'] = $crypto['salt']; $dataInfo['langue'] = $this->doorGets->myLanguage; $dataInfo['network'] = $idGroupe; $dataInfo['active'] = $hasVerfication ? '3' : '2'; // moderation mode $dataInfo['horaire'] = $this->doorGets->Form['doorgets']->i['horaire']; $dataInfo['pseudo'] = $this->doorGets->Form['doorgets']->i['login']; $dataInfo['email'] = $this->doorGets->Form['doorgets']->i['email']; $dataInfo['last_name'] = $this->doorGets->Form['doorgets']->i['lastname']; $dataInfo['first_name'] = $this->doorGets->Form['doorgets']->i['firstname']; $dataInfo['editor_html'] = ''; $dataInfo['notification_mail'] = 1; $dataInfo['notification_newsletter'] = array_key_exists('registerNewsletter', $this->doorGets->Form['doorgets']->i) ? 1 : 0; $dataInfo['date_creation'] = time(); $dataInfo['avatar'] = $avatar; $UsersLog = new UsersEntity(); $UsersLog->setData($dataLogin); $UsersLog->save(false); $dataInfo['id_user'] = $UsersLog->getId(); $UsersInfo = new UsersInfoEntity(); $UsersInfo->setData($dataInfo); $UsersInfo->save(false); // create activation code if ($hasVerfication) { $dataCode['type'] = 'subscribe'; $dataCode['id_user'] = $dataInfo['id_user']; $dataCode['code'] = $this->doorGets->_genRandomKey(45); $dataCode['date_creation'] = time(); $UsersActivation = new UsersActivationEntity(); $UsersActivation->setData($dataCode); $UsersActivation->save(false); $this->doorGets->createFolderUser($dataInfo['pseudo'], $dataInfo['id_user']); $lgUser = ''; if (count($this->doorGets->allLanguagesWebsite) > 1) { $lgUser = $this->doorGets->myLanguage . '/'; } $urlToSend = URL_USER . $lgUser . '?controller=authentification&action=activation&code=' . $dataCode['code']; // send mail with code confirmation new SendMailAuth($dataInfo['email'], 'subscribe', $urlToSend, $this->doorGets); } else { // Connect user $_token = md5(uniqid(mt_rand(), true)); $_SESSION['doorgets_user']['id'] = $dataInfo['id_user']; $_SESSION['doorgets_user']['groupe'] = $dataInfo['network']; $_SESSION['doorgets_user']['login'] = $dataLogin['login']; $_SESSION['doorgets_user']['password'] = $dataLogin['password']; $_SESSION['doorgets_user']['langue'] = $dataInfo['langue']; $_SESSION['doorgets_user']['token'] = $_token; $this->doorGets->createFolderUser($dataInfo['pseudo'], $dataInfo['id_user']); $this->doorGets->dbQU($dataInfo['id_user'], array('token' => $_token), '_users'); FlashInfo::set($this->doorGets->__("Connexion réussie")); header('Location:' . $backUrl); exit; } $this->doorGets->Form['doorgets']->isSended = true; } } FlashInfo::set($errorMsg, "error"); } break; case 'reset': if (!empty($this->doorGets->Form->i)) { $this->doorGets->Form = $this->doorGets->Form; $timer = 60 * 60 * 2; // 2 Hours $isOkForActivation = false; $Params = $this->doorGets->Params(); if (array_key_exists('code', $Params['GET']) && !empty($Params['GET']['code'])) { $isActivation = $this->doorGets->dbQS($Params['GET']['code'], '_users_activation', 'code', " AND type = 'forget' LIMIT 1 "); if (!empty($isActivation)) { $timeCreated = (int) $isActivation['date_creation']; $timeLeft = time() - $timeCreated; if ($timer > $timeLeft) { $isOkForActivation = true; } } } if ($isOkForActivation) { // vérification champ vide foreach ($this->doorGets->Form->i as $k => $v) { if (empty($v)) { $this->doorGets->Form->e['reset_' . $k] = 'Vide !'; } } // verification adresse email if (empty($this->doorGets->Form->e['reset_email'])) { // verification du format mail $email = filter_var($this->doorGets->Form->i['email'], FILTER_VALIDATE_EMAIL); if (empty($email)) { $this->doorGets->Form->e['reset_email'] = 'Format email invalid'; } // verification de l'existance de l'adresse email if (empty($this->doorGets->Form->e['subscribe_email'])) { $isEmailLogin = $this->doorGets->dbQS($this->doorGets->Form->i['email'], '_users', 'login'); if (empty($isEmailLogin) || !empty($isEmailLogin) && $isActivation['id_user'] !== $isEmailLogin['id']) { $this->doorGets->Form->e['reset_email'] = 'Email deja ulisise'; } } } // verification du mot de passe if (empty($this->doorGets->Form->e['reset_password'])) { if (strlen($this->doorGets->Form->i['password']) < 8) { $this->doorGets->Form->e['reset_password'] = '******'; $this->doorGets->Form->e['reset_re-password'] = '******'; } if (empty($this->doorGets->Form->e['reset_password'])) { if ($this->doorGets->Form->i['password'] !== $this->doorGets->Form->i['re-password']) { $this->doorGets->Form->e['reset_password'] = '******'; $this->doorGets->Form->e['reset_re-password'] = '******'; } } } if (empty($this->doorGets->Form->e)) { $crypto = $this->doorGets->_cryptMe($this->doorGets->Form->i['password']); $dataReset['salt'] = $crypto['salt']; $dataReset['password'] = $crypto['password']; $this->doorGets->dbQU($isActivation['id_user'], $dataReset, '_users'); $this->doorGets->Form->isSended = true; } } } break; case 'forget': if (!empty($this->doorGets->Form->i)) { $idGroupe = '1'; $isValid = false; $this->doorGets->Form = $this->doorGets->Form; $email = filter_var($this->doorGets->Form->i['email'], FILTER_VALIDATE_EMAIL); if ($email) { $isEmail = $this->doorGets->dbQS($email, '_users', 'login'); if (!empty($isEmail)) { // Delete last code $this->doorGets->dbQL("DELETE FROM _users_activation WHERE id_user = '******'id'] . "' AND type = 'forget'"); $dataCode['type'] = 'forget'; $dataCode['id_user'] = $isEmail['id']; $dataCode['code'] = $this->doorGets->_genRandomKey(45); $dataCode['date_creation'] = time(); $this->doorGets->dbQI($dataCode, '_users_activation'); $lgUser = ''; if (count($this->doorGets->allLanguagesWebsite) > 1) { $lgUser = $this->doorGets->myLanguage . '/'; } $urlToSend = URL_USER . $lgUser . '?controller=authentification&action=reset&code=' . $dataCode['code']; // send mail with code confirmation new SendMailAuth($isEmail['login'], 'forget', $urlToSend, $this->doorGets); $this->doorGets->Form->isSended = true; } } if (!$isValid) { $this->doorGets->Form->e['forget_email'] = 'ok'; } } break; case 'logout': if (array_key_exists('cart', $_SESSION)) { $cart = $_SESSION['cart']; $_SESSION = array(); $_SESSION['cart'] = $cart; } else { $_SESSION = array(); } header('Location:' . $backUrl); exit; break; } return $out; }