示例#1
0
 public function signup()
 {
     $validation = Validator::make(Input::all(), static::$rules);
     if ($validation->fails()) {
         return Redirect::to('signup')->with(array('note' => Lang::get('lang.signup_error'), 'note_type' => 'error'));
     }
     $settings = Setting::first();
     if ($settings->captcha) {
         $privatekey = $settings->captcha_private_key;
         $resp = Recaptcha::recaptcha_check_answer($privatekey, $_SERVER["REMOTE_ADDR"], Input::get('recaptcha_challenge_field'), Input::get('recaptcha_response_field'));
         if (!$resp->is_valid) {
             // Incorrect Captcha
             return Redirect::to('signup')->with(array('note' => Lang::get('lang.incorrect_captcha'), 'note_type' => 'error'));
         } else {
         }
     }
     $username = htmlspecialchars(stripslashes(Input::get('username')));
     $user = User::where('username', '=', $username)->first();
     if (!$user) {
         if ($settings->user_registration) {
             if (count(explode(' ', $username)) == 1) {
                 if (Input::get('password') != '') {
                     $user = $this->new_user($username, Input::get('email'), Hash::make(Input::get('password')));
                     if ($user) {
                         Auth::attempt(array('email' => Input::get('email'), 'password' => Input::get('password')));
                         $this->new_user_points($user->id);
                     }
                     $redirect = Input::get('redirect');
                     if ($redirect == '') {
                         $redirect = '/';
                     }
                     return Redirect::to($redirect)->with(array('note' => Lang::get('lang.signup_success'), 'note_type' => 'success'));
                 } else {
                     return Redirect::to('signup')->with(array('note' => Lang::get('lang.signup_invalidpass'), 'note_type' => 'error'));
                 }
             } else {
                 return Redirect::to('/signup')->with(array('note' => Lang::get('lang.username_no_spaces'), 'note_type' => 'error'));
             }
         } else {
             return Redirect::to('/')->with(array('note' => Lang::get('lang.signup_reg_closed'), 'note_type' => 'error'));
         }
     } else {
         return Redirect::to('signup')->with(array('note' => Lang::get('lang.username_in_use'), 'note_type' => 'error'));
     }
 }