merge
This commit is contained in:
commit
390b43c122
|
@ -1,8 +1,8 @@
|
||||||
const { newid } = require("../hashing")
|
const { newid } = require("../hashing")
|
||||||
|
|
||||||
exports.StaticDatabases = {
|
exports.StaticDatabases = {
|
||||||
USER: {
|
GLOBAL: {
|
||||||
name: "user-db",
|
name: "global-db",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ passport.use(new JwtStrategy(jwt.options, jwt.authenticate))
|
||||||
passport.serializeUser((user, done) => done(null, user))
|
passport.serializeUser((user, done) => done(null, user))
|
||||||
|
|
||||||
passport.deserializeUser(async (user, done) => {
|
passport.deserializeUser(async (user, done) => {
|
||||||
const db = new database.CouchDB(StaticDatabases.USER.name)
|
const db = new database.CouchDB(StaticDatabases.GLOBAL.name)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const user = await db.get(user._id)
|
const user = await db.get(user._id)
|
||||||
|
|
|
@ -21,7 +21,7 @@ exports.authenticate = async function(username, password, done) {
|
||||||
if (!password) return done(null, false, "Password Required.")
|
if (!password) return done(null, false, "Password Required.")
|
||||||
|
|
||||||
// Check the user exists in the instance DB by email
|
// Check the user exists in the instance DB by email
|
||||||
const db = new database.CouchDB(StaticDatabases.USER.name)
|
const db = new database.CouchDB(StaticDatabases.GLOBAL.name)
|
||||||
|
|
||||||
let dbUser
|
let dbUser
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -11,6 +11,16 @@ const USER_DB = StaticDatabases.USER.name
|
||||||
|
|
||||||
exports.save = async function(ctx, next) {
|
exports.save = async function(ctx, next) {
|
||||||
const db = new CouchDB(USER_DB)
|
const db = new CouchDB(USER_DB)
|
||||||
|
const doc = ctx.request.body
|
||||||
|
|
||||||
|
const groupDoc = {
|
||||||
|
users: ["us:1234", "us:1234"],
|
||||||
|
managers: ["us:1234"],
|
||||||
|
defaultRole: "BASIC",
|
||||||
|
apps: {
|
||||||
|
abc123: "ADMIN",
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.fetch = async function(ctx, next) {
|
exports.fetch = async function(ctx, next) {
|
||||||
|
|
|
@ -7,10 +7,10 @@ const {
|
||||||
} = require("@budibase/auth")
|
} = require("@budibase/auth")
|
||||||
const { UserStatus } = require("../../../constants")
|
const { UserStatus } = require("../../../constants")
|
||||||
|
|
||||||
const USER_DB = StaticDatabases.USER.name
|
const GLOBAL_DB = StaticDatabases.GLOBAL.name
|
||||||
|
|
||||||
exports.userSave = async ctx => {
|
exports.userSave = async ctx => {
|
||||||
const db = new CouchDB(USER_DB)
|
const db = new CouchDB(GLOBAL_DB)
|
||||||
const { email, password, _id } = ctx.request.body
|
const { email, password, _id } = ctx.request.body
|
||||||
const hashedPassword = password ? await hash(password) : null
|
const hashedPassword = password ? await hash(password) : null
|
||||||
let user = {
|
let user = {
|
||||||
|
@ -47,7 +47,7 @@ exports.userSave = async ctx => {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.userDelete = async ctx => {
|
exports.userDelete = async ctx => {
|
||||||
const db = new CouchDB(USER_DB)
|
const db = new CouchDB(GLOBAL_DB)
|
||||||
const dbUser = await db.get(generateUserID(ctx.params.email))
|
const dbUser = await db.get(generateUserID(ctx.params.email))
|
||||||
await db.remove(dbUser._id, dbUser._rev)
|
await db.remove(dbUser._id, dbUser._rev)
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
|
@ -57,7 +57,7 @@ exports.userDelete = async ctx => {
|
||||||
|
|
||||||
// called internally by app server user fetch
|
// called internally by app server user fetch
|
||||||
exports.userFetch = async ctx => {
|
exports.userFetch = async ctx => {
|
||||||
const db = new CouchDB(USER_DB)
|
const db = new CouchDB(GLOBAL_DB)
|
||||||
const response = await db.allDocs(
|
const response = await db.allDocs(
|
||||||
getUserParams(null, {
|
getUserParams(null, {
|
||||||
include_docs: true,
|
include_docs: true,
|
||||||
|
@ -75,7 +75,7 @@ exports.userFetch = async ctx => {
|
||||||
|
|
||||||
// called internally by app server user find
|
// called internally by app server user find
|
||||||
exports.userFind = async ctx => {
|
exports.userFind = async ctx => {
|
||||||
const db = new CouchDB(USER_DB)
|
const db = new CouchDB(GLOBAL_DB)
|
||||||
let user
|
let user
|
||||||
try {
|
try {
|
||||||
user = await db.get(generateUserID(ctx.params.email))
|
user = await db.get(generateUserID(ctx.params.email))
|
||||||
|
|
Loading…
Reference in New Issue