mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-01-23 06:38:34 +01:00
Handle Language setting from Laravel side
This commit is contained in:
parent
53d8cce838
commit
b30219f407
39
app/Http/Controllers/SettingController.php
Normal file
39
app/Http/Controllers/SettingController.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class SettingController extends Controller
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Get options
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
// Fetch all setting values
|
||||
$settings = DB::table('options')->get();
|
||||
|
||||
return response()->json(['settings' => $settings], 200);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save options
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
// Store all setting values
|
||||
foreach($request->all() as $opt => $val) {
|
||||
option([$opt => $val]);
|
||||
$settings[$opt] = option($opt);
|
||||
}
|
||||
|
||||
return response()->json(['message' => __('settings.forms.setting_saved'), 'settings' => $settings], 200);
|
||||
}
|
||||
}
|
@ -19,6 +19,7 @@ class Kernel extends HttpKernel
|
||||
\App\Http\Middleware\TrimStrings::class,
|
||||
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
|
||||
\App\Http\Middleware\TrustProxies::class,
|
||||
\App\Http\Middleware\SetLanguage::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
22
app/Http/Middleware/SetLanguage.php
Normal file
22
app/Http/Middleware/SetLanguage.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
|
||||
class SetLanguage
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle($request, Closure $next)
|
||||
{
|
||||
\App::setLocale(option('lang', 'en'));
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
6
resources/js/langs/locales.js
vendored
6
resources/js/langs/locales.js
vendored
@ -76,7 +76,8 @@ export default {
|
||||
"language": "Language",
|
||||
"confirm": [],
|
||||
"forms": {
|
||||
"edit_settings": "Edit settings"
|
||||
"edit_settings": "Edit settings",
|
||||
"setting_saved": "Settings saved"
|
||||
}
|
||||
},
|
||||
"twofaccounts": {
|
||||
@ -323,7 +324,8 @@ export default {
|
||||
"language": "Langue",
|
||||
"confirm": [],
|
||||
"forms": {
|
||||
"edit_settings": "Modifier les réglages"
|
||||
"edit_settings": "Modifier les réglages",
|
||||
"setting_saved": "Réglages sauvegardés"
|
||||
}
|
||||
},
|
||||
"twofaccounts": {
|
||||
|
@ -17,7 +17,7 @@
|
||||
success: '',
|
||||
fail: '',
|
||||
form: new Form({
|
||||
lang: 'fr'
|
||||
lang: ''
|
||||
}),
|
||||
options: [
|
||||
{ text: this.$t('languages.en'), value: 'en' },
|
||||
@ -26,8 +26,35 @@
|
||||
}
|
||||
},
|
||||
|
||||
methods : {
|
||||
async mounted() {
|
||||
|
||||
const { data } = await this.axios.get('/api/settings')
|
||||
|
||||
data.settings.forEach((setting) => {
|
||||
this.form[setting.key] = setting.value
|
||||
})
|
||||
},
|
||||
|
||||
methods : {
|
||||
handleSubmit(e) {
|
||||
e.preventDefault()
|
||||
|
||||
this.fail = ''
|
||||
this.success = ''
|
||||
|
||||
this.form.post('/api/settings', {returnError: true})
|
||||
.then(response => {
|
||||
this.$router.go()
|
||||
})
|
||||
.catch(error => {
|
||||
if( error.response.status === 400 ) {
|
||||
this.fail = error.response.data.message
|
||||
}
|
||||
else if( error.response.status !== 422 ) {
|
||||
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
}
|
||||
</script>
|
@ -22,6 +22,7 @@
|
||||
],
|
||||
'forms' => [
|
||||
'edit_settings' => 'Edit settings',
|
||||
'setting_saved' => 'Settings saved',
|
||||
],
|
||||
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
],
|
||||
'forms' => [
|
||||
'edit_settings' => 'Modifier les réglages',
|
||||
'setting_saved' => 'Réglages sauvegardés',
|
||||
],
|
||||
|
||||
|
||||
|
@ -31,6 +31,9 @@
|
||||
Route::patch('user', 'UserController@update');
|
||||
Route::get('user', 'UserController@getDetails');
|
||||
|
||||
Route::get('settings', 'SettingController@index');
|
||||
Route::post('settings', 'SettingController@store');
|
||||
|
||||
Route::delete('twofaccounts/batch', 'TwoFAccountController@batchDestroy');
|
||||
Route::apiResource('twofaccounts', 'TwoFAccountController');
|
||||
Route::post('twofaccounts/otp', 'TwoFAccountController@generateOTP')->name('twofaccounts.generateOTP');
|
||||
|
Loading…
Reference in New Issue
Block a user