mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-20 11:48:27 -06:00
Basic edit user routine.
This commit is contained in:
parent
2be060796e
commit
b021c7690f
@ -16,9 +16,12 @@ namespace FireflyIII\Http\Controllers\Admin;
|
||||
|
||||
use FireflyConfig;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Requests\UserFormRequest;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use FireflyIII\User;
|
||||
use Preferences;
|
||||
use Session;
|
||||
use URL;
|
||||
use View;
|
||||
|
||||
/**
|
||||
@ -53,10 +56,21 @@ class UserController extends Controller
|
||||
*/
|
||||
public function edit(User $user)
|
||||
{
|
||||
// put previous url in session if not redirect from store (not "return_to_edit").
|
||||
if (session('users.edit.fromUpdate') !== true) {
|
||||
Session::put('users.edit.url', URL::previous());
|
||||
}
|
||||
Session::forget('users.edit.fromUpdate');
|
||||
|
||||
$subTitle = strval(trans('firefly.edit_user', ['email' => $user->email]));
|
||||
$subTitleIcon = 'fa-user-o';
|
||||
$codes = [
|
||||
'' => strval(trans('firefly.no_block_code')),
|
||||
'bounced' => strval(trans('firefly.block_code_bounced')),
|
||||
'expired' => strval(trans('firefly.block_code_expired')),
|
||||
];
|
||||
|
||||
return view('admin.users.edit', compact('user', 'subTitle', 'subTitleIcon'));
|
||||
return view('admin.users.edit', compact('user', 'subTitle', 'subTitleIcon', 'codes'));
|
||||
|
||||
}
|
||||
|
||||
@ -146,5 +160,41 @@ class UserController extends Controller
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UserFormRequest $request
|
||||
* @param User $user
|
||||
*
|
||||
* @return $this|\Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
|
||||
*/
|
||||
public function update(UserFormRequest $request, User $user)
|
||||
{
|
||||
$data = $request->getUserData();
|
||||
|
||||
// update password
|
||||
if (strlen($data['password']) > 0) {
|
||||
$user->password = bcrypt($data['password']);
|
||||
$user->save();
|
||||
}
|
||||
|
||||
// change blocked status and code:
|
||||
$user->blocked = $data['blocked'];
|
||||
$user->blocked_code = $data['blocked_code'];
|
||||
$user->save();
|
||||
|
||||
Session::flash('success', strval(trans('firefly.updated_user', ['email' => $user->email])));
|
||||
Preferences::mark();
|
||||
|
||||
if (intval($request->get('return_to_edit')) === 1) {
|
||||
// set value so edit routine will not overwrite URL:
|
||||
Session::put('users.edit.fromUpdate', true);
|
||||
|
||||
return redirect(route('admin.users.edit', [$user->id]))->withInput(['return_to_edit' => 1]);
|
||||
}
|
||||
|
||||
// redirect to previous URL.
|
||||
return redirect(session('users.edit.url'));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
60
app/Http/Requests/UserFormRequest.php
Normal file
60
app/Http/Requests/UserFormRequest.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* UserFormRequest.php
|
||||
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This software may be modified and distributed under the terms of the
|
||||
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
||||
*
|
||||
* See the LICENSE file for details.
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
|
||||
namespace FireflyIII\Http\Requests;
|
||||
|
||||
/**
|
||||
* Class UserFormRequest
|
||||
*
|
||||
*
|
||||
* @package FireflyIII\Http\Requests
|
||||
*/
|
||||
class UserFormRequest extends Request
|
||||
{
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
// Only allow logged in users
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getUserData(): array
|
||||
{
|
||||
return [
|
||||
'email' => trim($this->get('email')),
|
||||
'blocked' => intval($this->get('blocked')),
|
||||
'blocked_code' => trim($this->get('blocked_code')),
|
||||
'password' => trim($this->get('password')),
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'id' => 'required|exists:users,id',
|
||||
'email' => 'required',
|
||||
'password' => 'confirmed',
|
||||
'blocked_code' => 'between:0,30',
|
||||
'blocked' => 'between:0,1|numeric',
|
||||
];
|
||||
}
|
||||
}
|
@ -341,6 +341,24 @@ class ExpandedForm
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $value
|
||||
* @param array $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function password(string $name, array $options = []): string
|
||||
{
|
||||
$label = $this->label($name, $options);
|
||||
$options = $this->expandOptionArray($name, $label, $options);
|
||||
$classes = $this->getHolderClasses($name);
|
||||
$html = view('form.password', compact('classes', 'name', 'label', 'value', 'options'))->render();
|
||||
|
||||
return $html;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param null $value
|
||||
|
@ -23,7 +23,7 @@ declare(strict_types = 1);
|
||||
|
|
||||
*/
|
||||
|
||||
bcscale(4);
|
||||
bcscale(6);
|
||||
|
||||
|
||||
$app = new Illuminate\Foundation\Application(
|
||||
|
@ -159,7 +159,7 @@ return [
|
||||
'ExpandedForm' => [
|
||||
'is_safe' => [
|
||||
'date', 'text', 'select', 'balance', 'optionsList', 'checkbox', 'amount', 'tags', 'integer', 'textarea', 'location',
|
||||
'multiRadio', 'file', 'multiCheckbox', 'staticText', 'amountSmall',
|
||||
'multiRadio', 'file', 'multiCheckbox', 'staticText', 'amountSmall', 'password',
|
||||
],
|
||||
],
|
||||
'Form' => [
|
||||
|
@ -857,6 +857,9 @@ return [
|
||||
'mail_for_blocked_email_help' => 'When a user tries to register using a blocked email address',
|
||||
'mail_for_bad_login_help' => 'When a user fails to login',
|
||||
'mail_for_blocked_login_help' => 'When a blocked user tries to login',
|
||||
'block_code_bounced' => 'Email message(s) bounced',
|
||||
'block_code_expired' => 'Demo account expired',
|
||||
'no_block_code' => 'No reason for block or user not blocked',
|
||||
|
||||
|
||||
// split a transaction:
|
||||
|
@ -150,28 +150,35 @@ return [
|
||||
'category_keep_transactions' => 'The only transaction connected to this category will not be deleted.|All :count transactions connected to this category will spared deletion.',
|
||||
'tag_keep_transactions' => 'The only transaction connected to this tag will not be deleted.|All :count transactions connected to this tag will spared deletion.',
|
||||
|
||||
'email' => 'Email address',
|
||||
'password' => 'Password',
|
||||
'password_confirmation' => 'Password (again)',
|
||||
'blocked' => 'Is blocked?',
|
||||
'blocked_code' => 'Reason for block',
|
||||
|
||||
|
||||
// admin
|
||||
'domain' => 'Domain',
|
||||
'single_user_mode' => 'Single user mode',
|
||||
'must_confirm_account' => 'New users must activate account',
|
||||
'is_demo_site' => 'Is demo site',
|
||||
'mail_for_lockout' => 'Locked out',
|
||||
'mail_for_blocked_domain' => 'Blocked domain',
|
||||
'mail_for_blocked_email' => 'Blocked email address',
|
||||
'mail_for_bad_login' => 'Login failure',
|
||||
'mail_for_blocked_login' => 'Blocked user',
|
||||
'domain' => 'Domain',
|
||||
'single_user_mode' => 'Single user mode',
|
||||
'must_confirm_account' => 'New users must activate account',
|
||||
'is_demo_site' => 'Is demo site',
|
||||
'mail_for_lockout' => 'Locked out',
|
||||
'mail_for_blocked_domain' => 'Blocked domain',
|
||||
'mail_for_blocked_email' => 'Blocked email address',
|
||||
'mail_for_bad_login' => 'Login failure',
|
||||
'mail_for_blocked_login' => 'Blocked user',
|
||||
|
||||
|
||||
// import
|
||||
'import_file' => 'Import file',
|
||||
'configuration_file' => 'Configuration file',
|
||||
'import_file_type' => 'Import file type',
|
||||
'csv_comma' => 'A comma (,)',
|
||||
'csv_semicolon' => 'A semicolon (;)',
|
||||
'csv_tab' => 'A tab (invisible)',
|
||||
'csv_delimiter' => 'CSV field delimiter',
|
||||
'csv_import_account' => 'Default import account',
|
||||
'csv_config' => 'CSV import configuration',
|
||||
'import_file' => 'Import file',
|
||||
'configuration_file' => 'Configuration file',
|
||||
'import_file_type' => 'Import file type',
|
||||
'csv_comma' => 'A comma (,)',
|
||||
'csv_semicolon' => 'A semicolon (;)',
|
||||
'csv_tab' => 'A tab (invisible)',
|
||||
'csv_delimiter' => 'CSV field delimiter',
|
||||
'csv_import_account' => 'Default import account',
|
||||
'csv_config' => 'CSV import configuration',
|
||||
|
||||
|
||||
'due_date' => 'Due date',
|
||||
|
@ -12,6 +12,7 @@
|
||||
return [
|
||||
'buttons' => 'Buttons',
|
||||
'icon' => 'Icon',
|
||||
'id' => 'ID',
|
||||
'create_date' => 'Created at',
|
||||
'update_date' => 'Updated at',
|
||||
'balance_before' => 'Balance before',
|
||||
|
@ -4,11 +4,44 @@
|
||||
{{ Breadcrumbs.renderIfExists(Route.getCurrentRoute.getName, user) }}
|
||||
{% endblock %}
|
||||
{% block content %}
|
||||
|
||||
|
||||
{{ Form.model(user, {'class' : 'form-horizontal','id' : 'update','url' : route('admin.users.update',user.id) } ) }}
|
||||
|
||||
<input type="hidden" name="id" value="{{ user.id }}"/>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<p>
|
||||
This page is empty.
|
||||
</p>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<div class="box box-primary">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'mandatoryFields'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{{ ExpandedForm.text('email') }}
|
||||
{{ ExpandedForm.password('password') }}
|
||||
{{ ExpandedForm.password('password_confirmation') }}
|
||||
{{ ExpandedForm.checkbox('blocked') }}
|
||||
{{ ExpandedForm.select('blocked_code', codes, user.blocked_code) }}
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-12">
|
||||
<!-- panel for options -->
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'options'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
{{ ExpandedForm.optionsList('update','account') }}
|
||||
</div>
|
||||
<div class="box-footer">
|
||||
<button type="submit" class="btn pull-right btn-success">
|
||||
{{ ('update_user')|_ }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ Form.close|raw }}
|
||||
{% endblock %}
|
||||
|
9
resources/views/form/password.twig
Normal file
9
resources/views/form/password.twig
Normal file
@ -0,0 +1,9 @@
|
||||
<div class="{{ classes }}" id="{{ name }}_holder">
|
||||
<label for="{{ options.id }}" class="col-sm-4 control-label">{{ label }}</label>
|
||||
|
||||
<div class="col-sm-8">
|
||||
{{ Form.input('password', name, value, options) }}
|
||||
{% include 'form/help' %}
|
||||
{% include 'form/feedback' %}
|
||||
</div>
|
||||
</div>
|
@ -676,6 +676,7 @@ Route::group(
|
||||
Route::get('users', ['uses' => 'UserController@index', 'as' => 'users']);
|
||||
Route::get('users/edit/{user}', ['uses' => 'UserController@edit', 'as' => 'users.edit']);
|
||||
Route::get('users/show/{user}', ['uses' => 'UserController@show', 'as' => 'users.show']);
|
||||
Route::post('users/update/{user}', ['uses' => 'UserController@update', 'as' => 'users.update']);
|
||||
|
||||
// user domain manager
|
||||
Route::get('domains', ['uses' => 'DomainController@domains', 'as' => 'users.domains']);
|
||||
|
Loading…
Reference in New Issue
Block a user