Attention ! Gitlab fournissant maintenant nativement des certificats Let’s Encrypt aux domaines personnalisés des Gitlab Pages, nous avons coupé notre service qui le faisait automatiquement pour vous.

Il est impératif, pour que votre domaine personnalisé continue à avoir un certificat Let’s Encrypt à jour, d’activer la fonctionnalité native dans les paramètres de votre projet. Cette activation remplacera votre certificat actuel par un nouveau certificat Let’s Encrypt géré par Gitlab.

Voir les détails sur https://docs.framasoft.org/fr/gitlab/gitlab-pages-le.html

Commit 4d5c9fa5 authored by Emmanuel Raviart's avatar Emmanuel Raviart

Add support for authentication to client.

parent cf147255
......@@ -3,6 +3,7 @@ import { Store } from "svelte/store.js"
import * as sapper from "../__sapper__/client.js"
function post(endpoint, data) {
// eslint-disable-next-line no-undef
return fetch(endpoint, {
body: JSON.stringify(data),
credentials: "same-origin",
......@@ -43,12 +44,19 @@ class ConduitStore extends Store {
}
}
sapper.start({
store: data => {
return new ConduitStore({
...data,
// eslint-disable-next-line no-undef
fetch("auth/me", { credentials: "same-origin" })
.then(response => response.json())
.then(user => {
sapper.start({
store: data => {
return new ConduitStore({
...data,
user,
})
},
// eslint-disable-next-line no-undef
target: document.querySelector("#sapper"),
})
},
// eslint-disable-next-line no-undef
target: document.querySelector("#sapper"),
})
})
.catch(error => console.error(error))
......@@ -15,6 +15,9 @@ export function entryToUser(entry) {
}
export function toUserJson(user, { showApiKey = false, showEmail = false } = {}) {
if (user === null) {
return null
}
let userJson = { ...user }
if (!showApiKey) delete userJson.apiKey
if (!showEmail) delete userJson.email
......
......@@ -8,14 +8,14 @@ export function post(req, res, next) {
return next(err)
}
if (!user) {
res.setHeader("Content-Type", "application/json")
res.setHeader("Content-Type", "application/json; charset=utf-8")
return res.end(JSON.stringify({ errors: info }))
}
req.login(user, function(err) {
if (err) {
return next(err)
}
res.setHeader("Content-Type", "application/json")
res.setHeader("Content-Type", "application/json; charset=utf-8")
return res.end(JSON.stringify(toUserJson(user, { showApiKey: true, showEmail: true })))
})
})(req, res, next)
......
......@@ -3,6 +3,6 @@ import { toUserJson } from "../../model/users"
export function post(req, res) {
const user = req.user || null
req.logout()
res.setHeader("Content-Type", "application/json")
res.setHeader("Content-Type", "application/json; charset=utf-8")
return res.end(JSON.stringify(toUserJson(user, { showApiKey: false, showEmail: false })))
}
import { toUserJson } from "../../model/users"
export async function get(req, res) {
res.writeHead(200, {
"Content-Type": "application/json; charset=utf-8",
})
res.end(JSON.stringify(toUserJson(req.user || null, { showApiKey: true, showEmail: true }), null, 2))
}
import { pbkdf2Sync, randomBytes } from "crypto"
import slugify from "slug"
import { db } from "../../database"
import { toUserJson } from "../../model/users"
import { slugify } from "../../strings"
export async function post(req, res) {
const { email, password, username } = req.body
......@@ -11,7 +11,7 @@ export async function post(req, res) {
if ((await db.one("SELECT EXISTS (SELECT 1 FROM users WHERE email = $1)", email)).exists) {
errors["email"] = "An user with the same email address already exists."
}
const slug = slugify(username, { mode: "rfc3986" })
const slug = slugify(username)
if (!slug) {
errors["username"] = "Username must contain at least one alphanumerical character."
} else if ((await db.one("SELECT EXISTS (SELECT 1 FROM users WHERE slug = $1)", slug)).exists) {
......@@ -19,8 +19,8 @@ export async function post(req, res) {
}
if (Object.keys(errors).length > 0) {
res.setHeader("Content-Type", "application/json")
return res.end(JSON.stringify({ errors }))
res.setHeader("Content-Type", "application/json; charset=utf-8")
return res.end(JSON.stringify({ errors }, null, 2))
}
const user = {
......@@ -55,6 +55,6 @@ export async function post(req, res) {
user.id = result.id
user.isAdmin = result.is_admin
// TODO: Convert user to JSON and remove secret attributes.
res.setHeader("Content-Type", "application/json")
return res.end(JSON.stringify(toUserJson(user, { showApiKey: true, showEmail: true })))
res.setHeader("Content-Type", "application/json; charset=utf-8")
return res.end(JSON.stringify(toUserJson(user, { showApiKey: true, showEmail: true }), null, 2))
}
......@@ -7,7 +7,6 @@ import passport from "passport"
import { Strategy as LocalStrategy } from "passport-local"
import polka from "polka"
import sirv from "sirv"
import slugify from "slug"
import { Store } from "svelte/store.js"
import * as sapper from "../__sapper__/server.js"
......@@ -15,6 +14,7 @@ import { checkDatabase, db } from "./database"
import "./global.css"
import { entryToUser } from "./model/users"
import serverConfig from "./server-config"
import { slugify } from "./strings"
const { PORT, NODE_ENV } = process.env
const dev = NODE_ENV === "development"
......@@ -59,7 +59,7 @@ passport.use(
return done(null, false, { username: `No user with email "${username}".` })
}
} else {
let slug = slugify(username, { mode: "rfc3986" })
let slug = slugify(username)
user = entryToUser(
await db.oneOrNone(
`
......@@ -89,28 +89,26 @@ checkDatabase()
.then(() => {
polka() // You can also use Express
.use(
compression({ threshold: 0 }),
sirv("static", { dev }),
session({
secret: serverConfig.sessionSecret,
resave: false,
saveUninitialized: false,
// cookie: {
// maxAge: 31536000
// },
resave: false,
saveUninitialized: false,
secret: serverConfig.sessionSecret,
store: new PgSessionStore({
pgPromise: db,
tableName: "sessions",
}),
})
)
.use(bodyParser.json({
limit: "1mb",
}))
// .use(bodyParser.urlencoded({ extended: false, type: "application/x-www-form-urlencoded" }))
.use(passport.initialize())
.use(passport.session())
.use(
compression({ threshold: 0 }),
sirv("static", { dev }),
}),
bodyParser.json({
limit: "1mb",
}),
// bodyParser.urlencoded({ extended: false, type: "application/x-www-form-urlencoded" }),
passport.initialize(),
passport.session(),
sapper.middleware({
store: req => {
return new Store({
......
import originalSlugify from "slug"
const slugifyCharmap = { ...originalSlugify.defaults.charmap, "'": " ", "@": " ", ".": " " }
export function buildSearchUrl(url, { limit = 10, offset = 0, term = "" }) {
let query = []
if (term) {
......@@ -20,6 +24,17 @@ export function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1)
}
export function slugify(string, replacement) {
const options = {
charmap: slugifyCharmap,
mode: "rfc3986",
}
if (replacement) {
options.replacement = replacement
}
return originalSlugify(string, options)
}
export function uncapitalizeFirstLetter(string) {
return string.charAt(0).toLowerCase() + string.slice(1)
}
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