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

116 lines
3.0 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-05-27 00:27:05 -05:00
use App;
2015-02-05 21:52:16 -06:00
use FireflyIII\Http\Controllers\Controller;
2015-05-27 00:27:05 -05:00
use FireflyIII\User;
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-05-01 01:29:41 -05:00
use Twig;
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
2015-05-14 02:51:54 -05:00
*
2015-05-10 06:06:02 -05:00
* @codeCoverageIgnore
2015-02-07 15:50:47 -06:00
*
*/
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-05-01 01:29:41 -05:00
/**
* Show the application login form.
*
2015-05-10 06:06:02 -05:00
* @codeCoverageIgnore
2015-05-01 01:29:41 -05:00
* @return \Illuminate\Http\Response
2015-05-10 06:06:02 -05:00
*
2015-05-01 01:29:41 -05:00
*/
public function getLogin()
{
return Twig::render('auth.login');
}
2015-03-03 02:29:02 -06:00
/**
* Handle a registration request for the application.
*
* @param Request $request
*
* @return \Illuminate\Http\RedirectResponse
2015-03-03 02:29:02 -06:00
*/
public function postRegister(Request $request)
{
$validator = $this->registrar->validator($request->all());
if ($validator->fails()) {
$this->throwValidationException(
$request, $validator
);
2015-05-10 06:06:02 -05:00
// @codeCoverageIgnoreStart
2015-03-03 02:29:02 -06:00
}
2015-05-10 06:06:02 -05:00
// @codeCoverageIgnoreEnd
2015-03-03 02:29:02 -06:00
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
2015-05-27 00:27:05 -05:00
if ($this->auth->user() instanceof User) {
$email = $this->auth->user()->email;
// send email.
Mail::send(
'emails.registered', [], function (Message $message) use ($email) {
$message->to($email, $email)->subject('Welcome to Firefly III!');
}
);
2015-03-03 02:29:02 -06:00
2015-05-27 00:27:05 -05:00
// set flash message
Session::flash('success', 'You have registered successfully!');
Session::flash('gaEventCategory', 'user');
Session::flash('gaEventAction', 'new-registration');
2015-03-03 02:29:02 -06:00
2015-05-27 00:27:05 -05:00
return redirect($this->redirectPath());
}
App::abort(500, 'Not a user!');
2015-03-03 02:29:02 -06:00
2015-05-27 00:27:05 -05:00
return false;
2015-03-03 02:29:02 -06:00
}
2015-02-05 21:39:52 -06:00
}