Advertisement
Guest User

Untitled

a guest
Jul 30th, 2014
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.03 KB | None | 0 0
  1. <?php
  2. /**
  3. * phpVMS - Virtual Airline Administration Software
  4. * Copyright (c) 2008 Nabeel Shahzad
  5. * For more information, visit www.phpvms.net
  6. * Forums: http://www.phpvms.net/forum
  7. * Documentation: http://www.phpvms.net/docs
  8. *
  9. * phpVMS is licenced under the following license:
  10. * Creative Commons Attribution Non-commercial Share Alike (by-nc-sa)
  11. * View license.txt in the root, or visit http://creativecommons.org/licenses/by-nc-sa/3.0/
  12. *
  13. * @author Nabeel Shahzad
  14. * @copyright Copyright (c) 2008, Nabeel Shahzad
  15. * @link http://www.phpvms.net
  16. * @license http://creativecommons.org/licenses/by-nc-sa/3.0/
  17. */
  18.  
  19. class RegistrationData extends CodonData
  20. {
  21.  
  22. static public $salt;
  23. static public $error;
  24. static public $pilotid;
  25.  
  26. /**
  27. * Get all of the custom fields that will show up
  28. * during the registration
  29. */
  30. public static function GetCustomFields($getall=false)
  31. {
  32.  
  33. $sql = 'SELECT * FROM ' . TABLE_PREFIX . 'customfields';
  34.  
  35. if($getall == false)
  36. $sql .=' WHERE showonregister=1';
  37.  
  38. return DB::get_results($sql);
  39. }
  40.  
  41. public static function CheckUserEmail($email)
  42. {
  43. $sql = 'SELECT * FROM '.TABLE_PREFIX.'pilots
  44. WHERE email=\''.$email.'\'';
  45.  
  46. return DB::get_row($sql);
  47. }
  48.  
  49. /**
  50. * Add a User
  51. *
  52. * $data = array(
  53. 'firstname' => '',
  54. 'lastname' => '',
  55. 'email' => '',
  56. 'password' => '',
  57. 'code' => '',
  58. 'location' => '',
  59. 'hub' => '',
  60. 'confirm' => false);
  61. */
  62. public static function AddUser($data)
  63. {
  64.  
  65. /*$data = array(
  66. 'firstname' => '',
  67. 'lastname' => '',
  68. 'email' => '',
  69. 'password' => '',
  70. 'code' => '',
  71. 'location' => '',
  72. 'hub' => '',
  73. 'confirm' => false);*/
  74.  
  75. $exists = self::CheckUserEmail($data['email']);
  76. if (is_object($exists) )
  77. {
  78. self::$error = 'Email already exists';
  79. return false;
  80. }
  81.  
  82. //Set the password, add some salt
  83. $salt = md5(date('His'));
  84. $password = md5($data['password'] . $salt);
  85.  
  86. //Stuff it into here, the confirmation email will use it.
  87. self::$salt = $salt;
  88.  
  89. $code = DB::escape(strtoupper($data['code']));
  90. $firstname = DB::escape(ucwords($data['firstname']));
  91. $lastname = DB::escape(ucwords($data['lastname']));
  92. $location = DB::escape(strtoupper($data['location']));
  93. //Add this stuff in
  94.  
  95. if($data['confirm'] === true)
  96. $confirm = 1;
  97. else
  98. $confirm = 0;
  99.  
  100. $sql = "INSERT INTO ".TABLE_PREFIX."pilots (firstname, lastname, email,
  101. code, location, hub, password, salt, confirmed, joindate, lastip)
  102. VALUES ('{$firstname}', '{$lastname}', '{$data['email']}', '{$code}',
  103. '{$location}', '{$data['hub']}', '{$password}', '{$salt}', {$confirm}, NOW(), '{$_SERVER['REMOTE_ADDR']}')";
  104.  
  105.  
  106. $res = DB::query($sql);
  107. if(DB::errno() != 0)
  108. {
  109. if(DB::errno() == 1062)
  110. {
  111. self::$error = 'This email address is already registered';
  112. return false;
  113. }
  114.  
  115. self::$error = DB::error();
  116. return false;
  117. }
  118.  
  119. //Grab the new pilotid, we need it to insert those "custom fields"
  120. $pilotid = DB::$insert_id;
  121. RanksData::CalculateUpdatePilotRank($pilotid);
  122. PilotData::GenerateSignature($pilotid);
  123.  
  124. /* Add them to the default group */
  125. PilotGroups::AddUsertoGroup($pilotid, DEFAULT_GROUP);
  126.  
  127. // For later
  128. self::$pilotid = $pilotid;
  129.  
  130. //Get customs fields
  131. $fields = self::GetCustomFields();
  132. if(!$fields)
  133. return true;
  134.  
  135. foreach($fields as $field)
  136. {
  137. $value = Vars::POST($field->fieldname);
  138. $value = DB::escape($value);
  139.  
  140. if($value != '')
  141. {
  142. $sql = "INSERT INTO ".TABLE_PREFIX."fieldvalues (fieldid, pilotid, value)
  143. VALUES ($field->fieldid, $pilotid, '$value')";
  144.  
  145. DB::query($sql);
  146. }
  147. }
  148.  
  149. return true;
  150. }
  151.  
  152. public static function ChangePassword($pilotid, $newpassword)
  153. {
  154. $salt = md5(date('His'));
  155. $password = md5($newpassword . $salt);
  156. self::$salt = $salt;
  157.  
  158. //, confirmed='y'
  159. $sql = "UPDATE " . TABLE_PREFIX ."pilots
  160. SET password='$password',
  161. salt='$salt'
  162. WHERE pilotid=$pilotid";
  163.  
  164. $res = DB::query($sql);
  165.  
  166. if(DB::errno() != 0)
  167. return false;
  168.  
  169. return true;
  170. }
  171.  
  172. public static function SendEmailConfirm($email, $firstname, $lastname, $newpw='')
  173. {
  174. /*$firstname = Vars::POST('firstname');
  175. $lastname = Vars::POST('lastname');
  176. $email = Vars::POST('email');*/
  177. $confid = self::$salt;
  178.  
  179. $subject = SITE_NAME . ' Registration';
  180.  
  181. Template::Set('firstname', $firstname);
  182. Template::Set('lastname', $lastname);
  183. Template::Set('confid', $confid);
  184.  
  185. $message = Template::GetTemplate('email_registered.tpl', true);
  186.  
  187. //email them the confirmation
  188. Util::SendEmail($email, $subject, $message);
  189. }
  190.  
  191. public static function ValidateConfirm()
  192. {
  193. $confid = Vars::GET('confirmid');
  194.  
  195. $sql = "UPDATE ".TABLE_PREFIX."pilots SET confirmed=1, retired=0 WHERE salt='$confid'";
  196. $res = DB::query($sql);
  197.  
  198. if(DB::errno() != 0)
  199. return false;
  200.  
  201. return true;
  202. }
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement