Browse Source

storeId added to create client

pull/468/head
tm-sanjay 4 years ago
parent
commit
153be8c644
  1. 10
      src/lib/Server.js
  2. 4
      src/lib/WireGuard.js
  3. 11
      src/www/index.html
  4. 4
      src/www/js/api.js
  5. 5
      src/www/js/app.js

10
src/lib/Server.js

@ -109,8 +109,14 @@ module.exports = class Server {
res.send(config); res.send(config);
})) }))
.post('/api/wireguard/client', Util.promisify(async req => { .post('/api/wireguard/client', Util.promisify(async req => {
const { name } = req.body; const { name , storeId } = req.body;
return WireGuard.createClient({ name }); if (name === undefined) {
throw new ServerError('Missing: Name', 400);
}
if (storeId === undefined) {
throw new ServerError('Missing: StoreId', 400);
}
return WireGuard.createClient({ name , storeId});
})) }))
.delete('/api/wireguard/client/:clientId', Util.promisify(async req => { .delete('/api/wireguard/client/:clientId', Util.promisify(async req => {
const { clientId } = req.params; const { clientId } = req.params;

4
src/lib/WireGuard.js

@ -224,7 +224,7 @@ Endpoint = ${localIP}:${WG_PORT}`;
}); });
} }
async createClient({ name }) { async createClient({ name , storeId }) {
if (!name) { if (!name) {
throw new Error('Missing: Name'); throw new Error('Missing: Name');
} }
@ -275,11 +275,11 @@ Endpoint = ${localIP}:${WG_PORT}`;
const clientId = uuid.v4(); const clientId = uuid.v4();
const client = { const client = {
name, name,
storeId,
address, address,
privateKey, privateKey,
publicKey, publicKey,
// preSharedKey, //unclear generation of preSharedKey // preSharedKey, //unclear generation of preSharedKey
createdAt: new Date(), createdAt: new Date(),
updatedAt: new Date(), updatedAt: new Date(),

11
src/www/index.html

@ -60,7 +60,7 @@
<p class="text-2xl font-medium">Clients</p> <p class="text-2xl font-medium">Clients</p>
</div> </div>
<div class="flex-shrink-0"> <div class="flex-shrink-0">
<button @click="clientCreate = true; clientCreateName = '';" <button @click="clientCreate = true; clientCreateName = ''; clientCreateStoreId = '';"
class="hover:bg-red-800 hover:border-red-800 hover:text-white text-gray-700 border-2 border-gray-100 py-2 px-4 rounded inline-flex items-center transition"> class="hover:bg-red-800 hover:border-red-800 hover:text-white text-gray-700 border-2 border-gray-100 py-2 px-4 rounded inline-flex items-center transition">
<svg class="w-4 mr-2" inline xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" <svg class="w-4 mr-2" inline xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
stroke="currentColor"> stroke="currentColor">
@ -281,7 +281,7 @@
</div> </div>
<div v-if="clients && clients.length === 0"> <div v-if="clients && clients.length === 0">
<p class="text-center m-10 text-gray-400 text-sm">There are no clients yet.<br /><br /> <p class="text-center m-10 text-gray-400 text-sm">There are no clients yet.<br /><br />
<button @click="clientCreate = true; clientCreateName = '';" <button @click="clientCreate = true; clientCreateName = ''; clientCreateStoreId = '';"
class="bg-red-800 text-white hover:bg-red-700 border-2 border-none py-2 px-4 rounded inline-flex items-center transition"> class="bg-red-800 text-white hover:bg-red-700 border-2 border-none py-2 px-4 rounded inline-flex items-center transition">
<svg class="w-4 mr-2" inline xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" <svg class="w-4 mr-2" inline xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24"
stroke="currentColor"> stroke="currentColor">
@ -368,14 +368,17 @@
<div class="mt-2"> <div class="mt-2">
<p class="text-sm text-gray-500"> <p class="text-sm text-gray-500">
<input class="rounded p-2 border-2 border-gray-100 focus:border-gray-200 outline-none w-full" <input class="rounded p-2 border-2 border-gray-100 focus:border-gray-200 outline-none w-full"
type="text" v-model.trim="clientCreateName" placeholder="Name" /> type="text" v-model.trim="clientCreateName" placeholder="Name"/>
<input class="rounded p-2 border-2 border-gray-100 focus:border-gray-200 outline-none w-full"
type="text" v-model.trim="clientCreateStoreId" placeholder="Store Id" style="margin-top: 5%;"/>
</p> </p>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
<div class="bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse"> <div class="bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
<button v-if="clientCreateName.length" type="button" @click="createClient(); clientCreate = null" <button v-if="clientCreateName.length && clientCreateStoreId.length" type="button" @click="createClient(); clientCreate = null"
class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-red-800 text-base font-medium text-white hover:bg-red-700 focus:outline-none sm:ml-3 sm:w-auto sm:text-sm"> class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-red-800 text-base font-medium text-white hover:bg-red-700 focus:outline-none sm:ml-3 sm:w-auto sm:text-sm">
Create Create
</button> </button>

4
src/www/js/api.js

@ -72,11 +72,11 @@ class API {
}))); })));
} }
async createClient({ name }) { async createClient({ name , storeId}) {
return this.call({ return this.call({
method: 'post', method: 'post',
path: '/wireguard/client', path: '/wireguard/client',
body: { name }, body: { name , storeId },
}); });
} }

5
src/www/js/app.js

@ -36,6 +36,7 @@ new Vue({
clientDelete: null, clientDelete: null,
clientCreate: null, clientCreate: null,
clientCreateName: '', clientCreateName: '',
clientCreateStoreId: '',
clientEditName: null, clientEditName: null,
clientEditNameId: null, clientEditNameId: null,
clientEditAddress: null, clientEditAddress: null,
@ -208,9 +209,11 @@ new Vue({
}, },
createClient() { createClient() {
const name = this.clientCreateName; const name = this.clientCreateName;
const storeId = this.clientCreateStoreId;
if (!name) return; if (!name) return;
if (!storeId) return;
this.api.createClient({ name }) this.api.createClient({ name , storeId })
.catch(err => alert(err.message || err.toString())) .catch(err => alert(err.message || err.toString()))
.finally(() => this.refresh().catch(console.error)); .finally(() => this.refresh().catch(console.error));
}, },

Loading…
Cancel
Save