2014-07-02 14:58:40 -05:00
|
|
|
<?php
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
2014-12-25 01:07:17 -06:00
|
|
|
* @SuppressWarnings("CyclomaticComplexity") // It's all 5. So ok.
|
|
|
|
*
|
2014-07-15 15:16:29 -05:00
|
|
|
* Class ProfileController
|
|
|
|
*/
|
2014-07-02 14:58:40 -05:00
|
|
|
class ProfileController extends BaseController
|
|
|
|
{
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\View\View
|
|
|
|
*/
|
2014-11-12 15:36:02 -06:00
|
|
|
public function changePassword()
|
2014-07-02 14:58:40 -05:00
|
|
|
{
|
2014-11-12 15:36:02 -06:00
|
|
|
return View::make('profile.change-password')->with('title', Auth::user()->email)->with('subTitle', 'Change your password')->with(
|
|
|
|
'mainTitleIcon', 'fa-user'
|
|
|
|
);
|
2014-07-02 14:58:40 -05:00
|
|
|
}
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\View\View
|
2014-11-12 15:36:02 -06:00
|
|
|
*
|
2014-07-15 15:16:29 -05:00
|
|
|
*/
|
2014-11-12 15:36:02 -06:00
|
|
|
public function index()
|
2014-07-02 14:58:40 -05:00
|
|
|
{
|
2014-11-12 15:36:02 -06:00
|
|
|
return View::make('profile.index')->with('title', 'Profile')->with('subTitle', Auth::user()->email)->with('mainTitleIcon', 'fa-user');
|
2014-07-02 14:58:40 -05:00
|
|
|
}
|
|
|
|
|
2014-07-15 15:16:29 -05:00
|
|
|
/**
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
|
|
|
|
*/
|
2014-07-02 14:58:40 -05:00
|
|
|
public function postChangePassword()
|
|
|
|
{
|
|
|
|
|
|
|
|
// old, new1, new2
|
|
|
|
if (!Hash::check(Input::get('old'), Auth::user()->password)) {
|
|
|
|
Session::flash('error', 'Invalid current password!');
|
2014-07-28 14:33:32 -05:00
|
|
|
|
2014-07-02 14:58:40 -05:00
|
|
|
return View::make('profile.change-password');
|
|
|
|
}
|
|
|
|
if (strlen(Input::get('new1')) == 0 || strlen(Input::get('new2')) == 0) {
|
|
|
|
Session::flash('error', 'Do fill in a password!');
|
2014-07-28 14:33:32 -05:00
|
|
|
|
2014-07-02 14:58:40 -05:00
|
|
|
return View::make('profile.change-password');
|
|
|
|
}
|
|
|
|
if (Input::get('new1') == Input::get('old')) {
|
|
|
|
Session::flash('error', 'The idea is to change your password.');
|
2014-07-28 14:33:32 -05:00
|
|
|
|
2014-07-02 14:58:40 -05:00
|
|
|
return View::make('profile.change-password');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Input::get('new1') !== Input::get('new2')) {
|
|
|
|
Session::flash('error', 'New passwords do not match!');
|
2014-07-28 14:33:32 -05:00
|
|
|
|
2014-07-02 14:58:40 -05:00
|
|
|
return View::make('profile.change-password');
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the user with the new password.
|
2014-12-15 13:24:19 -06:00
|
|
|
/** @var \FireflyIII\Database\User\User $repository */
|
|
|
|
$repository = \App::make('FireflyIII\Database\User\User');
|
2014-11-12 03:54:53 -06:00
|
|
|
$repository->updatePassword(Auth::user(), Input::get('new1'));
|
2014-07-03 02:16:17 -05:00
|
|
|
|
2014-07-02 14:58:40 -05:00
|
|
|
Session::flash('success', 'Password changed!');
|
2014-07-28 14:33:32 -05:00
|
|
|
|
2014-07-02 14:58:40 -05:00
|
|
|
return Redirect::route('profile');
|
|
|
|
}
|
|
|
|
|
2015-01-01 23:16:49 -06:00
|
|
|
}
|