Advertisement
Guest User

register.php

a guest
Apr 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.58 KB | None | 0 0
  1. <?php
  2.  
  3. require_once 'core/init.php';
  4.  
  5. if(Input::exists()) {
  6.  
  7.   if(Token::check(Input::get('token'))) {
  8.  
  9.       $validate = new Validate();
  10.  
  11.       $validation = $validate->check($_POST, array(
  12.  
  13.         'username' => array(
  14.  
  15.           'required'  => true,
  16.           'min'       => 2,
  17.           'max'       => 20,
  18.           'unique'    => 'users'
  19.  
  20.         ),
  21.  
  22.         'password' => array(
  23.  
  24.           'required'  => true,
  25.           'min'       => 6
  26.  
  27.         ),
  28.  
  29.         'password_again' => array(
  30.  
  31.           'required'  => true,
  32.           'matches'   => 'password'
  33.  
  34.         ),
  35.  
  36.         'name' => array(
  37.  
  38.           'required'  => true,
  39.           'min'       => 2,
  40.           'max'       => 50
  41.         )
  42.  
  43.       ));
  44.  
  45.       if($validation->passed()) {
  46.  
  47.         $user = new User();
  48.  
  49.         $salt = Hash::salt(32);
  50.  
  51.         try {
  52.  
  53.           $user->create(array(
  54.  
  55.             'username'  => Input::get('username'),
  56.             'password'  => Hash::make(Input::get('password'), $salt),
  57.             'salt'      => $salt,
  58.             'name'      => Input::get('name'),
  59.             'joined'    => date('Y-m-d H:i:s'),
  60.             'group'     => 1
  61.  
  62.           ));
  63.  
  64.           Session::flash('home', 'You have been registered and can now log in!');
  65.  
  66.           Redirect::to('index.php');
  67.  
  68.         } catch(Exception $e) {
  69.  
  70.           die($e->getMessage());
  71.  
  72.         }
  73.  
  74.       } else {
  75.  
  76.         foreach($validation->errors() as $error) {
  77.  
  78.           echo $error, '<br>';
  79.  
  80.         }
  81.  
  82.       }
  83.  
  84.   }
  85.  
  86. }
  87.  
  88. ?>
  89.  
  90. <form action="" method="post">
  91.     <div class="field">
  92.         <label for="username">Username</label>
  93.         <input type="text" name="username" id="username" value="<?php echo escape(Input::get('username')); ?>" autocomplete="off" />
  94.     </div><!-- end .field -->
  95.  
  96.     <div class="field">
  97.         <label for="password">Choose a password</label>
  98.         <input type="password" name="password" id="password" value="" autocomplete="off" />
  99.     </div><!-- end .field -->
  100.  
  101.     <div class="field">
  102.         <label for="password_again">Enter your password again</label>
  103.         <input type="password" name="password_again" id="password_again" value="" autocomplete="off" />
  104.     </div><!-- end .field -->
  105.  
  106.     <div class="field">
  107.         <label for="name">Your name</label>
  108.         <input type="text" name="name" id="name" value="<?php echo escape(Input::get('name')); ?>" autocomplete="off" />
  109.     </div><!-- end .field -->
  110.  
  111.     <input type="hidden" name="token" value="<?php echo Token::generate(); ?>" />
  112.     <input type="submit" value="Register" />
  113. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement