Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private function insertUserDetails($uname, $fname, $lname, $eml, $passwd) {
- $encryptedPasswd = md5($passwd);
- $profilePic = "assets/img/profile-pics/profile_pic.pgn";
- $date = date("Y-m-d");
- $result = mysqli_query($this->connect, "INSERT INTO users VALUES('', '$uname', '$fname', '$lname', '$eml', '$encryptedPasswd', '$date', '$profilePic')");
- return $result;
- }
- public function register($uname, $fname, $lname, $eml, $cemail, $passwd, $cpasswd) {
- $this->validateUsername($uname);
- $this->validateFirstname($fname);
- $this->validateLastname($lname);
- $this->validateEmail($eml, $cemail);
- $this->validatePasswords($passwd, $cpasswd);
- if(empty($this->errorArray) == true) {// Check if array contain errors, if not insert data into db
- return insertUserDetails($uname, $fname, $lname, $eml, $passwd);
- }
- else {
- return false;
- }
- }
- class Account {
- private $connect; //sql connect
- private $errorArray; // Array to contain error messages
- public function __construct($connect) {
- $this->connect = $connect;
- $this->errorArray = array();
- }
- // VALIDATION FUNCTIONS, these functions are used to validate user input, things like password, email match
- public function register($uname, $fname, $lname, $eml, $cemail, $passwd, $cpasswd) {
- $this->validateUsername($uname);
- $this->validateFirstname($fname);
- $this->validateLastname($lname);
- $this->validateEmail($eml, $cemail);
- $this->validatePasswords($passwd, $cpasswd);
- if(empty($this->errorArray) == true) {// Check if array contain errors, if not insert data into db
- return insertUserDetails($uname, $fname, $lname, $eml, $passwd);
- }
- else {
- return false;
- }
- }
- if(isset($_POST['register-button'])){
- //Get user info
- $username = sanitizeFormUsername($_POST['username']);
- $firstname = sanitizeFormString($_POST['firstname']);
- $lastname = sanitizeFormString($_POST['lastname']);
- $email = sanitizeFormString($_POST['email']);
- $confirmEmail = sanitizeFormString($_POST['confirmEmail']);
- $password = sanitizeFormPassword($_POST['password']);
- $confirmPassword = sanitizeFormPassword($_POST['confirmPassword']);
- //$wasSuccessful hold the result(value) of the function call (register);
- $wasSuccessful = $account->register($username, $firstname, $lastname, $email, $confirmEmail, $password, $confirmPassword);
- if($wasSuccessful == true) {
- header("Location: index.php"); //redirect user to index.php if successful.
- }
- <!doctype html>
- <?php
- include("includes/config.php");
- include("includes/classes/Account.inc.php");
- include("includes/classes/Constants.inc.php");
- $account = new Account($connect);
- include("includes/handlers/register-handler.php");
- include("includes/handlers/login-handler.php");
- function getInputValue($name) {
- if(isset($_POST[$name])) {
- echo $_POST[$name];
- }
- }
Add Comment
Please, Sign In to add comment