function login($email, $password) { // check username and password with db // if yes, return true // else throw exception // connect to db $dbInfo = initialize_db_info(); $dbLink = db_connect($dbInfo); db_select($dbLink, $dbInfo); $sql = generateUserVerificationSql($email, $password); // check if username is unique $result = mysql_query($sql, $dbLink); if (!$result || mysql_num_rows($result) == 0) { // The username and password did not match. // Check to see if the user exists. if (findUsername($email)) { } else { } } if (mysql_num_rows($result) > 0) { $row = mysql_fetch_assoc($result); $currentUser = new user_info(); $currentUser->setId($row['id']); $currentUser->setFirstName($row['first_name']); $currentUser->setLastName($row['last_name']); $currentUser->setEmail($row['email']); $currentUser->setHunterId($row['hunter_id']); $currentUser->setLoggedIn(true); $_SESSION['current_user'] = $currentUser; $_SESSION['roles'] = getRoles($currentUser); return $currentUser; } else { throw new Exception('no user found 2'); } }
function createUserFromRow($dbRow) { $rowUser = new user_info(); $rowUser->setId($dbRow['id']); $rowUser->setFirstName($dbRow['first_name']); $rowUser->setLastName($dbRow['last_name']); $rowUser->setEmail($dbRow['email']); $rowUser->setHunterId($dbRow['hunter_id']); return $rowUser; }
// // email address not valid // if (!valid_email($email)) { // throw new Exception('That is not a valid email address. Please go back and try again.'); // } // // // passwords not the same // if ($password1 != $password2) { // throw new Exception('The passwords you entered do not match - please go back and try again.'); // } // // // Check password length is ok // // Ok if username truncates, but passwords will get // // Munged if they are too long. // if ((strlen($password1) < 6) || (strlen($password1) > 16)) { // throw new Exception('Your password must be between 6 and 16 characters Please go back and try again.'); // } // Attempt to register // This function can also throw an exception register($email, $password1, $firstName, $lastName); $currentUser = new user_info(); $currentUser->setFirstName($firstName); $currentUser->setLastName($lastName); $currentUser->setEmail($email); sendNewUserNotification($currentUser); // Register session variable $_SESSION['current_user'] = $currentUser; header("Location: /index.php"); } catch (Exception $e) { echo $e->getMessage(); } }