Guest User

Untitled

a guest
Oct 21st, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. <?php
  2.  
  3. class Register
  4. {
  5.  
  6. private $dob = null,
  7. $day = null,
  8. $month = null,
  9. $year = null,
  10. $gender = 'male',
  11. $username = 'Guest',
  12. $password = null,
  13. $email = null,
  14. $secCode = null,
  15. $minAge = 11,
  16. $maxAge = 100;
  17.  
  18. private $step = 1,
  19. $errorMessage = null,
  20. $currentPage = null,
  21. $bgClass = null;
  22.  
  23. public function __construct()
  24. {
  25.  
  26. global $Smarty;
  27.  
  28. $this->currentPage = $_GET['page'];
  29.  
  30. $this->_setData();
  31.  
  32. $this->_findValidPage();
  33.  
  34. if( $_POST )
  35. {
  36.  
  37. $this->_processData();
  38.  
  39. }
  40.  
  41. $Smarty->assign('step', $this->grabData('step') );
  42. $Smarty->assign('bodyClass', $this->grabData('bgClass') );
  43. $Smarty->assign('error', $this->grabData('errorMessage') );
  44.  
  45. }
  46.  
  47. public function grabSession( $key )
  48. {
  49.  
  50. return ($_SESSION[$key] ? $_SESSION[$key] : false);
  51.  
  52. }
  53.  
  54. public function setSession( $key, $value = '' )
  55. {
  56.  
  57. $_SESSION[$key] = $value;
  58.  
  59. }
  60.  
  61. public function grabData( $key, $value = '' )
  62. {
  63.  
  64. if( $value )
  65. {
  66.  
  67. $this->$key = $value;
  68.  
  69. return $value;
  70.  
  71. }
  72. else
  73. {
  74.  
  75. return $this->$key ? $this->$key : false;
  76.  
  77. }
  78.  
  79. }
  80.  
  81. private function _setData()
  82. {
  83.  
  84. if( $_SESSION )
  85. {
  86.  
  87. foreach( $_SESSION as $key => $value )
  88. {
  89.  
  90. $this->$key = $value;
  91.  
  92. }
  93.  
  94. }
  95.  
  96. if( $_POST )
  97. {
  98.  
  99. foreach( $_POST as $key => $value )
  100. {
  101.  
  102. $key = str_replace('bean_', '', $key);
  103.  
  104. $this->$key = $value;
  105.  
  106. }
  107.  
  108. }
  109.  
  110. }
  111.  
  112. private function _findValidPage( )
  113. {
  114.  
  115. switch( $this->grabSession('step') )
  116. {
  117.  
  118. default:
  119.  
  120. $this->setSession('step', 1);
  121.  
  122. $this->redirect();
  123.  
  124. break;
  125.  
  126. case 1:
  127.  
  128. if( $this->currentPage != 'start' )
  129. {
  130.  
  131. if( !$this->grabData('dob') || $this->grabData('bean_gender') )
  132. {
  133.  
  134. $this->redirect();
  135.  
  136. }
  137. }
  138.  
  139. $this->grabData('bgClass', 'background-agegate');
  140. $this->grabData('template', 'start');
  141.  
  142. break;
  143.  
  144. case 2:
  145.  
  146. if( $this->currentPage != 'email_password' )
  147. {
  148.  
  149. if( !$this->grabData('email') || !$this->grabData('password') )
  150. {
  151.  
  152. $this->redirect('email_password');
  153.  
  154. }
  155.  
  156. }
  157.  
  158. $this->grabData('bgClass', 'background-accountdetails-'.$this->grabData('gender') );
  159. $this->grabData('template', 'email_password');
  160.  
  161. break;
  162.  
  163. }
  164.  
  165. }
  166.  
  167. private function redirect( $pageName = 'start' )
  168. {
  169.  
  170. header('Location: /quickregister/' . $pageName );
  171.  
  172. }
  173.  
  174. private function _processData()
  175. {
  176.  
  177. switch( $this->grabData('step') )
  178. {
  179.  
  180. case 1:
  181.  
  182. if( $this->gender != 'male' )
  183. {
  184.  
  185. $this->gender = 'female';
  186.  
  187. }
  188. else
  189. {
  190.  
  191. $this->gender = 'male';
  192.  
  193. }
  194.  
  195. $this->setSession('gender', $this->gender);
  196.  
  197. foreach( array ( 'day', 'month', 'year' ) as $check )
  198. {
  199.  
  200. if( $this->grabData( $check ) )
  201. {
  202.  
  203. $this->dob .= $this->$check . ( $check == 'year' ?: '-' );
  204.  
  205. }
  206. else
  207. {
  208.  
  209. $this->errorMessage = 'Please supply a valid birthdate.';
  210. break;
  211.  
  212. }
  213.  
  214. }
  215.  
  216. if( !$this->errorMessage ){ $this->setSession('step', 2); $this->redirect('password_email'); }
  217.  
  218. break;
  219.  
  220. case 2:
  221.  
  222. if( strlen( $this->password ) >= 5 && strlen( $this->password ) <= 20 )
  223. {
  224.  
  225. $this->errorMessage = '';
  226.  
  227. }
  228.  
  229. break;
  230.  
  231. }
  232.  
  233.  
  234. }
  235.  
  236.  
  237. }
Add Comment
Please, Sign In to add comment