Example #1
0
<?php

require_once "actions/LoginAction.php";
$action = new LoginAction();
$action->execute();
require_once "header.php";
require_once "menu.php";
?>
    <div class="container col-sm-4">
      <h2>Please authenticate yourself</h2>
      <form class="form-horizontal" role="form" method="POST" action="login.php">
	<div class="form-group">
	  <label for="username" class="col-sm-2 control-label">Username</label>
	  <div class="col-sm-10">
	    <input type="text" name="username" id="username" class="form-control" placeholder="Username"/>
	  </div>
	</div>
	<div class="form-group">
	  <label for="password" class="col-sm-2 control-label">Password</label>
	  <div class="col-sm-10">
	    <input type="password" name="password" id="password" class="form-control" placeholder="Password"/>
	  </div>
	</div>
	<div class="form-group">
	  <div class="col-sm-offset-2 col-sm-10">
	    <button type="submit" class="btn btn-default">Log in</button>
	  </div>
	</div>
      </form>
      <?php 
if ($action->isSignUpOpen()) {
 public function execute($action)
 {
     $forwards = $action->getForwards();
     // Checks if all fields were provided
     if (!empty($_POST['nameNewUser']) && !empty($_POST['emailNewUser']) && !empty($_POST['passwordNewUser']) && !empty($_POST['confirmPasswordNewUser'])) {
         $listUsers = $this->dao->listUsers();
         $cont = 0;
         foreach ($listUsers as $user) {
             if ($user->getEmail() == $_POST['emailNewUser']) {
                 $cont++;
             }
         }
         if ($cont == 0) {
             // Checks if the passwords are corresponding
             if ($_POST['passwordNewUser'] == $_POST['confirmPasswordNewUser']) {
                 // Instantiates a new user;
                 $user = new User();
                 $user->setName($_POST['nameNewUser']);
                 $user->setEmail($_POST['emailNewUser']);
                 $user->setPassword($_POST['passwordNewUser']);
                 $user->setRoomcreator(false);
                 $resultUser = $this->dao->saveNewUser($user);
                 // Once you register, the user is logged into the system
                 $_POST['email'] = $user->getEmail();
                 $_POST['password'] = $user->getPassword();
                 $loginAction = new LoginAction();
                 $loginAction->execute($action);
                 // Showing the page
                 $this->pageController->run($forwards['success']);
             } else {
                 // It will set a variable with the id of the button
                 // that opens the modal window that was active
                 $_SESSION['openModalWindow'] = "#dialogRegister";
                 // Error if the passwords do not match
                 $_REQUEST["errorMsg"] = $this->message->getText("error.incompatiblePasswords");
                 $this->pageController->run($forwards['error']);
             }
         } else {
             // It will set a variable with the id of the button
             // that opens the modal window that was active
             $_SESSION['openModalWindow'] = "#dialogRegister";
             // Error if the passwords do not match
             $_REQUEST["errorMsg"] = $this->message->getText("error.unavailableEmail");
             $this->pageController->run($forwards['error']);
         }
     } else {
         // It will set a variable with the id of the button
         // that opens the modal window that was active
         $_SESSION['openModalWindow'] = "#dialogRegister";
         // Error if there are blank fields
         $_REQUEST["errorMsg"] = $this->message->getText("error.blankField");
         $this->pageController->run($forwards['error']);
     }
 }