mirror of https://github.com/xfarrow/blink
update
This commit is contained in:
parent
9742e81023
commit
dd43439d5b
|
@ -1,7 +1,13 @@
|
||||||
|
# Blink configuration file
|
||||||
|
|
||||||
|
# API server settings
|
||||||
API_SERVER_PORT = 3000
|
API_SERVER_PORT = 3000
|
||||||
|
|
||||||
|
# Database settings
|
||||||
POSTGRES_SERVER = localhost
|
POSTGRES_SERVER = localhost
|
||||||
POSTGRES_USERNAME = postgres
|
POSTGRES_USERNAME = postgres
|
||||||
POSTGRES_PASSWORD = postgres
|
POSTGRES_PASSWORD = postgres
|
||||||
POSTGRES_PORT = 5432
|
POSTGRES_PORT = 5432
|
||||||
|
|
||||||
|
# Application settings
|
||||||
|
ALLOW_USER_REGISTRATION = true
|
|
@ -31,10 +31,8 @@ const jwt = require('jsonwebtoken');
|
||||||
// POST
|
// POST
|
||||||
async function registerPerson(req, res){
|
async function registerPerson(req, res){
|
||||||
|
|
||||||
const userData = req.body;
|
|
||||||
|
|
||||||
// Ensure that the required fields are present before proceeding
|
// Ensure that the required fields are present before proceeding
|
||||||
if (!userData.display_name || !userData.email || !userData.password) {
|
if (!req.body.display_name || !req.body.email || !req.body.password) {
|
||||||
return res.status(400).json("Invalid request.");
|
return res.status(400).json("Invalid request.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +40,7 @@ async function registerPerson(req, res){
|
||||||
const activationLink = crypto.randomBytes(16).toString('hex');
|
const activationLink = crypto.randomBytes(16).toString('hex');
|
||||||
|
|
||||||
// Hash provided password
|
// Hash provided password
|
||||||
const hashPasswordPromise = bcrypt.hash(userData.password, 10);
|
const hashPasswordPromise = bcrypt.hash(req.body.password, 10);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
// Begin transaction
|
// Begin transaction
|
||||||
|
@ -50,13 +48,13 @@ async function registerPerson(req, res){
|
||||||
|
|
||||||
const personIdResult = await tr('Person')
|
const personIdResult = await tr('Person')
|
||||||
.insert({
|
.insert({
|
||||||
email: userData.email,
|
email: req.body.email,
|
||||||
password: await hashPasswordPromise,
|
password: await hashPasswordPromise,
|
||||||
display_name: userData.display_name,
|
display_name: req.body.display_name,
|
||||||
date_of_birth: userData.date_of_birth,
|
date_of_birth: req.body.date_of_birth,
|
||||||
available: userData.available,
|
available: req.body.available,
|
||||||
enabled: true,
|
enabled: true,
|
||||||
place_of_living: userData.place_of_living})
|
place_of_living: req.body.place_of_living})
|
||||||
.returning("id");
|
.returning("id");
|
||||||
|
|
||||||
await tr('ActivationLink')
|
await tr('ActivationLink')
|
||||||
|
@ -75,15 +73,12 @@ async function registerPerson(req, res){
|
||||||
|
|
||||||
// POST
|
// POST
|
||||||
async function login(req, res){
|
async function login(req, res){
|
||||||
|
|
||||||
const userData = req.body;
|
|
||||||
|
|
||||||
// Ensure that the required fields are present before proceeding
|
// Ensure that the required fields are present before proceeding
|
||||||
if (!userData.email || !userData.password) {
|
if (!req.body.email || !req.body.password) {
|
||||||
return res.status(400).json("Invalid request");
|
return res.status(400).json("Invalid request");
|
||||||
}
|
}
|
||||||
|
|
||||||
const person = await checkUserCredentials(userData.email, userData.password);
|
const person = await checkUserCredentials(req.body.email, req.body.password);
|
||||||
|
|
||||||
if (person){
|
if (person){
|
||||||
const token = generateToken(person.id);
|
const token = generateToken(person.id);
|
||||||
|
@ -117,10 +112,9 @@ async function getPerson(req, res){
|
||||||
|
|
||||||
// POST
|
// POST
|
||||||
async function createOrganization(req, res){
|
async function createOrganization(req, res){
|
||||||
const organizationData = req.body;
|
|
||||||
|
|
||||||
// Ensure that the required fields are present before proceeding
|
// Ensure that the required fields are present before proceeding
|
||||||
if (!organizationData.name) {
|
if (!req.body.name) {
|
||||||
return res.status(400).json("Invalid request.");
|
return res.status(400).json("Invalid request.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,10 +122,10 @@ async function createOrganization(req, res){
|
||||||
knex.transaction(async (trx) => {
|
knex.transaction(async (trx) => {
|
||||||
const organizationResult = await trx('Organization')
|
const organizationResult = await trx('Organization')
|
||||||
.insert({
|
.insert({
|
||||||
name: organizationData.name,
|
name: req.body.name,
|
||||||
location: organizationData.location,
|
location: req.body.location,
|
||||||
description: organizationData.description,
|
description: req.body.description,
|
||||||
is_hiring: organizationData.is_hiring,
|
is_hiring: req.body.is_hiring,
|
||||||
})
|
})
|
||||||
.returning('*');
|
.returning('*');
|
||||||
|
|
||||||
|
@ -174,19 +168,18 @@ async function deleteOrganization(req, res){
|
||||||
|
|
||||||
// POST
|
// POST
|
||||||
async function createOrganizationPost(req, res){
|
async function createOrganizationPost(req, res){
|
||||||
const organizationPostData = req.body;
|
|
||||||
|
|
||||||
// Ensure that the required fields are present before proceeding
|
// Ensure that the required fields are present before proceeding
|
||||||
if (!organizationPostData.organization_id || !organizationPostData.content) {
|
if (!req.body.organization_id || !req.body.content) {
|
||||||
return res.status(400).json("Invalid request.");
|
return res.status(400).json("Invalid request.");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (await isPersonOrganizationAdmin(req.jwt.person_id, organizationPostData.organization_id)){
|
if (await isPersonOrganizationAdmin(req.jwt.person_id, req.body.organization_id)){
|
||||||
const organizationPost = await knex('OrganizationPost')
|
const organizationPost = await knex('OrganizationPost')
|
||||||
.insert({
|
.insert({
|
||||||
organization_id: organizationPostData.organization_id,
|
organization_id: req.body.organization_id,
|
||||||
content: organizationPostData.content,
|
content: req.body.content,
|
||||||
})
|
})
|
||||||
.returning('*');
|
.returning('*');
|
||||||
return res.status(200).json(organizationPost[0]);
|
return res.status(200).json(organizationPost[0]);
|
||||||
|
@ -266,7 +259,7 @@ async function isPersonOrganizationAdmin(personId, organizationId){
|
||||||
.where('id_person', personId)
|
.where('id_person', personId)
|
||||||
.where('id_organization', organizationId)
|
.where('id_organization', organizationId)
|
||||||
.select('*')
|
.select('*')
|
||||||
.first(); // Retrieve the first matching row
|
.first();
|
||||||
|
|
||||||
if (organizationAdministrator) {
|
if (organizationAdministrator) {
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue