Guest User

Untitled

a guest
May 26th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. private function insertUserDetails($uname, $fname, $lname, $eml, $passwd) {
  2.  
  3. $encryptedPasswd = md5($passwd);
  4. $profilePic = "assets/img/profile-pics/profile_pic.pgn";
  5. $date = date("Y-m-d");
  6.  
  7. $result = mysqli_query($this->connect, "INSERT INTO users VALUES('', '$uname', '$fname', '$lname', '$eml', '$encryptedPasswd', '$date', '$profilePic')");
  8.  
  9. return $result;
  10. }
  11.  
  12. public function register($uname, $fname, $lname, $eml, $cemail, $passwd, $cpasswd) {
  13.  
  14. $this->validateUsername($uname);
  15. $this->validateFirstname($fname);
  16. $this->validateLastname($lname);
  17. $this->validateEmail($eml, $cemail);
  18. $this->validatePasswords($passwd, $cpasswd);
  19.  
  20. if(empty($this->errorArray) == true) {// Check if array contain errors, if not insert data into db
  21. return insertUserDetails($uname, $fname, $lname, $eml, $passwd);
  22. }
  23. else {
  24. return false;
  25. }
  26. }
  27.  
  28. class Account {
  29.  
  30. private $connect; //sql connect
  31. private $errorArray; // Array to contain error messages
  32.  
  33. public function __construct($connect) {
  34.  
  35. $this->connect = $connect;
  36. $this->errorArray = array();
  37.  
  38. }
  39.  
  40. // VALIDATION FUNCTIONS, these functions are used to validate user input, things like password, email match
  41. public function register($uname, $fname, $lname, $eml, $cemail, $passwd, $cpasswd) {
  42.  
  43. $this->validateUsername($uname);
  44. $this->validateFirstname($fname);
  45. $this->validateLastname($lname);
  46. $this->validateEmail($eml, $cemail);
  47. $this->validatePasswords($passwd, $cpasswd);
  48.  
  49. if(empty($this->errorArray) == true) {// Check if array contain errors, if not insert data into db
  50. return insertUserDetails($uname, $fname, $lname, $eml, $passwd);
  51. }
  52. else {
  53. return false;
  54. }
  55. }
  56.  
  57. if(isset($_POST['register-button'])){
  58. //Get user info
  59. $username = sanitizeFormUsername($_POST['username']);
  60. $firstname = sanitizeFormString($_POST['firstname']);
  61. $lastname = sanitizeFormString($_POST['lastname']);
  62. $email = sanitizeFormString($_POST['email']);
  63. $confirmEmail = sanitizeFormString($_POST['confirmEmail']);
  64. $password = sanitizeFormPassword($_POST['password']);
  65. $confirmPassword = sanitizeFormPassword($_POST['confirmPassword']);
  66.  
  67. //$wasSuccessful hold the result(value) of the function call (register);
  68. $wasSuccessful = $account->register($username, $firstname, $lastname, $email, $confirmEmail, $password, $confirmPassword);
  69.  
  70. if($wasSuccessful == true) {
  71. header("Location: index.php"); //redirect user to index.php if successful.
  72. }
  73.  
  74. <!doctype html>
  75. <?php
  76. include("includes/config.php");
  77. include("includes/classes/Account.inc.php");
  78. include("includes/classes/Constants.inc.php");
  79.  
  80. $account = new Account($connect);
  81.  
  82. include("includes/handlers/register-handler.php");
  83. include("includes/handlers/login-handler.php");
  84.  
  85. function getInputValue($name) {
  86. if(isset($_POST[$name])) {
  87. echo $_POST[$name];
  88. }
  89. }
Add Comment
Please, Sign In to add comment