Guest User

Untitled

a guest
Mar 25th, 2018
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. function RegisterUser()
  2. {
  3. if(!isset($_POST['submitted']))
  4. {
  5. return false;
  6. }
  7.  
  8. $formvars = array();
  9.  
  10. if(!$this->ValidateRegistrationSubmission())
  11. {
  12. return false;
  13. }
  14.  
  15. $this->CollectRegistrationSubmission($formvars);
  16.  
  17. if(!$this->SaveToDatabase($formvars))
  18. {
  19. return false;
  20. }
  21.  
  22. /*if(!$this->SendUserConfirmationEmail($formvars))
  23. {
  24. return false;
  25. }*/
  26.  
  27. $this->SendAdminIntimationEmail($formvars);
  28.  
  29. $this->AutoLogin($formvars);// My call
  30.  
  31. return true;
  32. }
  33.  
  34. function Login()
  35. {
  36. if(empty($_POST['email']))
  37. {
  38. $this->HandleError("Email is empty!");
  39. return false;
  40. }
  41.  
  42. if(empty($_POST['password']))
  43. {
  44. $this->HandleError("Password is empty!");
  45. return false;
  46. }
  47.  
  48. $email = trim($_POST['email']);
  49. $password = trim($_POST['password']);
  50.  
  51. if(!isset($_SESSION)){ session_start(); }
  52. if(!$this->CheckLoginInDB($email,$password))
  53. {
  54. return false;
  55. }
  56.  
  57. $_SESSION[$this->GetLoginSessionVar()] = $email;
  58.  
  59. return true;
  60. }
  61.  
  62. function AutoLogin(&$formvars)
  63. {
  64. $email = trim($formvars['email']);
  65. $password = trim($formvars['password']);
  66.  
  67. if(!isset($_SESSION)){ session_start(); }
  68. if(!$this->CheckLoginInDB($email,$password))
  69. {
  70. return false;
  71. }
  72.  
  73. $_SESSION[$this->GetLoginSessionVar()] = $email;
  74.  
  75. return true;
  76. }
  77.  
  78. function CheckLogin()
  79. {
  80. if(!isset($_SESSION)){ session_start(); }
  81.  
  82. $sessionvar = $this->GetLoginSessionVar();
  83.  
  84. if(empty($_SESSION[$sessionvar]))
  85. {
  86. return false;
  87. }
  88. return true;
  89. }
  90.  
  91. function CheckLoginInDB($email,$password)
  92. {
  93. if(!$this->DBLogin())
  94. {
  95. $this->HandleError("Database login failed!");
  96. return false;
  97. }
  98. $email = $this->SanitizeForSQL($email);
  99. $pwdmd5 = md5($password);
  100. $qry = "Select name, email, pagecode, welcome from $this->tablename where email='$email' and password='$pwdmd5' and confirmcode='y'";
  101.  
  102. $result = mysql_query($qry,$this->connection);
  103.  
  104. if(!$result || mysql_num_rows($result) <= 0)
  105. {
  106. $this->HandleError("Error logging in. The email or password does not match");
  107. return false;
  108. }
  109.  
  110. $row = mysql_fetch_assoc($result);
  111.  
  112. $_SESSION['name_of_user'] = $row['name'];
  113. $_SESSION['email_of_user'] = $row['email'];
  114. $_SESSION['pagecode_of_user'] = $row['pagecode'];
  115. $_SESSION['welcome_user'] = $row['welcome'];
  116.  
  117. return true;
  118. }
  119.  
  120. function GetLoginSessionVar()
  121. {
  122. $retvar = md5($this->rand_key);
  123. $retvar = 'usr_'.substr($retvar,0,10);
  124. return $retvar;
  125. }
  126.  
  127. <?php
  128.  
  129. if (!$_SESSION) {
  130. session_start();
  131. }
  132.  
  133. $currentUser = array();
  134.  
  135. function getUserFromID($userID)
  136. {
  137. //TODO implement function
  138. return $user;
  139. }
  140.  
  141. function AutoLogin()
  142. {
  143. global $currentUser;
  144. if(!empty($_SESSION['userID'])) {
  145. return false;
  146. }
  147.  
  148. $user = getUserFromID($_SESSION['userID']);
  149. if (empty($user)) {
  150. return false;
  151. }
  152. $currentUser = $user;
  153. return true;
  154. }
Add Comment
Please, Sign In to add comment