mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-11-29 11:43:26 +01:00
Change Settings attributes and routes
This commit is contained in:
parent
8dc5e7d6e9
commit
361ee38cf2
@ -39,8 +39,8 @@ public function index()
|
||||
$settingsResources = collect();
|
||||
$settings->each(function ($item, $key) use ($settingsResources) {
|
||||
$settingsResources->push([
|
||||
'name' => $key,
|
||||
'data' => $item
|
||||
'key' => $key,
|
||||
'value' => $item
|
||||
]);
|
||||
});
|
||||
|
||||
@ -52,21 +52,21 @@ public function index()
|
||||
/**
|
||||
* Display a resource
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $settingName
|
||||
*
|
||||
* @return \App\Http\Resources\TwoFAccountReadResource
|
||||
*/
|
||||
public function show($name)
|
||||
public function show($settingName)
|
||||
{
|
||||
$setting = $this->settingService->get($name);
|
||||
$setting = $this->settingService->get($settingName);
|
||||
|
||||
if (!$setting) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'name' => $name,
|
||||
'data' => $setting
|
||||
'key' => $settingName,
|
||||
'value' => $setting
|
||||
], 200);
|
||||
}
|
||||
|
||||
@ -79,11 +79,11 @@ public function store(SettingStoreRequest $request)
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
$this->settingService->set($validated['name'], $validated['data']);
|
||||
$this->settingService->set($validated['key'], $validated['value']);
|
||||
|
||||
return response()->json([
|
||||
'name' => $validated['name'],
|
||||
'data' => $validated['data']
|
||||
'key' => $validated['key'],
|
||||
'value' => $validated['value']
|
||||
], 201);
|
||||
}
|
||||
|
||||
@ -92,21 +92,15 @@ public function store(SettingStoreRequest $request)
|
||||
* Save options
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function update(SettingUpdateRequest $request, $name)
|
||||
public function update(SettingUpdateRequest $request, $settingName)
|
||||
{
|
||||
$validated = $request->validated();
|
||||
|
||||
$setting = $this->settingService->get($name);
|
||||
|
||||
if (is_null($setting)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$setting = $this->settingService->set($name, $validated['data']);
|
||||
$this->settingService->set($settingName, $validated['value']);
|
||||
|
||||
return response()->json([
|
||||
'name' => $name,
|
||||
'data' => $validated['data']
|
||||
'key' => $settingName,
|
||||
'value' => $validated['value']
|
||||
], 200);
|
||||
|
||||
// The useEncryption option impacts the [existing] content of the database.
|
||||
@ -138,23 +132,23 @@ public function update(SettingUpdateRequest $request, $name)
|
||||
* Save options
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function destroy($name)
|
||||
public function destroy($settingName)
|
||||
{
|
||||
$setting = $this->settingService->get($name);
|
||||
$setting = $this->settingService->get($settingName);
|
||||
|
||||
if (is_null($setting)) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
$optionsConfig = config('app.options');
|
||||
if(array_key_exists($name, $optionsConfig)) {
|
||||
if(array_key_exists($settingName, $optionsConfig)) {
|
||||
return response()->json(
|
||||
['message' => 'bad request',
|
||||
'reason' => [__('errors.delete_user_setting_only')]
|
||||
], 400);
|
||||
}
|
||||
|
||||
$this->settingService->delete($name);
|
||||
$this->settingService->delete($settingName);
|
||||
|
||||
return response()->json(null, 204);
|
||||
}
|
||||
|
@ -24,8 +24,8 @@ public function authorize()
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'name' => 'required|alpha|max:128|unique:options,key',
|
||||
'data' => 'required',
|
||||
'key' => 'required|alpha|max:128|unique:options,key',
|
||||
'value' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ public function authorize()
|
||||
public function rules()
|
||||
{
|
||||
return [
|
||||
'data' => 'required',
|
||||
'value' => 'required',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ class RouteServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
Route::pattern('settingName', '[a-zA-Z]+');
|
||||
|
||||
parent::boot();
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ public function delete($ids) : int
|
||||
* @param Group $group The target group
|
||||
* @return Group The updated group
|
||||
*/
|
||||
public function assign(mixed $ids, Group $group = null) : Group
|
||||
public function assign($ids, Group $group = null) : Group
|
||||
{
|
||||
if (!$group) {
|
||||
$group = $this->destinationGroup();
|
||||
|
@ -38,11 +38,11 @@
|
||||
// Route::post('options', 'Settings\OptionController@store');
|
||||
// });
|
||||
|
||||
Route::get('settings/{name}', 'SettingController@show');
|
||||
Route::get('settings/{settingName}', 'SettingController@show');
|
||||
Route::get('settings', 'SettingController@index');
|
||||
Route::post('settings', 'SettingController@store');
|
||||
Route::put('settings/{name}', 'SettingController@update');
|
||||
Route::delete('settings/{name}', 'SettingController@destroy');
|
||||
Route::put('settings/{settingName}', 'SettingController@update');
|
||||
Route::delete('settings/{settingName}', 'SettingController@destroy');
|
||||
|
||||
Route::delete('twofaccounts', 'TwoFAccountController@batchDestroy');
|
||||
Route::patch('twofaccounts/withdraw', 'TwoFAccountController@withdraw');
|
||||
|
Loading…
Reference in New Issue
Block a user