ménage
This commit is contained in:
+20
-4
@@ -21,12 +21,15 @@ import ListItem from '@material-ui/core/ListItem';
|
||||
import { ListItemText } from '@material-ui/core';
|
||||
|
||||
import { Spring, animated } from 'react-spring'
|
||||
import Button from '@material-ui/core/Button';
|
||||
import GetApp from '@material-ui/icons/GetApp';
|
||||
import PWAInstallSnack from './PWAInstallSnack'
|
||||
|
||||
const styles = theme => ({
|
||||
root: {
|
||||
width: '100%',
|
||||
'& a':{
|
||||
textDecoration:'none'
|
||||
'& a': {
|
||||
textDecoration: 'none'
|
||||
}
|
||||
},
|
||||
|
||||
@@ -140,7 +143,7 @@ class Header extends React.Component {
|
||||
</IconButton>
|
||||
|
||||
<Link href="/" prefetch>
|
||||
<a><div onClick={this.toggle}>
|
||||
<a><div onClick={this.toggle}>
|
||||
<Spring native from={{ x: 0 }} to={{ x: this.state.toggle ? 1 : 0 }} config={{ duration: 1000 }}>
|
||||
{({ x }) => (
|
||||
<animated.div
|
||||
@@ -159,7 +162,20 @@ class Header extends React.Component {
|
||||
</Spring>
|
||||
</div></a>
|
||||
</Link>
|
||||
|
||||
<PWAInstallSnack >
|
||||
{({ initInstall }) =>
|
||||
|
||||
<Button
|
||||
aria-label='install' variant="contained" color="primary" onClick={initInstall}>
|
||||
<GetApp ></GetApp>
|
||||
<Typography variant="h6" color="inherit">
|
||||
Installer
|
||||
</Typography>
|
||||
</Button>
|
||||
|
||||
}
|
||||
</PWAInstallSnack>
|
||||
|
||||
</Toolbar>
|
||||
</AppBar>
|
||||
</div >
|
||||
|
||||
@@ -59,7 +59,7 @@ class PWAInstallSnack extends Component {
|
||||
return false;
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
componentDidMount() {debugger;
|
||||
if (window !== undefined) {
|
||||
// don't show if we are in App
|
||||
if (window.navigator.standalone ||
|
||||
@@ -74,10 +74,12 @@ class PWAInstallSnack extends Component {
|
||||
this.setState({ openSnack: false, buttonDisplay: false })
|
||||
|
||||
if(this.iOS())
|
||||
this.setState({ openSnack: false, buttonDisplay: true })
|
||||
this.setState({ buttonDisplay: true })
|
||||
|
||||
}
|
||||
|
||||
}else{
|
||||
this.setState({ openSnack: false, buttonDisplay: false })
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
/**
|
||||
* next-auth.config.js Example
|
||||
*
|
||||
* Environment variables for this example:
|
||||
*
|
||||
* PORT=3000
|
||||
* SERVER_URL=http://localhost:3000
|
||||
* MONGO_URI=mongodb://localhost:27017/my-database
|
||||
*
|
||||
* If you wish, you can put these in a `.env` to seperate your environment
|
||||
* specific configuration from your code.
|
||||
**/
|
||||
|
||||
// Load environment variables from a .env file if one exists
|
||||
require('dotenv').load()
|
||||
|
||||
const nextAuthProviders = require('./next-auth.providers')
|
||||
const nextAuthFunctions = require('./next-auth.functions')
|
||||
|
||||
// If we want to pass a custom session store then we also need to pass an
|
||||
// instance of Express Session along with it.
|
||||
const expressSession = require('express-session')
|
||||
const MongoStore = require('connect-mongo')(expressSession)
|
||||
|
||||
// If no store set, NextAuth defaults to using Express Sessions in-memory
|
||||
// session store (the fallback is intended as fallback for testing only).
|
||||
let sessionStore
|
||||
if (process.env.MONGO_URI) {
|
||||
sessionStore = new MongoStore({
|
||||
url: process.env.MONGO_URI,
|
||||
autoRemove: 'interval',
|
||||
autoRemoveInterval: 10, // Removes expired sessions every 10 minutes
|
||||
collection: 'sessions',
|
||||
stringify: false
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = () => {
|
||||
// We connect to the User DB before we define our functions.
|
||||
// next-auth.functions.js returns an async method that does that and returns
|
||||
// an object with the functions needed for authentication.
|
||||
return nextAuthFunctions()
|
||||
.then(functions => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// This is the config block we return, ready to be passed to NextAuth
|
||||
resolve({
|
||||
// Define a port (if none passed, will not start Express)
|
||||
// Note: This project omits a port for NextAuth as it uses Express to
|
||||
// add additional routes for the examples, so it takes control of
|
||||
// starting Express, rather than leaving it to NextAuth.
|
||||
// port: process.env.PORT || 3000,
|
||||
// Secret used to encrypt session data on the server.
|
||||
sessionSecret: 'pwacrypretenonsecrettedsecsessi',
|
||||
// Maximum Session Age in ms (optional, default is 7 days).
|
||||
// The expiry time for a session is reset every time a user revisits
|
||||
// the site or revalidates their session token. This is the maximum
|
||||
// idle time value.
|
||||
sessionMaxAge: 60000 * 60 * 24 * 7,
|
||||
// Session Revalidation in X ms (optional, default is 60 seconds).
|
||||
// Specifies how often a Single Page App should revalidate a session.
|
||||
// Does not impact the session life on the server, but causes clients
|
||||
// to refetch session info (even if it is in a local cache) after N
|
||||
// seconds has elapsed since it was last checked so they always display
|
||||
// state correctly.
|
||||
// If set to 0 will revalidate a session before rendering every page.
|
||||
sessionRevalidateAge: 60000,
|
||||
// Canonical URL of the server (optiona, but recommended).
|
||||
// e.g. 'http://localhost:3000' or 'https://www.example.com'
|
||||
// Used in callbak URLs and email sign in links. It will be auto
|
||||
// generated if not specified, which may cause problems if your site
|
||||
// uses multiple aliases (e.g. 'example.com and 'www.examples.com').
|
||||
serverUrl: process.env.SERVER_URL || null,
|
||||
// Add an Express Session store.
|
||||
expressSession: expressSession,
|
||||
sessionStore: sessionStore,
|
||||
// Define oAuth Providers
|
||||
providers: nextAuthProviders(),
|
||||
// Define functions for manging users and sending email.
|
||||
functions: functions,
|
||||
|
||||
csrf:{whitelist:['/account/user']}
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,271 +0,0 @@
|
||||
/**
|
||||
* next-auth.functions.js Example
|
||||
*
|
||||
* This file defines functions NextAuth to look up, add and update users.
|
||||
*
|
||||
* It returns a Promise with the functions matching these signatures:
|
||||
*
|
||||
* {
|
||||
* find: ({
|
||||
* id,
|
||||
* email,
|
||||
* emailToken,
|
||||
* provider,
|
||||
* poviderToken
|
||||
* } = {}) => {},
|
||||
* update: (user) => {},
|
||||
* insert: (user) => {},
|
||||
* remove: (id) => {},
|
||||
* serialize: (user) => {},
|
||||
* deserialize: (id) => {}
|
||||
* }
|
||||
*
|
||||
* Each function returns Promise.resolve() - or Promise.reject() on error.
|
||||
*
|
||||
* This specific example supports both MongoDB and NeDB, but can be refactored
|
||||
* to work with any database.
|
||||
*
|
||||
* Environment variables for this example:
|
||||
*
|
||||
* MONGO_URI=mongodb://localhost:27017/my-database
|
||||
* EMAIL_FROM=username@gmail.com
|
||||
* EMAIL_SERVER=smtp.gmail.com
|
||||
* EMAIL_PORT=465
|
||||
* EMAIL_USERNAME=username@gmail.com
|
||||
* EMAIL_PASSWORD=p4ssw0rd
|
||||
*
|
||||
* If you wish, you can put these in a `.env` to seperate your environment
|
||||
* specific configuration from your code.
|
||||
**/
|
||||
|
||||
// Load environment variables from a .env file if one exists
|
||||
require('dotenv').load()
|
||||
|
||||
// This config file uses MongoDB for User accounts, as well as session storage.
|
||||
// This config includes options for NeDB, which it defaults to if no DB URI
|
||||
// is specified. NeDB is an in-memory only database intended here for testing.
|
||||
const MongoClient = require('mongodb').MongoClient
|
||||
const NeDB = require('nedb')
|
||||
const MongoObjectId = (process.env.MONGO_URI) ? require('mongodb').ObjectId : (id) => { return id }
|
||||
|
||||
// Use Node Mailer for email sign in
|
||||
const nodemailer = require('nodemailer')
|
||||
const nodemailerSmtpTransport = require('nodemailer-smtp-transport')
|
||||
const nodemailerDirectTransport = require('nodemailer-direct-transport')
|
||||
|
||||
// Send email direct from localhost if no mail server configured
|
||||
let nodemailerTransport = nodemailerDirectTransport()
|
||||
if (process.env.EMAIL_SERVER && process.env.EMAIL_USERNAME && process.env.EMAIL_PASSWORD) {
|
||||
nodemailerTransport = nodemailerSmtpTransport({
|
||||
host: process.env.EMAIL_SERVER,
|
||||
port: process.env.EMAIL_PORT || 25,
|
||||
secure: false,
|
||||
auth: {
|
||||
user: process.env.EMAIL_USERNAME,
|
||||
pass: process.env.EMAIL_PASSWORD
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = () => {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (process.env.MONGO_URI) {
|
||||
// Connect to MongoDB Database and return user connection
|
||||
MongoClient.connect(process.env.MONGO_URI, (err, mongoClient) => {
|
||||
if (err) return reject(err)
|
||||
const dbName = process.env.MONGO_URI.split('/').pop().split('?').shift()
|
||||
const db = mongoClient.db(dbName)
|
||||
return resolve(db.collection('users'))
|
||||
})
|
||||
} else {
|
||||
// If no MongoDB URI string specified, use NeDB, an in-memory work-a-like.
|
||||
// NeDB is not persistant and is intended for testing only.
|
||||
let collection = new NeDB({ autoload: true })
|
||||
collection.loadDatabase(err => {
|
||||
if (err) return reject(err)
|
||||
resolve(collection)
|
||||
})
|
||||
}
|
||||
})
|
||||
.then(usersCollection => {
|
||||
return Promise.resolve({
|
||||
// If a user is not found find() should return null (with no error).
|
||||
find: ({id, email, emailToken, provider} = {}) => {
|
||||
let query = {}
|
||||
|
||||
// Find needs to support looking up a user by ID, Email, Email Token,
|
||||
// and Provider Name + Users ID for that Provider
|
||||
if (id) {
|
||||
query = { _id: MongoObjectId(id) }
|
||||
} else if (email) {
|
||||
query = { email: email }
|
||||
} else if (emailToken) {
|
||||
query = { emailToken: emailToken }
|
||||
} else if (provider) {
|
||||
query = { [`${provider.name}.id`]: provider.id }
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
usersCollection.findOne(query, (err, user) => {
|
||||
if (err) return reject(err)
|
||||
return resolve(user)
|
||||
})
|
||||
})
|
||||
},
|
||||
// The user parameter contains a basic user object to be added to the DB.
|
||||
// The oAuthProfile parameter is passed when signing in via oAuth.
|
||||
//
|
||||
// The optional oAuthProfile parameter contains all properties associated
|
||||
// with the users account on the oAuth service they are signing in with.
|
||||
//
|
||||
// You can use this to capture profile.avatar, profile.location, etc.
|
||||
insert: (user, oAuthProfile) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
usersCollection.insert(user, (err, response) => {
|
||||
if (err) return reject(err)
|
||||
|
||||
// Mongo Client automatically adds an id to an inserted object, but
|
||||
// if using a work-a-like we may need to add it from the response.
|
||||
if (!user._id && response._id) user._id = response._id
|
||||
|
||||
return resolve(user)
|
||||
})
|
||||
})
|
||||
},
|
||||
// The user parameter contains a basic user object to be added to the DB.
|
||||
// The oAuthProfile parameter is passed when signing in via oAuth.
|
||||
//
|
||||
// The optional oAuthProfile parameter contains all properties associated
|
||||
// with the users account on the oAuth service they are signing in with.
|
||||
//
|
||||
// You can use this to capture profile.avatar, profile.location, etc.
|
||||
update: (user, profile) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
usersCollection.update({_id: MongoObjectId(user._id)}, user, {}, (err) => {
|
||||
if (err) return reject(err)
|
||||
return resolve(user)
|
||||
})
|
||||
})
|
||||
},
|
||||
// The remove parameter is passed the ID of a user account to delete.
|
||||
//
|
||||
// This method is not used in the current version of next-auth but will
|
||||
// be in a future release, to provide an endpoint for account deletion.
|
||||
remove: (id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
usersCollection.remove({_id: MongoObjectId(id)}, (err) => {
|
||||
if (err) return reject(err)
|
||||
return resolve(true)
|
||||
})
|
||||
})
|
||||
},
|
||||
// Seralize turns the value of the ID key from a User object
|
||||
serialize: (user) => {
|
||||
// Supports serialization from Mongo Object *and* deserialize() object
|
||||
if (user.id) {
|
||||
// Handle responses from deserialize()
|
||||
return Promise.resolve(user.id)
|
||||
} else if (user._id) {
|
||||
// Handle responses from find(), insert(), update()
|
||||
return Promise.resolve(user._id)
|
||||
} else {
|
||||
return Promise.reject(new Error("Unable to serialise user"))
|
||||
}
|
||||
},
|
||||
// Deseralize turns a User ID into a normalized User object that is
|
||||
// exported to clients. It should not return private/sensitive fields,
|
||||
// only fields you want to expose via the user interface.
|
||||
deserialize: (id) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
usersCollection.findOne({ _id: MongoObjectId(id) }, (err, user) => {
|
||||
if (err) return reject(err)
|
||||
|
||||
// If user not found (e.g. account deleted) return null object
|
||||
if (!user) return resolve(null)
|
||||
|
||||
return resolve({
|
||||
id: user._id,
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
emailVerified: user.emailVerified,
|
||||
admin: user.admin || false
|
||||
})
|
||||
})
|
||||
})
|
||||
},
|
||||
// Define method for sending links for signing in over email.
|
||||
sendSignInEmail: ({
|
||||
email = null,
|
||||
url = null
|
||||
} = {}) => {
|
||||
nodemailer
|
||||
.createTransport(nodemailerTransport)
|
||||
.sendMail({
|
||||
to: email,
|
||||
from: process.env.EMAIL_FROM,
|
||||
subject: 'Sign in link',
|
||||
text: `Use the link below to sign in:\n\n${url}\n\n`,
|
||||
html: `<p>Use the link below to sign in:</p><p>${url}</p>`
|
||||
}, (err) => {
|
||||
if (err) {
|
||||
console.error('Error sending email to ' + email, err)
|
||||
}
|
||||
})
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
console.log('Generated sign in link ' + url + ' for ' + email)
|
||||
}
|
||||
},
|
||||
|
||||
// Credentials Sign In
|
||||
//
|
||||
// If you use this you will need to define your own way to validate
|
||||
// credentials. Unlike with oAuth or Email Sign In, accounts are not
|
||||
// created automatically so you will need to provide a way to create them.
|
||||
//
|
||||
// This feature is intended for strategies like Two Factor Authentication.
|
||||
//
|
||||
// To disable this option, do not set signin (or set it to null).
|
||||
/*
|
||||
*/
|
||||
signIn: ({form, req}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
// Should validate credentials (e.g. hash password, compare 2FA token
|
||||
// etc) and return a valid user object from a database.
|
||||
return usersCollection.findOne({
|
||||
email: form.email
|
||||
}, (err, user) => {
|
||||
if (err) return reject(err)
|
||||
if (!user) return resolve(null)
|
||||
|
||||
// Check credentials - e.g. compare bcrypt password hashes
|
||||
if (form.password === "test1234") {
|
||||
// If valid, return user object - e.g. { id, name, email }
|
||||
return resolve(user)
|
||||
} else {
|
||||
// If invalid, return null
|
||||
return resolve(null)
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
// Session Object (optional)
|
||||
//
|
||||
// The session object that gets returned to the client. You don't need to
|
||||
// specify this function here unless you want to override or extend the
|
||||
// default (e.g. with any other properties you have added to req.session)
|
||||
//
|
||||
// Note: The object returned will be stored in localStorage and visible
|
||||
// client side so do not return data you would not want the user to see.
|
||||
/*
|
||||
session: (session, req) => {
|
||||
if (req.session && req.session.someCustomProperty)
|
||||
session.someCustomProperty = req.session.someCustomProperty
|
||||
|
||||
session.someOtherCustomProperty = "Example custom property"
|
||||
|
||||
return session
|
||||
}
|
||||
*/
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
/**
|
||||
* next-auth.providers.js Example
|
||||
*
|
||||
* This file returns a simple array of oAuth Provider objects for NextAuth.
|
||||
*
|
||||
* This example returns an array based on what environment variables are set,
|
||||
* with explicit support for Facebook, Google and Twitter, but it can be used
|
||||
* to add strategies for other oAuth providers.
|
||||
*
|
||||
* Environment variables for this example:
|
||||
*
|
||||
* FACEBOOK_ID=
|
||||
* FACEBOOK_SECRET=
|
||||
* GOOGLE_ID=
|
||||
* GOOGLE_SECRET=
|
||||
* TWITTER_KEY=
|
||||
* TWITTER_SECRET=
|
||||
*
|
||||
* If you wish, you can put these in a `.env` to seperate your environment
|
||||
* specific configuration from your code.
|
||||
**/
|
||||
|
||||
// Load environment variables from a .env file if one exists
|
||||
require('dotenv').load()
|
||||
|
||||
module.exports = () => {
|
||||
let providers = []
|
||||
|
||||
if (process.env.FACEBOOK_ID && process.env.FACEBOOK_SECRET) {
|
||||
providers.push({
|
||||
providerName: 'Facebook',
|
||||
providerOptions: {
|
||||
scope: ['email', 'public_profile']
|
||||
},
|
||||
Strategy: require('passport-facebook').Strategy,
|
||||
strategyOptions: {
|
||||
clientID: process.env.FACEBOOK_ID,
|
||||
clientSecret: process.env.FACEBOOK_SECRET,
|
||||
profileFields: ['id', 'displayName', 'email', 'link']
|
||||
},
|
||||
getProfile(profile) {
|
||||
// Normalize profile into one with {id, name, email} keys
|
||||
return {
|
||||
id: profile.id,
|
||||
name: profile.displayName,
|
||||
email: profile._json.email
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (process.env.LINKEDIN_ID && process.env.LINKEDIN_SECRET) {
|
||||
providers.push({
|
||||
providerName: 'Linkedin',
|
||||
providerOptions: {
|
||||
scope: ['r_emailaddress', 'r_basicprofile']
|
||||
},
|
||||
Strategy: require('passport-linkedin-oauth2').Strategy,
|
||||
strategyOptions: {
|
||||
clientID: process.env.LINKEDIN_ID,
|
||||
clientSecret: process.env.LINKEDIN_SECRET,
|
||||
profileFields: ['r_emailaddress', 'r_basicprofile']
|
||||
},
|
||||
getProfile(profile) {
|
||||
console.log(profile);
|
||||
// Normalize profile into one with {id, name, email} keys
|
||||
return {
|
||||
id: profile.id,
|
||||
// name: profile.displayName,
|
||||
// email: profile._json.email
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
if (process.env.GOOGLE_ID && process.env.GOOGLE_SECRET) {
|
||||
providers.push({
|
||||
providerName: 'Google',
|
||||
providerOptions: {
|
||||
scope: ['profile', 'email']
|
||||
},
|
||||
Strategy: require('passport-google-oauth').OAuth2Strategy,
|
||||
strategyOptions: {
|
||||
clientID: process.env.GOOGLE_ID,
|
||||
clientSecret: process.env.GOOGLE_SECRET
|
||||
},
|
||||
getProfile(profile) {
|
||||
// Normalize profile into one with {id, name, email} keys
|
||||
return {
|
||||
id: profile.id,
|
||||
name: profile.displayName,
|
||||
email: profile.emails[0].value
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: Twitter doesn't expose emails by default.
|
||||
* If we don't get one NextAuth will create a placeholder in the form
|
||||
* `{provider}-{account-id}@localhost.localdomain`
|
||||
*
|
||||
* To have your Twitter oAuth return emails go to apps.twitter.com and add
|
||||
* links to your Terms and Conditions and Privacy Policy under the "Settings"
|
||||
* tab, then check the "Request email addresses" from users box under the
|
||||
* "Permissions" tab.
|
||||
**/
|
||||
if (process.env.TWITTER_KEY && process.env.TWITTER_SECRET) {
|
||||
providers.push({
|
||||
providerName: 'Twitter',
|
||||
providerOptions: {
|
||||
scope: []
|
||||
},
|
||||
Strategy: require('passport-twitter').Strategy,
|
||||
strategyOptions: {
|
||||
consumerKey: process.env.TWITTER_KEY,
|
||||
consumerSecret: process.env.TWITTER_SECRET,
|
||||
userProfileURL: 'https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true'
|
||||
},
|
||||
getProfile(profile) {
|
||||
// Normalize profile into one with {id, name, email} keys
|
||||
return {
|
||||
id: profile.id,
|
||||
name: profile.displayName,
|
||||
email: (profile.emails && profile.emails[0].value) ? profile.emails[0].value : ''
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return providers
|
||||
}
|
||||
+2
-1
@@ -33,7 +33,8 @@ module.exports = withPlugins(
|
||||
}}
|
||||
],
|
||||
importScripts:
|
||||
['/static/js/firebase-messaging-sw.js',
|
||||
[
|
||||
//'/static/js/firebase-messaging-sw.js',
|
||||
'/static/js/backgroundSync-sw.js'
|
||||
]
|
||||
},
|
||||
|
||||
+4
-4
@@ -9,10 +9,10 @@ class edit extends Component {
|
||||
state = {
|
||||
data: []
|
||||
}
|
||||
componentDidMount()
|
||||
{
|
||||
console.log('edit', this.props)
|
||||
}
|
||||
componentDidMount()
|
||||
{
|
||||
console.log('edit', this.props)
|
||||
}
|
||||
componentWillReceiveProps(nextProps) {
|
||||
|
||||
this.setState({ data: nextProps.data })
|
||||
|
||||
+3
-4
@@ -33,6 +33,7 @@ class ListeSAV extends React.Component {
|
||||
|
||||
//example requete adress:
|
||||
//https://poc-api.ag2l.fr:50000/rest/server.Atbl_Adr?filter={"Id_Adr_Key":"Cli.ARMORACIER22F.112731"}
|
||||
//https://poc-api.ag2l.fr:50000/rest/server.Ttbl_Aff_Elt?filter={Id_Res_Hg:"c7edb876-15e7-4dfe-be37-2498beb6457c"}
|
||||
async componentDidMount() {
|
||||
axios.defaults.headers.common.authorization = `Bearer ${localStorage.AG2LToken}`;
|
||||
|
||||
@@ -68,7 +69,7 @@ class ListeSAV extends React.Component {
|
||||
|
||||
let addrIds = tab.map(a => a.Id_Adr_Key)
|
||||
console.log(addrIds)
|
||||
return api.adresse.fetch(addrIds).then((res) => {
|
||||
return api.adresse.fetch(addrIds).then((res) => {
|
||||
if (res.status === 200) {
|
||||
let raw = res.data["server.Atbl_Adr"];
|
||||
|
||||
@@ -115,8 +116,6 @@ class ListeSAV extends React.Component {
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
.catch(() => this.setState({ data: null }))
|
||||
|
||||
}
|
||||
@@ -129,7 +128,7 @@ class ListeSAV extends React.Component {
|
||||
<Head>
|
||||
<title>AG2L SAV</title>
|
||||
<meta name="description" content="" />
|
||||
<link rel="canonical" href="https://AG2L-pwa.bzh" />
|
||||
<link rel="canonical" href="https://ag2l.e-declic.net" />
|
||||
</Head>
|
||||
|
||||
<div className={classes.root}>
|
||||
|
||||
@@ -2,13 +2,9 @@
|
||||
|
||||
require('dotenv').load()
|
||||
const utils = require('./src/utils');
|
||||
const mailer = require("./src/mailer.js")
|
||||
const { google } = require('googleapis');
|
||||
//const express = require('express')
|
||||
const express = require('express')
|
||||
const axios = require('axios')
|
||||
const next = require('next')
|
||||
const nextAuth = require('next-auth')
|
||||
const nextAuthConfig = require('./next-auth.config')
|
||||
const { join } = require('path');
|
||||
const { parse } = require('url');
|
||||
|
||||
@@ -16,261 +12,18 @@ const dev = process.env.NODE_ENV !== 'production'
|
||||
const app = next({ dev })
|
||||
const handle = app.getRequestHandler()
|
||||
|
||||
// const passport = require('passport')
|
||||
// const FacebookStrategy = require('passport-facebook').Strategy
|
||||
|
||||
const routes = {
|
||||
admin: require('./routes/admin'),
|
||||
account: require('./routes/account')
|
||||
}
|
||||
|
||||
const bodyParser = require('body-parser');
|
||||
|
||||
function getAccessToken() {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var key = require('./service-account.json');
|
||||
var jwtClient = new google.auth.JWT(
|
||||
key.client_email,
|
||||
null,
|
||||
key.private_key,
|
||||
'https://www.googleapis.com/auth/firebase.messaging',
|
||||
null
|
||||
);
|
||||
jwtClient.authorize(function (err, tokens) {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(tokens.access_token);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// passport.use(new FacebookStrategy({
|
||||
// clientID: process.env.FACEBOOK_ID,
|
||||
// clientSecret: process.env.FACEBOOK_SECRET,
|
||||
// callbackURL: "http://localhost:3000/auth/facebook/callback",
|
||||
// enableProof: true
|
||||
// },
|
||||
// function (accessToken, refreshToken, profile, cb) {
|
||||
// User.findOrCreate({ facebookId: profile.id }, function (err, user) {
|
||||
// return cb(err, user);
|
||||
// });
|
||||
// console.log(profile)
|
||||
|
||||
// console.log("accessToken : " + accessToken);
|
||||
// console.log("refreshToken" + refreshToken);//****not needed because we only use accesstoken to connect to our api*/
|
||||
|
||||
// return cb(null, profile);
|
||||
// }
|
||||
// ));
|
||||
|
||||
app.prepare()
|
||||
.then(() => {
|
||||
// Load configuration and return config object
|
||||
return nextAuthConfig()
|
||||
})
|
||||
.then(nextAuthOptions => {
|
||||
// Pass Next.js App instance and NextAuth options to NextAuth
|
||||
// Note We do not pass a port in nextAuthOptions, because we want to add some
|
||||
// additional routes before Express starts (if you do pass a port, NextAuth
|
||||
// tells NextApp to handle default routing and starts Express automatically).
|
||||
return nextAuth(app, nextAuthOptions)
|
||||
})
|
||||
.then(nextAuthOptions => {
|
||||
|
||||
const express = nextAuthOptions.express
|
||||
const expressApp = nextAuthOptions.expressApp
|
||||
|
||||
// Add admin routes
|
||||
routes.admin(expressApp)
|
||||
|
||||
// Add account management route - reuses functions defined for NextAuth
|
||||
routes.account(expressApp, nextAuthOptions.functions)
|
||||
const expressApp = express()
|
||||
|
||||
expressApp.use('/', express.static(__dirname + '/.next/'))
|
||||
|
||||
var jsonParser = bodyParser.json()
|
||||
|
||||
expressApp.post('/feedback', jsonParser, (req, res) => {
|
||||
|
||||
let message = req.body.message;
|
||||
let nom = req.body.nom;
|
||||
let prenom = req.body.prenom;
|
||||
let tel = req.body.tel;
|
||||
let mail = req.body.mail;
|
||||
let recaptchaValue = req.body.recaptchaValue;
|
||||
|
||||
console.log(message);
|
||||
if (message === '') {
|
||||
res.status(400).json({
|
||||
errors: { global: "Message is empty." }
|
||||
}); return;
|
||||
}
|
||||
if (mail === '') {
|
||||
res.status(400).json({
|
||||
errors: { global: "email is empty." }
|
||||
}); return;
|
||||
}
|
||||
utils.verifyCaptcha(recaptchaValue)
|
||||
.then(
|
||||
respo => {
|
||||
if (respo.data.success == true) {
|
||||
try {
|
||||
mailer.sendEmail(message, nom, prenom, tel, mail);
|
||||
res.status(200).send({})
|
||||
} catch (err) {
|
||||
res.status(500).send({ message: "Send mail fail." })
|
||||
}
|
||||
}
|
||||
else
|
||||
res.status(500).send({ message: "Captcha invalid." })
|
||||
})
|
||||
.catch(() =>
|
||||
res.status(403).send({ message: "Captcha verification impossible." })
|
||||
)
|
||||
|
||||
});
|
||||
|
||||
expressApp.post('/push/message', jsonParser, (req, res) => {
|
||||
let message = req.body.payload;
|
||||
|
||||
if (message === '') {
|
||||
res.status(400).json({
|
||||
errors: { global: "Message is empty." }
|
||||
}); return;
|
||||
}
|
||||
else {
|
||||
getAccessToken().then((googleAccessToken) => {
|
||||
utils.setAuthorizationHeader(googleAccessToken);
|
||||
// console.log(message);
|
||||
axios.post('https://fcm.googleapis.com/v1/projects/edeclicpwa/messages:send',
|
||||
message
|
||||
).then(r => {
|
||||
console.log("message : "); console.log(r)
|
||||
res.status(200).send({ message: "message sent to firebase" })
|
||||
}
|
||||
)
|
||||
.catch(err => console.log("first catch" + err)
|
||||
//res.status(500).send({ message: "Push error" })
|
||||
)
|
||||
}).catch(err => console.log("second catch" + err)
|
||||
//err => res.status(500).send({ message: "Push error" + err })
|
||||
)
|
||||
|
||||
}
|
||||
})
|
||||
expressApp.get('/push/info/:token', (req, res) => {
|
||||
|
||||
var token = req.params.token
|
||||
if (token === '') {
|
||||
res.status(498).json({
|
||||
errors: { global: "No token specified." }
|
||||
}); return;
|
||||
}
|
||||
|
||||
var url = 'https://iid.googleapis.com/iid/info/' + token + '?details=true'
|
||||
|
||||
utils.setAuthorizationHeaderForIID(process.env.FIREBASE_API_KEY)
|
||||
axios.get(url).then(r => {
|
||||
if (!!r.data.rel && !!r.data.rel.topics) {
|
||||
res.status(200).send({ topics: r.data.rel.topics })
|
||||
}
|
||||
else
|
||||
res.status(200).send({ topics: null })
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
res.status(500).send({ message: "Push error" })
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
expressApp.post('/push/subscribe', jsonParser, (req, res) => {
|
||||
let message = req.body;
|
||||
|
||||
if (message === '') {
|
||||
res.status(400).json({
|
||||
errors: { global: "Message is empty." }
|
||||
}); return;
|
||||
}
|
||||
else {
|
||||
if (message.topic === '' || message.token === '') {
|
||||
res.status(400).json({
|
||||
errors: { global: "Message isnot well formed." }
|
||||
}); return;
|
||||
}
|
||||
|
||||
var url = 'https://iid.googleapis.com/iid/v1/' + message.token + '/rel/topics/' + message.topic
|
||||
|
||||
utils.setAuthorizationHeaderForIID(process.env.FIREBASE_API_KEY)
|
||||
|
||||
axios.post(url)
|
||||
.then(r => {
|
||||
res.status(200).send({ message: "message sent to firebase" })
|
||||
})
|
||||
.catch(err => console.log(err))
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
expressApp.post('/push/unsubscribe', jsonParser, (req, res) => {
|
||||
let message = req.body;
|
||||
|
||||
if (message === '') {
|
||||
res.status(400).json({
|
||||
errors: { global: "Message is empty." }
|
||||
}); return;
|
||||
}
|
||||
else {
|
||||
if (message.topic === '' || message.token === '') {
|
||||
res.status(400).json({
|
||||
errors: { global: "Message is not well formed." }
|
||||
}); return;
|
||||
}
|
||||
message.topic = '/topics/' + message.topic
|
||||
var payload = { to: message.topic, registration_tokens: [message.token] }
|
||||
var url = 'https://iid.googleapis.com/iid/v1:batchRemove'
|
||||
|
||||
utils.setAuthorizationHeaderForIID(process.env.FIREBASE_API_KEY)
|
||||
axios.post(url, payload
|
||||
).then(r => {
|
||||
res.status(200).send({ message: "message sent to firebase" })
|
||||
}
|
||||
)
|
||||
.catch(err => console.log(err)
|
||||
)
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
//https://us-central1-edeclicpwa.cloudfunctions.net/pushMessageToAllSubscribers
|
||||
expressApp.post('/push/allsubscribers', jsonParser, (req, res) => {
|
||||
let message = req.body.payload;
|
||||
|
||||
if (message === '') {
|
||||
res.status(400).json({
|
||||
errors: { global: "Message is empty." }
|
||||
}); return;
|
||||
}
|
||||
else {
|
||||
|
||||
utils.setAuthorizationHeader(process.env.FIREBASE_API_KEY)
|
||||
// console.log(message);
|
||||
axios.post('https://us-central1-edeclicpwa.cloudfunctions.net/pushMessageToAllSubscribers',
|
||||
{ payload: message }
|
||||
).then(r => {
|
||||
res.status(200).send({ message: "message sent to firebase" })
|
||||
}
|
||||
)
|
||||
.catch(err => console.log(err))
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
expressApp.get('/static/js/*.js', (req, res) => {
|
||||
|
||||
const parsedUrl = parse(req.url, true);
|
||||
const { pathname } = parsedUrl;
|
||||
const filePath = join(__dirname, '.next', pathname);
|
||||
@@ -278,14 +31,12 @@ app.prepare()
|
||||
})
|
||||
|
||||
expressApp.get('/manifest.json', (req, res) => {
|
||||
|
||||
const parsedUrl = parse(req.url, true);
|
||||
const { pathname } = parsedUrl;
|
||||
const filePath = join(__dirname, '/static/', pathname);
|
||||
app.serveStatic(req, res, filePath);
|
||||
})
|
||||
|
||||
|
||||
expressApp.get('*', (req, res) => {
|
||||
return handle(req, res)
|
||||
})
|
||||
@@ -293,7 +44,6 @@ app.prepare()
|
||||
expressApp.listen(process.env.PORT, (err) => {
|
||||
if (err) throw err
|
||||
console.log('> Ready on http://localhost:' + process.env.PORT)
|
||||
console.log('> access Token googleapi >' + getAccessToken())
|
||||
})
|
||||
})
|
||||
.catch((ex) => {
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
{
|
||||
"type": "service_account",
|
||||
"project_id": "edeclicpwa",
|
||||
"private_key_id": "aef80b8a8d6f9f10aa0ef0cffd46992399fac45d",
|
||||
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDZuQVADJXtA7Hb\n2R36sZxD3fw5QOmLwvAGnIXtexf/hppz6J1mUDsbNDLF3FxlgzdKQguGE0+q6QI+\nIWEMYPVQPot8Tbs8rcL06EKkhLR3KHRI6hWRyFNnWKnig7xVD5LUNVjgtHNIx9TC\ndf+/F6kSsz7w7cjHZEFZ5k7eAeD3M15EhtGCCyJ9DM3MO/pKzW4lah1jTGeV1ZYS\nimuBSbSX9Z6k6l3dUayMYaARYjZkBu1syhUGs/KoeqS+o+bR1OJX/JiaYe0lWWAg\nuL4315c2SkuXeHX2y9BvxbY2TGfhAPuNFPSsJgt0hXE6QeSIjFZXePmWIq28tNhH\n6OR/EJFzAgMBAAECggEAZ23/YgF4mct3C19V4BnPB+ilYReGuzfkqediskIXUPMD\nXcvkNk4n/hDqi9dW53yR4AuHCO8UmjcuMxDNV0GaWEAWKHuO1tEfPBQ4UIqgZrkH\noPnfPE2j3YUf03VMm0YWNQyQx9LBr5IK70R6NbAKSFFxtafoiVyFtSz1S38t/ZB/\nqigCvK48kG6vZCyAozuKVbkLKorY8THZRbK24Mwp4rnAxRHUxG9pXCGe1/j1FvSP\nPRGPptvRSLP2kRPZXELKga7/yCPIOqT2jEoWiXAdfU2gyED4jEhby+ryBHuTsxpo\nJiaGtbUWMKjOEUOWekgTMvtgQD4T5WP5zx2AAZ5K4QKBgQDz7075SYWTy98MZSC2\nMVF6Ei2mGDMxLDJqpTnc3Oi7+eOXI8uTo5SqgaBHfM/uTywcipqSUQTseDN7C1wu\nWOb6r0shK6FfDP1GQc9l0mmNuIZ8JLkc6nB8Es5wwd4vLRhuSsy6pSz/wDovC3Q2\n5se/B7ir+kYeFlhIMAjN91rukwKBgQDkfdDpAociVjFpcjly5Zf60uL/BzIZOdpn\n1Iq/kAxFr2kuZzGDpwUgXvSU4nELivrsf452x3+R78C2SWwil9IRrD3DAYJzT3qP\nb6l4EuKuHRPtVJBqIPWaMiT6Ov6aAQpGYh5qZjFeHSIDBzXHd/OBbSzisE3zTOqm\nED3/eQq9oQKBgAD/XYdPcahlEQhv8W5NTVP+dwlS2AK/d4VQH6hzjtAV+YRItTBp\nXtZDqXAhZohG8ps7Rd6LTkXZR/yc00etPWSRCvGbyBEncHG1GzADaEMYGhSv4cHo\ng4U+XnG/mTUALjVlQOkSe9if5J0EovkGgJKbaXnqkBbXaI0DBUYyWMDZAoGBAMND\nGfLmbCFV02gvaxTbTCPXcJFMzu1r2U99/Qxzx2kN3C8BlPjTFLhzLUTGtqCMpp7Q\n6yhqmIRYhTHCURzG7YiYzzcE5TwxoaVOYV7xlLICu3LIH5nyjLC3RY5qOAXX+bXo\nR+HZbzrkXpqD4NuTkI78g609yX+wLZ64pqLaB+nBAoGATMflJNxgyWtY6b2yFYgm\nCOhMecJKMS2Rgmdl3FQGxAMPMIy18URW/t99LmbUhqQGsdFPDTcxR6V4ajWqltrj\nLkbrEtSHp7xFAQD2anUeEwxtW8PpICwhgGXJUSjXU8+2A20CaWcTwH5USnNp8kp/\n9402JWBkoe+kodILFHZ363M=\n-----END PRIVATE KEY-----\n",
|
||||
"client_email": "firebase-adminsdk-hffwl@edeclicpwa.iam.gserviceaccount.com",
|
||||
"client_id": "100436348289421185617",
|
||||
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
|
||||
"token_uri": "https://oauth2.googleapis.com/token",
|
||||
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
|
||||
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/firebase-adminsdk-hffwl%40edeclicpwa.iam.gserviceaccount.com"
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
|
||||
importScripts("https://www.gstatic.com/firebasejs/5.5.8/firebase-app.js")
|
||||
importScripts("https://www.gstatic.com/firebasejs/5.5.8/firebase-messaging.js")
|
||||
|
||||
if (firebase.messaging.isSupported()) {
|
||||
// Initialize Firebase
|
||||
var config = {
|
||||
apiKey: "AIzaSyArZab_4hUDgksQ4Dqdwv970JyRSlbGaKY",
|
||||
authDomain: "edeclicpwa.firebaseapp.com",
|
||||
databaseURL: "https://edeclicpwa.firebaseio.com",
|
||||
projectId: "edeclicpwa",
|
||||
storageBucket: "edeclicpwa.appspot.com",
|
||||
messagingSenderId: "130215947970"
|
||||
};
|
||||
firebase.initializeApp(config);
|
||||
|
||||
var messaging = firebase.messaging();
|
||||
|
||||
/**
|
||||
* Here is is the code snippet to initialize Firebase Messaging in the Service
|
||||
* Worker when your app is not hosted on Firebase Hosting.
|
||||
// [START initialize_firebase_in_sw]
|
||||
// Give the service worker access to Firebase Messaging.
|
||||
// Note that you can only use Firebase Messaging here, other Firebase libraries
|
||||
// are not available in the service worker.
|
||||
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js');
|
||||
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');
|
||||
// Initialize the Firebase app in the service worker by passing in the
|
||||
// messagingSenderId.
|
||||
firebase.initializeApp({
|
||||
'messagingSenderId': 'YOUR-SENDER-ID'
|
||||
});
|
||||
// Retrieve an instance of Firebase Messaging so that it can handle background
|
||||
// messages.
|
||||
const messaging = firebase.messaging();
|
||||
// [END initialize_firebase_in_sw]
|
||||
**/
|
||||
|
||||
|
||||
// If you would like to customize notifications that are received in the
|
||||
// background (Web app is closed or not in browser focus) then you should
|
||||
// implement this optional method.
|
||||
// [START background_handler]
|
||||
messaging.setBackgroundMessageHandler(function (payload) {
|
||||
console.log('[firebase-messaging-sw.js] Received background message ', payload);
|
||||
// Customize notification here
|
||||
var notificationTitle = 'Background Message Title';
|
||||
var notificationOptions = {
|
||||
body: 'Background Message body.',
|
||||
icon: '/firebase-logo.png'
|
||||
};
|
||||
|
||||
return self.registration.showNotification(notificationTitle,
|
||||
notificationOptions);
|
||||
});
|
||||
// [END background_handler]
|
||||
}
|
||||
+6
-57
@@ -1,72 +1,21 @@
|
||||
{
|
||||
"name": "E-Declic PWA",
|
||||
"short_name": "E-Declic",
|
||||
"name": "AG2L SAV",
|
||||
"short_name": "AG2L",
|
||||
"lang": "fr",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/static/images/icons/e-declicIco16x16.png",
|
||||
"sizes": "16x16",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/icons/e-declicIco32x32.png",
|
||||
"src": "/static/images/icons/AG2L32x32.png",
|
||||
"sizes": "32x32",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/icons/e-declicIco57x57.png",
|
||||
"sizes": "57x57",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/icons/e-declicIco72x72.png",
|
||||
"sizes": "72x72",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/icons/e-declicIco114x114.png",
|
||||
"sizes": "114x114",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/icons/e-declicIco128x128.png",
|
||||
"sizes": "128x128",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/icons/e-declicIco144x144.png",
|
||||
"sizes": "144x144",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/icons/e-declicIco152x152.png",
|
||||
"sizes": "152x152",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/icons/e-declicIco192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/icons/e-declicIco180x180.png",
|
||||
"sizes": "180x180",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/icons/e-declicIco256x256.png",
|
||||
"sizes": "256x256",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/static/images/icons/e-declicIco512x512.png",
|
||||
"sizes": "512x512",
|
||||
"src": "/static/images/icons/AG2L270x270.png",
|
||||
"sizes": "270x270",
|
||||
"type": "image/png"
|
||||
}
|
||||
],
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#ffffff",
|
||||
"theme_color": "#21b8cc",
|
||||
"gcm_sender_id":"103953800507"
|
||||
"theme_color": "#21b8cc"
|
||||
}
|
||||
Reference in New Issue
Block a user