firefly-iii/app/controllers/UserController.php
2014-07-04 07:30:12 +02:00

108 lines
3.0 KiB
PHP

<?php
use Firefly\Helper\Email\EmailHelperInterface as EHI;
use Firefly\Storage\User\UserRepositoryInterface as URI;
class UserController extends BaseController
{
public function __construct(URI $user, EHI $email)
{
$this->user = $user;
$this->email = $email;
}
public function login()
{
return View::make('user.login');
}
public function postLogin()
{
$rememberMe = Input::get('remember_me') == '1';
$data = [
'email' => Input::get('email'),
'password' => Input::get('password')
];
if (Auth::attempt($data, $rememberMe)) {
Session::flash('success', 'Logged in!');
return Redirect::route('index');
}
Session::flash('error', 'No good!');
return View::make('user.login');
}
public function register()
{
if (Config::get('auth.allow_register') !== true) {
return View::make('error')->with('message', 'Not possible');
}
return View::make('user.register');
}
public function postRegister()
{
if (Config::get('auth.allow_register') !== true) {
return View::make('error')->with('message', 'Not possible');
}
$user = $this->user->register(Input::all());
if ($user) {
if (Config::get('auth.verify_mail') === true) {
$this->email->sendVerificationMail($user);
return View::make('user.verification-pending');
}
$this->email->sendPasswordMail($user);
return View::make('user.registered');
}
return View::make('user.register');
}
public function logout()
{
Auth::logout();
return Redirect::route('index');
}
public function remindme()
{
return View::make('user.remindme');
}
public function postRemindme()
{
$user = $this->user->findByEmail(Input::get('email'));
if (!$user) {
Session::flash('error', 'No good!');
return View::make('user.remindme');
}
if (Config::get('auth.verify_reset') === true) {
$this->email->sendResetVerification($user);
return View::make('user.verification-pending');
}
$this->email->sendPasswordMail($user);
return View::make('user.registered');
}
public function verify($verification)
{
$user = $this->user->findByVerification($verification);
if ($user) {
$this->email->sendPasswordMail($user);
return View::make('user.registered');
}
return View::make('error')->with('message', 'Yo no hablo verification code!');
}
public function reset($reset)
{
$user = $this->user->findByReset($reset);
if ($user) {
$this->email->sendPasswordMail($user);
return View::make('user.registered');
}
return View::make('error')->with('message', 'Yo no hablo reset code!');
}
}