Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function post_register()
- {
- try {
- // Get input values
- $email = strtolower(Input::get('email'));
- $password = Input::get('password');
- // Validation rules
- $rules = array(
- 'email' => 'required|email',
- 'password' => 'required|min:6',
- 'confirm_password' => 'required|same:password',
- );
- // Check for duplicate email
- $email_check = User::where('email', '=', $email)->count();
- if($email_check > 0)
- throw new Exception('That email is already registered.');
- // Validate credentials
- $validation = Validator::make(Input::all(), $rules);
- if($validation->fails())
- throw new Exception($validation->errors->first());
- // Hash password via bcrypt
- $password = Hash::make($password);
- // Insert user into database
- $user = User::create(array(
- 'email' => $email,
- 'password' => $password,
- ));
- $credentials = array(
- 'username' => $email,
- 'password' => $password,
- );
- if(Auth::attempt($credentials))
- throw new Exception('Could not log you in.');
- // Send user back to homepage
- return Redirect::to('social');
- } catch(Exception $e) {
- // Fail: Return to login/register page
- return Redirect::to('login')->with('register_errors', $e->getMessage());
- }
- }
Add Comment
Please, Sign In to add comment