firefly-iii/app/Http/Controllers/Auth/AuthController.php

90 lines
2.4 KiB
PHP
Raw Normal View History

2015-02-05 21:52:16 -06:00
<?php namespace FireflyIII\Http\Controllers\Auth;
2015-02-05 21:39:52 -06:00
2015-02-05 21:52:16 -06:00
use FireflyIII\Http\Controllers\Controller;
2015-02-05 21:39:52 -06:00
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\Registrar;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
2015-03-03 02:29:02 -06:00
use Illuminate\Http\Request;
2015-03-29 00:43:20 -05:00
use Illuminate\Mail\Message;
2015-03-03 02:29:02 -06:00
use Mail;
use Session;
2015-02-05 21:39:52 -06:00
2015-02-11 00:35:10 -06:00
/**
* Class AuthController
*
* @package FireflyIII\Http\Controllers\Auth
*/
2015-02-07 15:50:47 -06:00
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers;
public $redirectTo = '/';
/**
* Create a new authentication controller instance.
*
* @param \Illuminate\Contracts\Auth\Guard $auth
* @param \Illuminate\Contracts\Auth\Registrar $registrar
*
*/
public function __construct(Guard $auth, Registrar $registrar)
{
$this->auth = $auth;
$this->registrar = $registrar;
$this->middleware('guest', ['except' => 'getLogout']);
}
2015-02-05 21:39:52 -06:00
2015-03-03 02:29:02 -06:00
/**
* Handle a registration request for the application.
*
* @param Request $request
*
* @return \Illuminate\Http\Response
*/
public function postRegister(Request $request)
{
$validator = $this->registrar->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException(
$request, $validator
);
}
2015-03-29 14:27:51 -05:00
$data = $request->all();
2015-03-25 16:29:32 -05:00
$data['password'] = bcrypt($data['password']);
2015-03-25 16:30:36 -05:00
$this->auth->login($this->registrar->create($data));
2015-03-03 02:29:02 -06:00
// get the email address
$email = $this->auth->user()->email;
// send email.
Mail::send(
2015-03-29 00:43:20 -05:00
'emails.registered', [], function (Message $message) use ($email) {
2015-03-03 02:29:02 -06:00
$message->to($email, $email)->subject('Welcome to Firefly III!');
}
);
// set flash message
2015-03-10 11:26:31 -05:00
Session::flash('success', 'You have registered successfully!');
2015-03-03 02:29:02 -06:00
return redirect($this->redirectPath());
}
2015-02-05 21:39:52 -06:00
}