Define accountCount internally instead of as a props

This commit is contained in:
Bubka 2020-11-21 19:41:36 +01:00
parent 1864378c74
commit b4ce39e9d5
4 changed files with 26 additions and 5 deletions

View File

@ -256,6 +256,18 @@ class TwoFAccountController extends Controller
} }
/**
* A simple and light method to get the account count.
*
* @param \App\TwoFAccount $twofaccount
* @return \Illuminate\Http\Response
*/
public function count(Request $request)
{
return response()->json([ 'count' => TwoFAccount::count() ], 200);
}
/** /**
* Remove the specified resource from storage. * Remove the specified resource from storage.
* *

View File

@ -261,7 +261,7 @@
this.$router.push({ name: 'createAccount' }) this.$router.push({ name: 'createAccount' })
} }
else { else {
this.$router.push({ name: 'start', params: { accountCount: this.accounts.length } }) this.$router.push({ name: 'start' })
} }
}, },
@ -280,9 +280,9 @@
}) })
}) })
// No account yet, we push user to the start view // No account yet, we force user to land on the start view.
if( this.accounts.length === 0 ) { if( this.accounts.length === 0 ) {
this.$router.push({ name: 'start', params: { accountCount: 0 } }); this.$router.push({ name: 'start' });
} }
}) })
}, },

View File

@ -45,7 +45,7 @@
</div> </div>
</div> </div>
<!-- Footer --> <!-- Footer -->
<vue-footer :showButtons="true"> <vue-footer :showButtons="true" v-if="accountCount > 0">
<!-- back button --> <!-- back button -->
<p class="control"> <p class="control">
<router-link class="button is-dark is-rounded" :to="{ name: 'accounts' }" > <router-link class="button is-dark is-rounded" :to="{ name: 'accounts' }" >
@ -109,6 +109,7 @@
data(){ data(){
return { return {
accountCount: null,
form: new Form({ form: new Form({
qrcode: null, qrcode: null,
uri: '', uri: '',
@ -121,7 +122,14 @@
} }
}, },
props: ['accountCount'], // props: ['accountCount'],
mounted() {
this.axios.get('api/twofaccounts/count').then(response => {
this.accountCount = response.data.count
})
},
created() { created() {

View File

@ -40,6 +40,7 @@ Route::group(['middleware' => 'auth:api'], function() {
Route::patch('twofaccounts/reorder', 'TwoFAccountController@reorder'); Route::patch('twofaccounts/reorder', 'TwoFAccountController@reorder');
Route::post('twofaccounts/preview', 'TwoFAccountController@preview'); Route::post('twofaccounts/preview', 'TwoFAccountController@preview');
Route::get('twofaccounts/{twofaccount}/withSensitive', 'TwoFAccountController@showWithSensitive'); Route::get('twofaccounts/{twofaccount}/withSensitive', 'TwoFAccountController@showWithSensitive');
Route::get('twofaccounts/count', 'TwoFAccountController@count');
Route::apiResource('twofaccounts', 'TwoFAccountController'); Route::apiResource('twofaccounts', 'TwoFAccountController');
Route::patch('group/accounts', 'GroupController@associateAccounts'); Route::patch('group/accounts', 'GroupController@associateAccounts');
Route::apiResource('groups', 'GroupController'); Route::apiResource('groups', 'GroupController');