Files
firefly-iii/app/controllers/ProfileController.php

86 lines
2.2 KiB
PHP
Raw Normal View History

<?php
2014-07-15 22:16:29 +02:00
/**
2015-01-17 10:05:43 +01:00
* @SuppressWarnings("CamelCase") // I'm fine with this.
2014-07-15 22:16:29 +02:00
* Class ProfileController
*/
class ProfileController extends BaseController
{
2014-07-15 22:16:29 +02:00
/**
* @return \Illuminate\View\View
*/
2014-11-12 22:36:02 +01:00
public function changePassword()
{
2014-11-12 22:36:02 +01:00
return View::make('profile.change-password')->with('title', Auth::user()->email)->with('subTitle', 'Change your password')->with(
'mainTitleIcon', 'fa-user'
);
}
2014-07-15 22:16:29 +02:00
/**
* @return \Illuminate\View\View
2014-11-12 22:36:02 +01:00
*
2014-07-15 22:16:29 +02:00
*/
2014-11-12 22:36:02 +01:00
public function index()
{
2014-11-12 22:36:02 +01:00
return View::make('profile.index')->with('title', 'Profile')->with('subTitle', Auth::user()->email)->with('mainTitleIcon', 'fa-user');
}
2014-07-15 22:16:29 +02:00
/**
* @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
*/
public function postChangePassword()
{
// old, new1, new2
if (!Hash::check(Input::get('old'), Auth::user()->password)) {
Session::flash('error', 'Invalid current password!');
2014-07-28 21:33:32 +02:00
return View::make('profile.change-password');
}
2015-01-17 08:57:55 +01:00
$result = $this->_validatePassword(Input::get('old'), Input::get('new1'), Input::get('new2'));
if (!($result === true)) {
Session::flash('error', $result);
2014-07-28 21:33:32 +02:00
return View::make('profile.change-password');
}
// update the user with the new password.
2014-12-15 20:24:19 +01:00
/** @var \FireflyIII\Database\User\User $repository */
$repository = \App::make('FireflyIII\Database\User\User');
$repository->updatePassword(Auth::user(), Input::get('new1'));
2014-07-03 09:16:17 +02:00
Session::flash('success', 'Password changed!');
2014-07-28 21:33:32 +02:00
return Redirect::route('profile');
}
2015-01-17 08:57:55 +01:00
/**
2015-01-17 10:05:43 +01:00
* @SuppressWarnings("CyclomaticComplexity") // It's exactly 5. So I don't mind.
*
2015-01-17 08:57:55 +01:00
* @param string $old
* @param string $new1
* @param string $new2
*
* @return string|bool
*/
protected function _validatePassword($old, $new1, $new2)
{
if (strlen($new1) == 0 || strlen($new2) == 0) {
return 'Do fill in a password!';
}
if ($new1 == $old) {
return 'The idea is to change your password.';
}
if ($new1 !== $new2) {
return 'New passwords do not match!';
}
return true;
}
2015-01-02 06:16:49 +01:00
}