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