diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index a4130d446a..512a65d9af 100755 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -4,12 +4,13 @@ namespace App\Http\Controllers; use Image; use Input; use Redirect; -use App\Models\Location; use View; use Auth; use App\Helpers\Helper; use App\Models\Setting; use Gate; +use Illuminate\Http\Request; +use Illuminate\Support\Facades\Hash; /** * This controller handles all actions related to User Profiles for @@ -87,4 +88,64 @@ class ProfileController extends Controller public function api() { return view('account/api'); } + + /** + * User change email page. + * + * @return View + */ + public function password() + { + $user = Auth::user(); + return view('account/change-password', compact('user')); + } + + /** + * Users change password form processing page. + * + * @return Redirect + */ + public function passwordSave(Request $request) + { + if (config('app.lock_passwords')) { + return redirect()->route('account.password.index')->with('error', Lang::get('admin/users/table.lock_passwords')); + } else { + + // Grab the user + $user = Auth::user(); + + if ($user->ldap_import=='1') { + return redirect()->route('account.password.index')->with('error', Lang::get('admin/users/message.error.password_ldap')); + } + + + $rules = array( + 'current_password' => 'required', + 'password' => 'required|min:6', + 'password_confirm' => 'required|same:password', + ); + + $validator = \Validator::make($request->all(), $rules); + + $validator->after(function($validator) use ($request, $user) { + + if (!Hash::check($request->input('current_password'), $user->password)) { + $validator->errors()->add('current_password', trans('validation.hashed_pass')); + } + }); + + if (!$validator->fails()) { + $user->password = Hash::make($request->input('password')); + $user->save(); + return redirect()->route('account.password.index')->with('success', 'Password updated!'); + + } + return redirect()->back()->withInput()->withErrors($validator); + + + } + + + } + } diff --git a/resources/lang/en/admin/users/message.php b/resources/lang/en/admin/users/message.php index ef41b2a820..8ee552afab 100644 --- a/resources/lang/en/admin/users/message.php +++ b/resources/lang/en/admin/users/message.php @@ -41,6 +41,7 @@ return array( 'ldap_could_not_bind' => 'Could not bind to the LDAP server. Please check your LDAP server configuration in the LDAP config file.
Error from LDAP Server: ', 'ldap_could_not_search' => 'Could not search the LDAP server. Please check your LDAP server configuration in the LDAP config file.
Error from LDAP Server:', 'ldap_could_not_get_entries' => 'Could not get entries from the LDAP server. Please check your LDAP server configuration in the LDAP config file.
Error from LDAP Server:', + 'password_ldap' => 'The password for this account is managed by LDAP/Active Directory. Please contact your IT department to change your password. ', ), 'deletefile' => array( diff --git a/resources/lang/en/validation.php b/resources/lang/en/validation.php index c39da95df0..fd5a589e1a 100644 --- a/resources/lang/en/validation.php +++ b/resources/lang/en/validation.php @@ -35,6 +35,7 @@ return array( "email" => "The :attribute format is invalid.", "exists" => "The selected :attribute is invalid.", "email_array" => "One or more email addresses is invalid.", + "hashed_pass" => "Your current password is incorrect", "image" => "The :attribute must be an image.", "in" => "The selected :attribute is invalid.", "integer" => "The :attribute must be an integer.", diff --git a/resources/views/account/change-password.blade.php b/resources/views/account/change-password.blade.php index af17444d49..f91016287f 100755 --- a/resources/views/account/change-password.blade.php +++ b/resources/views/account/change-password.blade.php @@ -2,35 +2,35 @@ {{-- Page title --}} @section('title') -Change your Password +{{ trans('general.changepassword') }} @stop {{-- Account page content --}} @section('content') -
-
-

{{ trans('general.changepassword') }}

-
-
-
-
+ +
+
+ {{ Form::open(['method' => 'POST', 'files' => true, 'class' => 'form-horizontal', 'autocomplete' => 'off']) }} - + +
+
+ -
-
+ {{ Form::close() }} +
+
@stop diff --git a/resources/views/layouts/default.blade.php b/resources/views/layouts/default.blade.php index c4d18eb174..cdd372774a 100644 --- a/resources/views/layouts/default.blade.php +++ b/resources/views/layouts/default.blade.php @@ -301,6 +301,14 @@ @lang('general.editprofile') +
  • + + @lang('general.changepassword') + +
  • + + + @can('self.api')
  • diff --git a/routes/web.php b/routes/web.php index 983d2fb133..6bc2fd46c3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -215,6 +215,10 @@ Route::group([ 'prefix' => 'account', 'middleware' => ['auth']], function () { # Profile Route::get('profile', [ 'as' => 'profile', 'uses' => 'ProfileController@getIndex' ]); Route::post('profile', 'ProfileController@postIndex'); + + Route::get('password', [ 'as' => 'account.password.index', 'uses' => 'ProfileController@password' ]); + Route::post('password', [ 'uses' => 'ProfileController@passwordSave' ]); + Route::get('api', [ 'as' => 'user.api', 'uses' => 'ProfileController@api' ]); # View Assets