Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include_once('class_user.php');
- $userObject = new user();
- if(!$userObject->checkLogin()){
- include_once('class_inputValidation.php');
- if(isset($_POST['userName']) && isset($_POST['userPassword'])){
- $validate = new inputValidation();
- $rules = array(
- 'userName' => array('type' => 'text', 'name' => 'Username', 'required' => true,
- 'trim' => true, 'min' => '3', 'max' => '30' ),
- 'userPassword' => array('type' => 'text', 'name' => 'Password', 'required' => true,
- 'trim' => true, 'min' => '3', 'max' => '30' )
- );
- $validate->addUserInput($_POST);
- $validate->addValidationRules($rules);
- $validate->startValidation();
- }
- if(!isset($_POST['userName']) && !isset($_POST['userPassword']) ||
- !empty($validate->inputErrors)){
- ?>
- <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
- <p>User Name:
- <input type="text" name="userName" size="10"
- value="<?php echo $validate->inputValidated['userName']; ?>">
- <span class="error">* <?php echo $validate->inputErrors['userName']; ?></span></p>
- <p>Password:
- <input type="password" name="userPassword" size="10"
- value="<?php echo $validate->inputValidated['userPassword']; ?>">
- <span class="error">* <?php echo $validate->inputErrors['userPassword']; ?></span></p>
- <input type="submit" value="Login">
- </form>
- <?php
- }
- else{
- include_once('class_sqlGenerator.php');
- include_once('class_PDOConfig.php');
- $userObject->userName = $validate->inputValidated['userName'];
- $userObject->userPassword = $validate->inputValidated['userPassword'];
- $userObject->userEmail = $validate->inputValidated['userEmail'];
- $db = new PDOV('localhost', 'OOP', 'yoyo', 'OOP');
- $dbQuery = new sqlGenerator();
- $dbQuery->table = "`usersExample`";
- $data = array(
- '`userName`' => array(),
- '`userPassword`' => array(),
- '`userEmail`' => array(),
- '`userID`' => array());
- $queryType = array('sqlQuery' => array('type' => 'SELECT',
- 'whereCol' => '`userName`',
- 'whereVal' => $validate->inputValidated['userName']));
- $sql = $dbQuery->sqlGeneratorStart($data, $queryType);
- $stmt = $db->preparedQuery($sql);
- $dbObject = $stmt->fetchObjs('User');
- try{$userObject->verifyCredentials($dbObject);}
- catch(Exception $e){ echo "Error: " .$e->getMessage; }
- if($userObject->checkLogin()){
- echo "Welcome " .$userObject->userName. ", you are now logged in!";
- }
- }
- }
- else{
- echo "Hello Again!";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement