Skip to content
Snippets Groups Projects
Commit 21e0f387 authored by Wilson JALLET's avatar Wilson JALLET :money_with_wings:
Browse files

Encapsulating graphql schema in its own file

parent dbd952f4
No related branches found
No related tags found
No related merge requests found
......@@ -15,6 +15,11 @@ exports.seed = function(knex, Promise) {
website: 'binet-jtx.com',
school: 'polytechnique'
},
{
name: 'Kès',
website: 'kes.binets.fr',
school: 'polytechnique'
},
{
name: 'DaTA',
website: 'data-ensta.fr',
......
/**
* @file Interface "administrateur" de l'acces aux BDD. S'appuie sur css et views.
* @file
*/
import express from 'express';
import knex from '../../db/knex_router';
import passport from 'passport';
......@@ -20,17 +19,17 @@ router.get('/admin', function (req, res) {
res.render('home', { title: 'Home', port: port });
});
router.post('/loginAttempt'
, passport.authenticate('ldapauth', {
router.post('/login',
passport.authenticate('ldapauth', {
//successRedirect: '/admin',
failureRedirect: '/',
//failureFlash: true
//failureFlas: 'Invalid username or password.' //TODO: test this. ce message s'affiche-t-il tout seul ou faut-il aller le chercher quand on genere login.pug?
})
}),
// on a commente les deux lignes dessus et on a besoin de faire un callback apres le passport.authenticate car
// on souhaite garde l'information user.dn et body.password qq part.
// TODO: essayer de garder ces informations plus proprement...
, function (req, res) {
function (req, res) {
req.session.dn = req.user.dn;
req.session.password = req.body.password;
......@@ -43,7 +42,7 @@ router.post('/loginAttempt'
);
router.get('/logout', function (req, res) {
router.post('/logout', function (req, res) {
req.logout();
res.redirect('/');
});
......
import knex from '../../db/knex_router';
import { makeExecutableSchema } from 'graphql-tools';
const typeDefs = `
type Query {
groups: [Group]
}
type Group {
name: String!
id: ID!
website: String
updatedAt: String!
description: String
school: String!
}
`;
const resolvers = {
Query: {
groups: () => knex.select().from('groups')
}
};
const schema = makeExecutableSchema({
typeDefs,
resolvers
});
export default schema;
\ No newline at end of file
/**
* @file Entry point de webpack
*/
import server from './server';
import colors from 'colors';
import { graphqlExpress, graphiqlExpress } from 'graphql-server-express';
import makeExecutableSchema from 'graphql-tools';
import setupLdapAuth from './ldap_auth/ldap_auth';
import router from './admin_view/admin_router';
......
......@@ -2,11 +2,10 @@ import express from 'express';
import bodyParser from 'body-parser';
import favicon from 'serve-favicon';
import morgan from 'morgan';
import knex from '../db/knex_router';
import path from 'path';
import ldap_auth from './ldap_auth/ldap_auth';
import schema from './graphql/schema';
import { graphqlExpress, graphiqlExpress } from 'graphql-server-express';
import { makeExecutableSchema } from 'graphql-tools';
/**
* @file Cree le serveur express avec tous les middleware qui vont bien
......@@ -35,32 +34,6 @@ server.use(morgan('dev'));
// setting up ldap authentication
ldap_auth(server);
const typeDefs = `
type Query {
groups: [Group]
}
type Group {
name: String!
id: ID!
website: String
updatedAt: String!
description: String
school: String!
}
`;
const resolvers = {
Query: {
groups: () => knex.select().from('groups')
}
};
const schema = makeExecutableSchema({
typeDefs,
resolvers
});
// Charge le middleware express pour GraphQL
server.use('/graphql', bodyParser.json(), graphqlExpress({schema}));
......
......@@ -4,7 +4,7 @@ block content
h1 Sigma backend API
p Veuillez vous connecter.
p Please log in.
form(action="/loginAttempt", method="post")
form(action="/login", method="post")
div.form-group
label(for="username") Frankiz ID
input.form-control(type="text", placeholder="User", name="username")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment