add msg in case unconsistent key

This commit is contained in:
2023-12-29 13:38:47 +01:00
parent ed8a747b0b
commit c5899f21e4
15 changed files with 6548 additions and 3483 deletions

View File

@@ -8,11 +8,28 @@ const isAuthenticated = require("../middlewares/isAuthenticated");
const router = express.Router();
/**
* wait Sagar feedback for language and label description
* @ api {post} /api/notifications/backend - Notification Backend post
* @apiName notifBackend
* @apiDescription Send an api result {status,ref,msg,data} to get personnalize notification by header.xlang abd by data
* @apiGroup Notification
*
* @apiBody {integer} status an http status
* @apiBody {string} ref an existing model name
* @apiBody {string} msg a key word existing in referentiual
* */
router.post("/backend", (req, res) => {
})
/**
* @api {get} /notifications/:alias/:tribeId
* @apiName notiflist
* @apiDescription Get list of notifications for an alias and a tribe
* @apiGroup Notification
* @apiGroup Notifications
*
* @apiParam {string} alias
* @apiParam {string} tribeId
@@ -20,11 +37,73 @@ const router = express.Router();
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {status:200,ref:"Notification",msg:"Messagelist",data:{notif:[{tribeId,msg:{from(email or uuid or alias):[{dt,msg}]}}]}
*
* bouture
**/
router.get("/:alias/:tribeId", (req, res) => {
const getnot = Notification.get(req.params.alias,req.params.tribeId);
const getnot = Notification.get(req.params.alias, req.params.tribeId);
res.status(getalias.status).send(getalias);
});
module.exports=router;
router.post("/registeranonymous", checkHeaders, (req, res) => {
['uuid','srckey','mlist'].forEach(k=>{
if (!req.body[k]){}
});
res.status().json({status:410, ref:"", msg:""})
let result;
if (req.body.email) {
result= Notifications.registertolist(
req.body.email,
"email",
req.session.header.xtribe,
req.body.mlist,
req.body.srckey,
req.body.uuid);
}
res(200).json({status:200})
})
/**
* @api {POST} /actions/contactanonymous -Contact anonymous
* @apiName contactanonymous
* @apiGroup Notifications
* @apiDescription Run action store in body.order and update mailinglist or create contact message
*
* @apiBody {string} order name of function for action in Actions.js example:registercontact ,
* @apiBody {string} srckey: where it come from and eventualy email template name to use to send email ,
* @apiBody {string} email to use
* @apiBody {string} route /actions/contactanonymous
* @apiBody {string} [mlist] filename to store email registration /contacts/mlist.json if not => filename is quest_/contacts/email.json with {email:{dt_create,dt_update, src:[list of source]}} or add message in /contacts/quest_{email}.json {timestamp:{message,name,email,dt_create,emailcontact}}
* @apiBody {string} others any other usefull key:value relevant for order action
*
* @apiSuccess {object} update/contacts/{mlist}.json successfull
* @apiSuccessExample {json} successfullmessage
* HTTP/1.1 200 OK
* {"status":200, "ref":"Contact", "msg":"success", "data":{"indexlist":[]}}
*
*/
router.post("/contactanonymous", checkHeaders, async (req, res) => {
const done = Actions[req.body.order]
? await Actions[req.body.order](req.body, req.session.header)
: { status: 406, ref: "Actions", msg: "bodyerror", data: req.body };
//console.log('routes contactanonymous ', req.body);
res.status(done.status).json(done);
});
/**
* Same as /copntactanonymous but for authenticated user => data are updated in persons/itm/alias.json
*/
router.post("/contact", checkHeaders, isAuthenticated, (req, res) => {
const done = Actions[req.body.order]
? Actions[req.body.order](req.body, req.session.header)
: { status: 406, ref: "Actions", msg: "bodyerror", data: req.body };
console.log(req.body);
res.status(done.status).json(done);
});
router.get("/contact", checkHeaders, isAuthenticated, (req, res) => {
res.status(200).json({ data: {} });
});
module.exports = router;

View File

@@ -1,5 +1,6 @@
const express = require("express");
const fs = require("fs-extra");
const dayjs=require('dayjs');
const path = require("path");
// Classes
const Pagans = require("../models/Pagans.js");
@@ -41,11 +42,10 @@ router.get("/alias/:alias", (req, res) => {
res.status(getalias.status).send(getalias);
});
/**
* Remove serveur token
* @api {get} /pagans/logout - pagan Logout
* @apiName Removetoken
* @apiGroup Pagans
* @apiDescription Remove token
* @apiDescription Remove server's token only the owner of the token (no one else can delete a token )
*
* @apiSuccess {object} indexfile content
* @apiSuccessExample {json} Success-Response:
@@ -97,7 +97,8 @@ router.get("/isauth", checkHeaders, isAuthenticated, (req, res) => {
* @apiGroup Pagans
* @apiDescription
* Create a pagan account from alias, publickey, if trusted recovery =>
* Create a person in xtribe/person/xalias.json with profil.auth={email,privatekey, passphrase}
* If trustedtribe is true then create a person in xtribe/person/xalias.json with profil.auth={email,privatekey, passphrase}.
*
* Middleware isAuthenticated check that:
* - xhash is well signed from private key linked to the publickey of alias
* - check that alias does not already exist (if yes then verifiedsigne would be false)
@@ -107,7 +108,8 @@ router.get("/isauth", checkHeaders, isAuthenticated, (req, res) => {
* @apiBody {string} [email] if specified then an email is sent to it with public and privatekey
* @apiBody {string} [privatekey]
* @apiBody {string} [passphrase] if not specidied => passphrase=""
* @apiBody {string} [trustedtribe] the tribename if not specified then the process will only create a pagan identity, else an item person is create for trustedtribe (that must exist with profil 'person'). To create a person with an existing pagan identity use put /api/person/:alias after authenticated you (headers). In case a person is created then we use all valid other apiBody respecting rules https://smatchit.io/api/odmdb/schema/persons.json
* @apiBody {string} [trustedtribe] the tribename if not specified then the process will only create a pagan identity, else an item person is create for trustedtribe (that must exist with profil 'person'). To create a person with an existing pagan identity use put /api/person/:alias after authenticated you (headers). In case a person is created then we use all valid other apiBody respecting the persons schema (see put persons)
* @apiBody {object} schema:pagans <a href='https://wall-ants.ndda.fr/nationchains/schema/pagans.json' target='_blank'>https://wall-ants.ndda.fr/nationchains/schema/pagans.json</a>
*
* @apiError {json} objectNotfound the file does not exist
* @apiErrorExample {json}
@@ -121,7 +123,7 @@ router.get("/isauth", checkHeaders, isAuthenticated, (req, res) => {
*
*/
router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
console.log("pass ici", req.body);
log('dev',`passici ${req.body}`);
const role = {
xalias: req.session.header.xalias,
xprofils: req.session.header.xprofils,
@@ -191,22 +193,37 @@ router.post("/", checkHeaders, isAuthenticated, async (req, res) => {
* @apiName deletepagan
* @apiGroup Pagans
* @apiDescription
* Delete an alias and his publickey, this mean that publickey disapear as well as alias. All tribe will be inform and will delete person of this alias if they have. This alias will be availlable after 1 year.
* Delete an alias and his publickey, this mean that publickey disapear as well as alias. We set dt_delete
* */
router.delete("/alias/:alias", checkHeaders, isAuthenticated, (req, res) => {
const personpath=`../nationchains/pagans`;
const role = {
xalias: req.session.header.xalias,
xprofils: req.session.header.xprofils,
};
req.session.header.role
const delperson = Odmdb.cud(personpath,"U",{alias:req.params.alias,dt_delete:dayjs().toISOString()},role,true);
console.log(`DELETE person ${personpath}/${req.params.alias}.json `);
console.log(delperson)
res.status(delperson.status).json(delperson);
console.log(`DELETE pagans nationchains/pagans/${req.params.alias}.json`);
const result = Pagans.deletealias(req.params.id, req.session.header);
const result = Pagans.delete(req.params.alias, req.session.header);
res.status(result.status).send(result);
});
/**
* @api {delete} /pagans/person/:alias - person Delete
* @api {delete} /pagans/person/:tribe/:alias - person Delete
* @apiName deleteperson
* @apiGroup Pagans
* @apiDescription
* Unsubscribe a person to a tribe => remove a person item and all data link to this alias
* @apiHeader {array} xprofils list of profil of authenticated user
* @apiHeader {string} xalias current user
* @apiParam {string} tribe where person alias exist
* @apiParam {string} alias to delete as person
* */
router.delete("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
const personpath=`../nationchains/tribes/${req.session.header.xtribe}/objects/persons`;
router.delete("/person/:tribe/:alias", checkHeaders, isAuthenticated, (req, res) => {
const personpath=`../nationchains/tribes/${req.params.tribe}/objects/persons`;
const role = {
xalias: req.session.header.xalias,
xprofils: req.session.header.xprofils,
@@ -244,17 +261,19 @@ router.get("/person/:alias", checkHeaders, isAuthenticated, (req, res) => {
});
/**
* @api {put} /pagans/person - person Put
* @api {put} /pagans/person/:tribe - person Put
* @apiName updateperson
* @apiGroup Pagans
* @apiDescription add or update a person = alias in a tribe. alias authenticated must have a profil with accessright into schema person.
* @apiHeader {string} xalias
* @apiParam {object} in line with schema in https://smatchit.io/api/odmdb/schema/persons
* @apiDescription add or update a person = alias in tribe. xalias authenticated (in header) must have a profil with accessright into schema person to create a person.
* @apiHeader {string} xhash authenthicate hash with current user keys
* @apiHeader {string} xalias current user
* @apiHeader {string} xprofils profil list
* @apiParam {object} schema:persons <a href='https://smatchit.io/smatchit/schema/persons.json' target='_blank'>https://dnstribe/tribe/schema/persons.json</a>
*
*/
router.put("/person", checkHeaders, isAuthenticated, (req, res) => {
router.put("/person/:tribe", checkHeaders, isAuthenticated, (req, res) => {
//console.log(req.body);
const pathobj=`../nationchains/tribes/${req.session.header.xtribe}/objects/persons`;
const pathobj=`../nationchains/tribes/${req.params.tribe}/objects/persons`;
const action = (fs.existsSync(`${pathobj}/itm/${req.body.alias}.json`))? "U":"C";
//set req.body to be in line with schema
if (!req.body.profils){
@@ -266,7 +285,7 @@ router.put("/person", checkHeaders, isAuthenticated, (req, res) => {
});
/**
* @api {get} /pagans/keyrecovery/tribe/email - recovery keys by email
* @api {get} /pagans/keyrecovery/:tribe/:email - recovery keys by email
* @apiName recoveryKey
* @apiGroup Pagans
* @apiDescription Send mails with all registers identities (one per alias where recoveryauth.email is register)