Advertisement
Guest User

Untitled

a guest
May 17th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.38 KB | None | 0 0
  1. <?php
  2.  
  3. class InvalidLoginException extends Exception {}
  4.  
  5. $action = false;
  6. $lusername = false;
  7. $lpassword = false;
  8. $rusername = false;
  9. $rpassword = false;
  10. $confirm = false;
  11. $name = false;
  12. $city = false;
  13. $subscribe = false;
  14. $errors = array();
  15.  
  16. if (!empty($_POST) && is_array($_POST)) {
  17.     if (isset($_POST['action']) && $_POST['action'] == 'login') {
  18.         $action = 'login';
  19.  
  20.         $lusername = strtolower(trim($_POST['lusername']));
  21.         if (!$lusername) {
  22.             $errors['lusername'] = 'Имя пользователя не может быть пустым';
  23.         }
  24.  
  25.         $lpassword = strtolower(trim($_POST['lpassword']));
  26.         if (!$lpassword) {
  27.             $errors['lpassword'] = 'Пароль не может быть пустым';
  28.         }
  29.  
  30.         if (!count($errors)) {
  31.             try {
  32.                 try {
  33.                     $login_service->login($auth, array(
  34.                         'username' => $lusername,
  35.                         'password' => $lpassword
  36.                     ));
  37.                     $userdata = $auth->getUserData();
  38.                 } catch (\Aura\Auth\Exception\UsernameMissing $e) {
  39.                     // $log->notice("The 'username' field is missing or empty.");
  40.                     throw new InvalidLoginException();
  41.                 } catch (\Aura\Auth\Exception\PasswordMissing $e) {
  42.                     // $log->notice("The 'password' field is missing or empty.");
  43.                     throw new InvalidLoginException();
  44.                 } catch (\Aura\Auth\Exception\UsernameNotFound $e) {
  45.                     // $log->warning("The username you entered was not found.");
  46.                     throw new InvalidLoginException();
  47.                 } catch (\Aura\Auth\Exception\MultipleMatches $e) {
  48.                     // $log->warning("There is more than one account with that username.");
  49.                     throw new InvalidLoginException();
  50.                 } catch (\Aura\Auth\Exception\PasswordIncorrect $e) {
  51.                     // $log->notice("The password you entered was incorrect.");
  52.                     throw new InvalidLoginException();
  53.                 } catch (\Aura\Auth\Exception\ConnectionFailed $e) {
  54.                     // $log->notice("Cound not connect to IMAP or LDAP server.");
  55.                     // $log->info("This could be because the username or password was wrong,");
  56.                     // $log->info("or because the the connect operation itself failed in some way. ");
  57.                     // $log->info($e->getMessage());
  58.                     throw new InvalidLoginException();
  59.                 } catch (\Aura\Auth\Exception\BindFailed $e) {
  60.                     // $log->notice("Cound not bind to LDAP server.");
  61.                     // $log->info("This could be because the username or password was wrong,");
  62.                     // $log->info("or because the the bind operation itself failed in some way. ");
  63.                     // $log->info($e->getMessage());
  64.                     throw new InvalidLoginException();
  65.                 }
  66.             } catch (InvalidLoginException $e) {
  67.                 $errors['invalid'] = "Введены неверные данные. Попробуйте еще раз.";
  68.             }
  69.         }
  70.     } elseif (isset($_POST['action']) && $_POST['action'] == 'register') {
  71.         $action = 'register';
  72.  
  73.         $rusername = strtolower(trim($_POST['rusername']));
  74.         if (!$rusername) {
  75.             $errors['rusername'] = 'Имя пользователя не может быть пустым';
  76.         }
  77.  
  78.         $rpassword = trim($_POST['rpassword']);
  79.         $confirm = trim($_POST['confirm']);
  80.         if (!$rpassword) {
  81.             $errors['rpassword'] = 'Пароль не может быть пустым';
  82.         }
  83.         if ($rpassword !== $confirm) {
  84.             $errors['confirm'] = 'Пароль и потверждение пароля не совпадают';
  85.         }
  86.  
  87.         $name = strtolower(trim($_POST['name']));
  88.         if (!$name) {
  89.             $errors['name'] = 'Имя не может быть пустым';
  90.         }
  91.  
  92.         $city = strtolower(trim($_POST['city']));
  93.         if (!$city) {
  94.             $errors['city'] = 'Город не может быть пустым';
  95.         }
  96.  
  97.         $subscribe = (int)$_POST['subscribe'];
  98.  
  99.         if (!count($errors)) {
  100.  
  101.         }
  102.     }
  103. }
  104.  
  105. include_once ($view_path . "user_auth.php");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement