firefly-iii/app/Http/Controllers/ProfileController.php

118 lines
2.9 KiB
PHP
Raw Normal View History

2015-02-25 14:19:06 -06:00
<?php namespace FireflyIII\Http\Controllers;
use Auth;
use FireflyIII\Http\Requests;
use FireflyIII\Http\Requests\DeleteAccountFormRequest;
2015-02-25 14:19:06 -06:00
use FireflyIII\Http\Requests\ProfileFormRequest;
use Hash;
use Redirect;
use Session;
/**
* Class ProfileController
*
* @package FireflyIII\Http\Controllers
*/
class ProfileController extends Controller
{
/**
* @return \Illuminate\View\View
*/
public function changePassword()
{
return view('profile.change-password')->with('title', Auth::user()->email)->with('subTitle', 'Change your password')->with(
'mainTitleIcon', 'fa-user'
);
}
/**
* @return \Illuminate\View\View
*/
public function deleteAccount()
{
return view('profile.delete-account')->with('title', Auth::user()->email)->with('subTitle', 'Delete account')->with(
'mainTitleIcon', 'fa-user'
);
}
/**
2015-05-03 02:19:14 -05:00
* @return \Illuminate\View\View
*
*/
2015-05-03 02:19:14 -05:00
public function index()
2015-04-28 08:26:30 -05:00
{
2015-05-03 02:19:14 -05:00
return view('profile.index')->with('title', 'Profile')->with('subTitle', Auth::user()->email)->with('mainTitleIcon', 'fa-user');
}
2015-02-25 14:19:06 -06:00
/**
2015-05-03 05:58:55 -05:00
* @param ProfileFormRequest $request
*
2015-02-25 14:19:06 -06:00
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/
public function postChangePassword(ProfileFormRequest $request)
{
// old, new1, new2
if (!Hash::check($request->get('current_password'), Auth::user()->password)) {
Session::flash('error', 'Invalid current password!');
return Redirect::route('change-password');
}
2015-05-03 02:19:14 -05:00
$result = $this->validatePassword($request->get('current_password'), $request->get('new_password'));
2015-02-25 14:19:06 -06:00
if (!($result === true)) {
Session::flash('error', $result);
return Redirect::route('change-password');
}
// update the user with the new password.
Auth::user()->password = $request->get('new_password');
Auth::user()->save();
Session::flash('success', 'Password changed!');
return Redirect::route('profile');
}
/**
*
* @param string $old
* @param string $new1
*
* @return string|bool
*/
2015-05-03 02:19:14 -05:00
protected function validatePassword($old, $new1)
2015-02-25 14:19:06 -06:00
{
if ($new1 == $old) {
return 'The idea is to change your password.';
}
2015-05-03 02:19:14 -05:00
return true;
}
/**
2015-05-03 05:58:55 -05:00
* @param DeleteAccountFormRequest $request
2015-05-03 02:19:14 -05:00
*
2015-05-03 05:58:55 -05:00
* @return \Illuminate\Http\RedirectResponse
* @throws \Exception
2015-05-03 02:19:14 -05:00
*/
public function postDeleteAccount(DeleteAccountFormRequest $request)
{
// old, new1, new2
if (!Hash::check($request->get('password'), Auth::user()->password)) {
Session::flash('error', 'Invalid password!');
return Redirect::route('delete-account');
2015-02-25 14:19:06 -06:00
}
2015-05-03 02:19:14 -05:00
// DELETE!
Auth::user()->delete();
Session::flush();
2015-02-25 14:19:06 -06:00
2015-05-03 02:19:14 -05:00
return Redirect::route('index');
2015-02-25 14:19:06 -06:00
}
2015-05-03 02:19:14 -05:00
2015-02-25 14:19:06 -06:00
}