Guest User

Untitled

a guest
Sep 10th, 2018
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.62 KB | None | 0 0
  1.     public function post_register()
  2.     {
  3.         try {
  4.             // Get input values
  5.             $email = strtolower(Input::get('email'));
  6.             $password = Input::get('password');
  7.  
  8.             // Validation rules
  9.             $rules = array(
  10.                 'email' => 'required|email',
  11.                 'password' => 'required|min:6',
  12.                 'confirm_password' => 'required|same:password',
  13.             );
  14.  
  15.             // Check for duplicate email
  16.             $email_check = User::where('email', '=', $email)->count();
  17.             if($email_check > 0)
  18.                 throw new Exception('That email is already registered.');
  19.  
  20.             // Validate credentials
  21.             $validation = Validator::make(Input::all(), $rules);
  22.             if($validation->fails())
  23.                 throw new Exception($validation->errors->first());
  24.  
  25.             // Hash password via bcrypt
  26.             $password = Hash::make($password);
  27.  
  28.             // Insert user into database
  29.             $user = User::create(array(
  30.                 'email' => $email,
  31.                 'password' => $password,
  32.             ));
  33.  
  34.             $credentials = array(
  35.                 'username' => $email,
  36.                 'password' => $password,
  37.             );
  38.             if(Auth::attempt($credentials))
  39.                 throw new Exception('Could not log you in.');
  40.  
  41.             // Send user back to homepage
  42.             return Redirect::to('social');
  43.  
  44.         } catch(Exception $e) {
  45.             // Fail: Return to login/register page
  46.             return Redirect::to('login')->with('register_errors', $e->getMessage());
  47.         }
  48.     }
Add Comment
Please, Sign In to add comment