administration tool
This commit is contained in:
parent
22a21da722
commit
c947acf8bb
81
adminer/index.html
Normal file
81
adminer/index.html
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" src="style.css" />
|
||||||
|
<title>Contact mailer admin interface</title>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<main id="app">
|
||||||
|
<section>
|
||||||
|
<h3>Athentification</h3>
|
||||||
|
<div v-if="!loggedin" class="loginform">
|
||||||
|
<form v-on:submit.prevent="login">
|
||||||
|
<select v-model="type">
|
||||||
|
<option value="token">Utilisateur</option>
|
||||||
|
<option value="admin_pass">Administrateur</option>
|
||||||
|
</select>
|
||||||
|
<input type="password" v-model="password" />
|
||||||
|
<input type="submit" value="connect" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
<div v-else="">
|
||||||
|
<p>Connecté en tant que {{ type }}</p>
|
||||||
|
<button v-on:click="logout">Se déconnecter</button>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<div v-if="loggedin && type=='admin_pass'">
|
||||||
|
<h3>Utilisateurices</h3>
|
||||||
|
<form v-on:submit.prevent="addUser">
|
||||||
|
<input type="text" v-model="newUser" />
|
||||||
|
<input type="submit" />
|
||||||
|
</form>
|
||||||
|
<button v-on:click="getUsers">Rafraichir les utilisateurs</button>
|
||||||
|
<ul>
|
||||||
|
<li v-for="user in users">{{user.token}} — {{user.username}}</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<section>
|
||||||
|
<h3>Formulaires</h3>
|
||||||
|
<button v-on:click="getForms">Rafraichir les formulaires</button>
|
||||||
|
<ul>
|
||||||
|
<li v-for="form in forms">
|
||||||
|
<div>À {{form.mail}}</div>
|
||||||
|
<div>Objet {{form.subject}}</div>
|
||||||
|
<div>{{form.content}}</div>
|
||||||
|
<div>{{form.token}} — {{form.honeypotfield}} — {{form.timerdelay}}</div>
|
||||||
|
<button v-on:click="deleteForm(form.token)">Supprimer</button>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<div v-if="page=='new_user'">
|
||||||
|
<form v-on:submit.prevent="addForm">
|
||||||
|
<label for="mail">Mail :</label>
|
||||||
|
<input v-model="newForm.mail" type="text" name="mail" id="mail" />
|
||||||
|
<br />
|
||||||
|
<label for="content">Contenu :</label>
|
||||||
|
<textarea v-model="newForm.content" name="content" id="content">
|
||||||
|
</textarea>
|
||||||
|
<br />
|
||||||
|
<label for="subject">Objet :</label>
|
||||||
|
<input v-model="newForm.subject" type="text" name="subject" id="subject" />
|
||||||
|
<br />
|
||||||
|
<label for="honeypot">Honeypot (ne pas toucher) :</label>
|
||||||
|
<input v-model="newForm.honeypotfield" type="text" name="honeypot" id="honeypot" />
|
||||||
|
<br />
|
||||||
|
<label for="timerdelay">Timer delay :</label>
|
||||||
|
<input v-model="newForm.timerdelay" type="number" name="timerdelay" id="timerdelay" />
|
||||||
|
<br />
|
||||||
|
<input type="submit" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
<script src="./vue.js"></script>
|
||||||
|
<script src="./index.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
124
adminer/index.js
Normal file
124
adminer/index.js
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
var app = new Vue({
|
||||||
|
el: '#app',
|
||||||
|
data: {
|
||||||
|
type: 'admin_pass', /* admin_pass or token */
|
||||||
|
password: 'test',
|
||||||
|
loggedin: false,
|
||||||
|
mailerHost: 'https://mailer.jean-cloud.net',
|
||||||
|
//mailerHost: 'http://localhost:8080',
|
||||||
|
//mailerHost: '/api',
|
||||||
|
forms: [],
|
||||||
|
users: [],
|
||||||
|
newUser: '',
|
||||||
|
page:'new_user',
|
||||||
|
newForm: {
|
||||||
|
'content': '{{message}}',
|
||||||
|
'subject': '[contact jean-cloud.net] {{nom|annonyme}} — {{objet}}',
|
||||||
|
'mail': 'contact@jean-cloud.org',
|
||||||
|
'honeypotfield': 'prenom',
|
||||||
|
'timerdelay': 5,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
login: function () {
|
||||||
|
if (!this.type) {
|
||||||
|
console.log('missing type')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!this.password) {
|
||||||
|
console.log('missing password')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.loggedin = true
|
||||||
|
this.getForms()
|
||||||
|
if ( this.type == 'admin_pass' )
|
||||||
|
this.getUsers()
|
||||||
|
},
|
||||||
|
logout: function () {
|
||||||
|
this.type = 'token'
|
||||||
|
this.password = null
|
||||||
|
this.loggedin = false
|
||||||
|
},
|
||||||
|
getForms: function () {
|
||||||
|
fetch(this.mailerHost + '/form/list', {
|
||||||
|
method: 'POST',
|
||||||
|
body: this.type + '=' + this.password
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.status != 'success')
|
||||||
|
console.error('getForms error: '+data.msg)
|
||||||
|
else
|
||||||
|
this.forms = data.data
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
getUsers: function () {
|
||||||
|
fetch(this.mailerHost + '/user/list', {
|
||||||
|
method: 'POST',
|
||||||
|
body: this.type + '=' + this.password
|
||||||
|
})
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
if (data.status != 'success')
|
||||||
|
console.error('getForms error: '+data.msg)
|
||||||
|
else
|
||||||
|
this.users = data.data
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
addForm: function () {
|
||||||
|
fetch(this.mailerHost + '/form', {
|
||||||
|
method: 'post',
|
||||||
|
body: this.type + '=' + this.password
|
||||||
|
+ '&subject=' + this.newForm.subject
|
||||||
|
+ '&mail=' + this.newForm.mail
|
||||||
|
+ '&content=' + this.newForm.content
|
||||||
|
+ '&honeypotfield=' + this.newForm.honeypotfield
|
||||||
|
+ '&timerdelay=' + this.newForm.timerdelay
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
console.log(data)
|
||||||
|
this.getForms()
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.log(error)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
addUser: function () {
|
||||||
|
if (!this.newUser) {
|
||||||
|
console.log('need username')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fetch(this.mailerHost + '/user/' + this.newUser, {
|
||||||
|
method: 'put',
|
||||||
|
body: this.type + '=' + this.password
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
this.newUser = ''
|
||||||
|
this.getUsers()
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error)
|
||||||
|
})
|
||||||
|
|
||||||
|
},
|
||||||
|
deleteForm: function (formId) {
|
||||||
|
fetch(this.mailerHost + '/form/' + formId, {
|
||||||
|
method: 'delete',
|
||||||
|
body: this.type + '=' + this.password
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
console.log(data)
|
||||||
|
this.getForms()
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error)
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
11965
adminer/vue.js
Normal file
11965
adminer/vue.js
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user