Guest User

Untitled

a guest
Aug 21st, 2017
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. The MIT License (MIT)
  5.  
  6. Shaheed Ahmed Dewan Sagar
  7. Email : sdewan64@gmail.com
  8. Ahsanullah University of Science and Technology,Dhaka,Bangladesh.
  9. Copyright (c) 2014
  10.  
  11. Permission is hereby granted, free of charge, to any person obtaining a copy
  12. of this software and associated documentation files (the "Software"), to deal
  13. in the Software without restriction, including without limitation the rights
  14. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  15. copies of the Software, and to permit persons to whom the Software is
  16. furnished to do so, subject to the following conditions:
  17.  
  18. The above copyright notice and this permission notice shall be included in all
  19. copies or substantial portions of the Software.
  20.  
  21. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  22. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  23. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  24. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  25. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  26. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  27. SOFTWARE.
  28. */
  29. /**
  30. * Description of class
  31. *
  32. * @author Shaheed Ahmed Dewan Sagar
  33. * email : sdewan64@gmail.com
  34. */
  35. require_once '../uses_constants/class.DatabaseConstants.php';
  36. require_once 'class.DBase.php';
  37. class Register {
  38.  
  39. private $username;
  40. private $password;
  41. private $cpassword;
  42. private $passmd5;
  43. private $email;
  44.  
  45. private $errors;
  46. private $token;
  47.  
  48. private $name;
  49. private $country;
  50. private $payment1;
  51. private $payment2;
  52. private $payment3;
  53. private $ref;
  54. private $regip;
  55. private $regdatum;
  56.  
  57. public function __construct() {
  58. $this->errors = array();
  59.  
  60. $this->username = $this->filter($_POST['username']);
  61. $this->password = $this->filter($_POST['password']);
  62. $this->cpassword = $this->filter($_POST['cpassword']);
  63. $this->email = $this->filter($_POST['mail']);
  64. $this->name = $this->filter($_POST['name']);
  65. $this->country = $this->filter($_POST['country']);
  66. $this->payment1 = $this->filter($_POST['payment1']);
  67. $this->payment2 = $this->filter($_POST['payment2']);
  68. $this->payment3 = $this->filter($_POST['payment3']);
  69. $this->ref = $this->filter($_POST['ref']);
  70. $this->regip = $this->filter($_POST['regip']);
  71.  
  72. $this->passmd5 = md5($this->password);
  73. $this->token = $this->filter($_POST['token']);
  74. }
  75.  
  76. public function process(){
  77. if($this->validToken() && $this->validData()){
  78. $this->register();
  79. }
  80. return count($this->errors) ? false : true;
  81. }
  82.  
  83. public function filter($var){
  84. return preg_replace('/[^a-zA-Z0-9@.]/','',$var);
  85. }
  86.  
  87. public function register(){
  88. $db = new DatabaseConstants();
  89. $dBase = new DBase($db->getHost(),$db->getUser(), $db->getPass());
  90. $dBase->setDatabaseName($db->getDb());
  91. if(!$dBase->connectDatabase()){
  92. die('SQL ERROR at db class vd fn');
  93. }
  94.  
  95. $qry = "INSERT INTO members (id,username,password,passmd5,email,country,paymenttype1,paymenttype2,paymenttype3,referredby,regip,regdatum) VALUES('','".$this->username."','".$this->password."','".$this->passmd5."','".$this->email."','".$this->country."','".$this->payment1."','".$this->payment2."','".$this->payment3."','".$this->ref."','".$this->regip."',NOW())";
  96. mysqli_query($dBase->getDbobj(), $qry);
  97. if(mysqli_affected_rows($dBase->getDbobj())<1){
  98. $this->errors[] = 'Could not process form';
  99. }
  100. $dBase->closeDatabse();
  101. }
  102.  
  103. public function getErrors(){
  104. return $this->errors;
  105. }
  106.  
  107. public function validData(){
  108.  
  109. if($this->password != $this->cpassword){
  110. $this->errors[] = 'Passwords does not match';
  111. }
  112.  
  113. if($this->country == "Country..."){
  114. $this->errors[] = 'You must select a valid country';
  115. }
  116.  
  117. $db = new DatabaseConstants();
  118. $dBase = new DBase($db->getHost(),$db->getUser(), $db->getPass());
  119. $dBase->setDatabaseName($db->getDb());
  120. if(!$dBase->connectDatabase()){
  121. die('SQL ERROR at db class vd fn');
  122. }
  123.  
  124. $qry = "Select username FROM members WHERE username=\"".$this->username."\"";
  125. $res = mysqli_query($dBase->getDbobj(), $qry);
  126.  
  127. if(mysqli_num_rows($res)){
  128. $this->errors[] = 'Username Already Taken!';
  129. }
  130.  
  131. $qry = "Select email FROM members WHERE email=\"".$this->email."\"";
  132. $res2 = mysqli_query($dBase->getDbobj(), $qry);
  133.  
  134. if(mysqli_num_rows($res2)){
  135. $this->errors[] = 'Email Address is Already registered!';
  136. }
  137.  
  138. return count($this->errors) ? false : true;
  139. }
  140.  
  141. public function validToken(){
  142. if(!isset($_SESSION['token']) || $this->token != $_SESSION['token']){
  143. $this->errors[] = 'Invalid Submission';
  144. }
  145. return count($this->errors) ? false : true;
  146. }
  147. }
Add Comment
Please, Sign In to add comment