mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-05 04:03:26 +00:00
Combination of initial files and some new code for login and user registration.
This commit is contained in:
75
app/controllers/RemindersController.php
Normal file
75
app/controllers/RemindersController.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
class RemindersController extends Controller {
|
||||
|
||||
/**
|
||||
* Display the password reminder view.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function getRemind()
|
||||
{
|
||||
return View::make('password.remind');
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a POST request to remind a user of their password.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function postRemind()
|
||||
{
|
||||
switch ($response = Password::remind(Input::only('email')))
|
||||
{
|
||||
case Password::INVALID_USER:
|
||||
return Redirect::back()->with('error', Lang::get($response));
|
||||
|
||||
case Password::REMINDER_SENT:
|
||||
return Redirect::back()->with('status', Lang::get($response));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the password reset view for the given token.
|
||||
*
|
||||
* @param string $token
|
||||
* @return Response
|
||||
*/
|
||||
public function getReset($token = null)
|
||||
{
|
||||
if (is_null($token)) App::abort(404);
|
||||
|
||||
return View::make('password.reset')->with('token', $token);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a POST request to reset a user's password.
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function postReset()
|
||||
{
|
||||
$credentials = Input::only(
|
||||
'email', 'password', 'password_confirmation', 'token'
|
||||
);
|
||||
|
||||
$response = Password::reset($credentials, function($user, $password)
|
||||
{
|
||||
$user->password = Hash::make($password);
|
||||
|
||||
$user->save();
|
||||
});
|
||||
|
||||
switch ($response)
|
||||
{
|
||||
case Password::INVALID_PASSWORD:
|
||||
case Password::INVALID_TOKEN:
|
||||
case Password::INVALID_USER:
|
||||
return Redirect::back()->with('error', Lang::get($response));
|
||||
|
||||
case Password::PASSWORD_RESET:
|
||||
return Redirect::to('/');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
75
app/controllers/UserController.php
Normal file
75
app/controllers/UserController.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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()
|
||||
{
|
||||
if (!$this->user->auth()) {
|
||||
$rememberMe = Input::get('remember_me') == '1';
|
||||
$result = [];
|
||||
$data = [
|
||||
'email' => Input::get('email'),
|
||||
'password' => Input::get('password')
|
||||
];
|
||||
|
||||
|
||||
if (Auth::attempt($data, $rememberMe)) {
|
||||
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 App::abort(404);
|
||||
}
|
||||
return View::make('user.register');
|
||||
}
|
||||
|
||||
public function postRegister()
|
||||
{
|
||||
if (Config::get('auth.allow_register') !== true) {
|
||||
return App::abort(404);
|
||||
}
|
||||
$user = $this->user->register();
|
||||
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 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!');
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user