Commit 62b80078 authored by Nacim Goura's avatar Nacim Goura

add gestion account and update dependencies

parent 7a2af955
......@@ -44,3 +44,4 @@ practicalmeteor:chai
# other packages
deanius:promise
dynamic-import
aldeed:tabular
......@@ -3,6 +3,7 @@ accounts-password@1.3.6
alanning:roles@1.2.16
aldeed:autoform@6.2.0
aldeed:collection2-core@2.0.1
aldeed:tabular@2.1.1
allow-deny@1.0.5
autoupdate@1.3.12
babel-compiler@6.19.2
......
import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import { Accounts } from 'meteor/accounts-base';
Meteor.methods({
addAccount(user) {
check(user, Object);
const id = Accounts.createUser(user);
if (!id) {
throw new Meteor.Error('Error', 'Impossible de se connecter');
}
},
deleteAccount(id) {
check(id, String);
Meteor.users.remove({ _id: id });
},
});
......@@ -60,7 +60,7 @@ export default class IndexGeneric {
query: term,
fuzziness: 'AUTO',
fields: [
'description',
'title.stemmed',
'description.stemmed',
'body',
'body.stemmed',
......@@ -76,7 +76,7 @@ export default class IndexGeneric {
fuzziness: 'AUTO',
fields: [
'title',
'title.stemmed',
'description',
'url',
'breadcrumb',
'h1',
......
......@@ -17,6 +17,17 @@ adminSection.route('/', {
},
});
adminSection.route('/account', {
name: 'account',
action() {
BlazeLayout.render('mainLayoutTpl', {
sidebar: 'sidebarLayoutTpl',
main: 'accountTpl',
navbar: 'navbarLayoutTpl',
});
},
});
adminSection.route('/stat', {
name: 'statistique',
action() {
......
......@@ -12,9 +12,9 @@ import '../../ui/layouts/sidebar/sidebar';
// Import page templates
import '../../ui/pages/home/home';
import '../../ui/pages/login/login';
import '../../ui/pages/register/register';
import '../../ui/pages/not-found/not-found';
import '../../ui/pages/admin/indexation/indexation';
import '../../ui/pages/admin/account/account';
import '../../ui/pages/admin/statistique/statistique';
// Set up all routes in the app
......@@ -54,16 +54,6 @@ FlowRouter.route('/logout', {
},
});
FlowRouter.route('/register', {
name: 'register',
action() {
BlazeLayout.render('mainLayoutTpl', {
main: 'registerTpl',
navbar: 'navbarLayoutTpl',
});
},
});
FlowRouter.notFound = {
action() {
BlazeLayout.render('mainLayoutTpl', {
......
// Register your apis here
import '../../api/indexation/methods';
import '../../api/account/methods';
import '../../tabular/tabularUser';
<template name="accountActionTable">
<button type="button" class="btn btn-xs btn-danger delete-account">Supprimer</button>
</template>
import Tabular from 'meteor/aldeed:tabular';
import { Meteor } from 'meteor/meteor';
new Tabular.Table({
name: 'Accounts',
collection: Meteor.users,
columns: [
{
data: 'username', title: 'Nom',
},
{
data: 'emails[0].address', title: 'Email',
},
{
tmpl: Meteor.isClient && Template.accountActionTable,
},
],
selector() {
return { roles: null };
},
pageLength: 20,
language: {
sProcessing: 'Traitement en cours...',
sSearch: 'Rechercher&nbsp;:',
sLengthMenu: 'Afficher _MENU_ &eacute;l&eacute;ments',
sInfo: "Affichage de l'&eacute;l&eacute;ment _START_ &agrave; _END_ sur _TOTAL_ &eacute;l&eacute;ments",
sInfoEmpty: "Affichage de l'&eacute;l&eacute;ment 0 &agrave; 0 sur 0 &eacute;l&eacute;ment",
sInfoFiltered: '(filtr&eacute; de _MAX_ &eacute;l&eacute;ments au total)',
sInfoPostFix: '',
sLoadingRecords: 'Chargement en cours...',
sZeroRecords: 'Aucun &eacute;l&eacute;ment &agrave; afficher',
sEmptyTable: 'Aucune donn&eacute;e disponible dans le tableau',
oPaginate: {
sFirst: 'Premier',
sPrevious: 'Pr&eacute;c&eacute;dent',
sNext: 'Suivant',
sLast: 'Dernier',
},
oAria: {
sSortAscending: ': activer pour trier la colonne par ordre croissant',
sSortDescending: ': activer pour trier la colonne par ordre d&eacute;croissant',
},
},
});
......@@ -10,6 +10,9 @@
<li>
<a href="/admin"><i class="fa fa-fw fa-etsy fa-20px" aria-hidden="true"></i> Indexation</a>
</li>
<li>
<a href="/admin/account"><i class="fa fa-fw fa-user fa-20px" aria-hidden="true"></i> Comptes</a>
</li>
<li>
<a href="/admin/stat"><i class="fa fa-fw fa-bar-chart-o fa-20px" aria-hidden="true"></i> Statistiques</a>
</li>
......
<template name="accountTpl">
<!-- accountTpl -->
{{> tabsTpl module="account"}}
{{> Template.dynamic template=template}}
</template>
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import { Session } from 'meteor/session';
import TabsCollection from '../../../../collections/tabsCollection';
import '../../../components/tabs/tabs';
import './list/list';
import './add/add';
import './account.html';
/**
* define tab depending on session
*/
Template.accountTpl.onCreated(() => {
Session.set('account', null);
const tabs = Meteor.settings.public.tabs.account;
TabsCollection.remove({});
tabs.forEach((tab) => {
TabsCollection.insert(tab);
});
});
/**
* change template dynamically
*/
Template.accountTpl.helpers({
template() {
const currentTab = Session.get('account');
return currentTab.layout;
},
});
<template name="addAccountTpl">
<!-- Template addAccountTpl -->
<div class="panel panel-default wrapper">
<div class="panel-body">
<h3 class="text-center">Ajouter un compte</h3>
</div>
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-primary">
<form class="register-form">
<div class="panel-body">
<div class="form-group">
<label class="control-label">Nom</label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-user fa"></i>
</span>
<input type="text" class="form-control" name="username" placeholder="Nom"/>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label">Email</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-envelope fa"></i>
</span>
<input type="text" class="form-control" name="email" placeholder="Email"/>
</div>
</div>
<div class="form-group">
<label class="control-label">Mot de passe</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-lock fa-lg"></i>
</span>
<input type="password" class="form-control" name="password" placeholder="Mot de passe"/>
</div>
</div>
</div>
<div class="panel-footer">
<div class="form-group ">
<button type="submit" class="btn btn-primary btn-lg btn-block">
Ajouter
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</template>
import { Meteor } from 'meteor/meteor';
import { FlowRouter } from 'meteor/kadira:flow-router';
import { Accounts } from 'meteor/accounts-base';
import { Template } from 'meteor/templating';
import displayNotif from '../../components/notifs/notifs';
import displayNotif from '../../../../components/notifs/notifs';
import './register.html';
import './add.html';
Template.registerTpl.helpers({
roles: () => Meteor.roles.find({}),
});
Template.registerTpl.events({
Template.addAccountTpl.events({
'submit form': (event) => {
event.preventDefault();
const user = {
username: event.target.username.value,
email: event.target.email.value,
password: event.target.password.value,
name: event.target.name.value,
username: event.target.username.value,
roles: [],
};
// Ask user creation on server side
Accounts.createUser(user, (err) => {
if (err) {
displayNotif({
type: 'error',
title: 'Erreur : ',
message: 'Impossible de vous inscrire!',
});
} else {
FlowRouter.go('/');
event.target.username.value = '';
event.target.email.value = '';
event.target.password.value = '';
Meteor.callPromise('addAccount', user)
.then(() => {
displayNotif({
type: 'success',
title: 'Succès : ',
message: 'Vous êtes maintenant inscrit!',
message: 'Compte ajouté avec succès!',
});
})
.catch((err) => {
displayNotif({
type: 'error',
title: 'Erreur : ',
message: err.message,
});
}
});
});
},
});
<template name="listAccountTpl">
<!-- Template listAccountTpl -->
<div class="panel panel-default wrapper">
<div class="panel-body">
<h3 class="text-center">Liste des comptes existants</h3>
</div>
{{> tabular table=TabularTables.Accounts class="table table-striped table-bordered table-condensed text-center"}}
</div>
</template>
import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating';
import dataTablesBootstrap from 'datatables.net-bs';
import 'datatables.net-bs/css/dataTables.bootstrap.css';
import displayNotif from '../../../../components/notifs/notifs';
import '../../../../../tabular/buttonTabular.html';
import '../../../../../tabular/tabularUser';
import './list.html';
dataTablesBootstrap(window, $);
Template.accountActionTable.events({
'click .delete-account': function () {
Meteor.callPromise('deleteAccount', this._id)
.then(() => {
displayNotif({
type: 'success',
title: 'Succès : ',
message: 'Compte supprimé avec succès!',
});
})
.catch((err) => {
displayNotif({
type: 'error',
title: 'Erreur : ',
message: err.message,
});
});
},
});
import { Template } from 'meteor/templating';
import './api.html';
<template name="registerTpl">
<!-- template registerTpl -->
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel panel-primary">
<div class="panel-heading">
<div class="panel-title text-center">
<h3>Inscription</h3>
<small>Déjà inscris ? <a href="/login">Connexion</a></small>
</div>
</div>
<form class="register-form">
<div class="panel-body">
<div class="form-group">
<label class="control-label">Nom</label>
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-user fa"></i>
</span>
<input type="text" class="form-control" name="name" placeholder="Nom"/>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label">Email</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-envelope fa"></i>
</span>
<input type="text" class="form-control" name="email" placeholder="Email"/>
</div>
</div>
<div class="form-group">
<label class="control-label">Login</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-users fa"></i>
</span>
<input type="text" class="form-control" name="username" placeholder="Login"/>
</div>
</div>
<div class="form-group">
<label class="control-label">Mot de passe</label>
<div class="input-group">
<span class="input-group-addon">
<i class="fa fa-lock fa-lg"></i>
</span>
<input type="password" class="form-control" name="password" placeholder="Mot de passe"/>
</div>
</div>
</div>
<div class="panel-footer">
<div class="form-group ">
<button type="submit" class="btn btn-primary btn-lg btn-block">
Inscription
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</template>
......@@ -36,6 +36,26 @@
"closable": false,
"sort": 3
}
],
"account": [
{
"module": "account",
"layout": "listAccountTpl",
"label": "Liste des comptes",
"state": {},
"activ": true,
"closable": false,
"sort": 1
},
{
"module": "account",
"layout": "addAccountTpl",
"label": "Ajouter un compte",
"state": {},
"activ": false,
"closable": false,
"sort": 2
}
]
}
}
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment