public function store()
{
$input = Input::only('username', 'realname', 'email', 'password', 'password_confirmation');
// Verify the submitted reCAPTCHA
if (!ReCaptcha::check()) {
$status = __d('users', 'Invalid reCAPTCHA submitted.');
return Redirect::back()->withStatus($status, 'danger');
}
// Create a Validator instance.
$validator = $this->validate($input);
if ($validator->fails()) {
// Errors occurred on Validation.
$status = $validator->errors();
return Redirect::back()->withInput()->withStatus($status, 'danger');
}
// Encrypt the given Password.
$password = Hash::make($input['password']);
// Create the Activation code.
$email = $input['email'];
$token = $this->createNewToken($email);
// Retrieve the default 'user' Role.
$role = Role::where('slug', 'user')->first();
if ($role === null) {
throw new \RuntimeException('Default Role not found.');
}
// Create the User record.
$user = User::create(array('username' => $input['username'], 'realname' => $input['realname'], 'email' => $email, 'password' => $password, 'activation_code' => $token, 'role_id' => $role->getKey()));
// Send the associated Activation E-mail.
Mailer::send('Emails/Auth/Activate', array('token' => $token), function ($message) use($user) {
$subject = __d('users', 'Activate your Account!');
$message->to($user->email, $user->realname);
$message->subject($subject);
});
// Prepare the flash message.
$status = __d('users', 'Your Account has been created. We have sent you an E-mail to activate your Account.');
return Redirect::to('register/status')->withStatus($status);
}