add route get alias and person

This commit is contained in:
philc 2023-06-07 07:32:23 +02:00
parent 41dbd92e4a
commit fd712a6d73
6 changed files with 77 additions and 38 deletions

View File

@ -73,8 +73,7 @@
</code> </code>
<hr> <hr>
<h3>Logout</h3> <h3>Logout</h3>
<button type="button" class="btn btn-outline-success btn-sm" <button type="button" class="btn btn-outline-success btn-sm" onclick="pagans.logout();">
onclick="pagans.logout();">
Remove headers</button> Remove headers</button>
<hr> <hr>
<h3>I prove that i own this alias</h3> <h3>I prove that i own this alias</h3>
@ -89,7 +88,8 @@
</div> </div>
<textarea rows="5" id="privatekeyauth"></textarea> <textarea rows="5" id="privatekeyauth"></textarea>
<button class="btn btn-primary" <button class="btn btn-primary"
onclick="pagans.authentifyme(document.getElementById('inputaliasauth').value,document.getElementById('inputpassphraseauth').value,document.getElementById('privatekeyauth').value);alert('Click on Test it to check')">Sign my header</button> onclick="pagans.authentifyme(document.getElementById('inputaliasauth').value,document.getElementById('inputpassphraseauth').value,document.getElementById('privatekeyauth').value);alert('Click on Test it to check')">Sign
my header</button>
<hr> <hr>
<h3>Create a decentralized Identity</h3> <h3>Create a decentralized Identity</h3>
<p>apXtrib allow you to create keys to identify yourself with a universal alias</p> <p>apXtrib allow you to create keys to identify yourself with a universal alias</p>
@ -148,10 +148,10 @@
<div id="downloadkeys" class="btn-group d-none"> <div id="downloadkeys" class="btn-group d-none">
<p>Download your keys at least PrivateKey this have to save in a secret place</p> <p>Download your keys at least PrivateKey this have to save in a secret place</p>
<button id="privatekey" key="" class="btn btn-outline-primary" <button id="privatekey" key="" class="btn btn-outline-primary"
onclick="app.downloadlink('tmp.privateKey',apx.data,apx.data.headers.xapp);">Download onclick="app.downloadlink('tmp.privateKey',apx.data,apx.data.headers.xalias);">Download
PrivateKey</button> PrivateKey</button>
<button id="publickey" key="" class="btn btn-outline-primary" <button id="publickey" key="" class="btn btn-outline-primary"
onclick="app.downloadlink('tmp.publicKey',apx.data,apx.data.headers.xapp);">Download onclick="app.downloadlink('tmp.publicKey',apx.data,apx.data.headers.xalias);">Download
PublicKey</button> PublicKey</button>
</div> </div>
<div id="createId" class="col-12 d-none"> <div id="createId" class="col-12 d-none">

View File

@ -1,23 +0,0 @@
<div class="container">
<h5>How to identify ourself</h5>
<p>You need to know your alias and to have your privateKey file</p>
<div class="mb-3">
<label for="youralias" class="form-label">Your alias</label>
<input type="email" class="form-control" id="youralias" aria-describedby="aliasHelp">
<div id="aliasHelp" class="form-text">Your unique alias when you create your account</div>
</div>
<div class="mb-3">
<label for="inputprivateKey" class="form-label">Copy & paste or load your private Key</label>
<textarea type="password" class="form-control" id="inputprivateKey" rows="6"></textarea>
<div id="inputprivateKey" class="form-text">I forgot my keys, <a onclick="">click to request it with my email recovery</a> or <a onclick="">Click to receive it from my alias</a> </div>
</div>
<div class="mb-3">
<label for="emailrecovery" class="form-label">Your email recovery</label>
<input type="email" class="form-control" id="emailrecovery" placeholder="name@example.com">
</div>
<div class="input-group">
<input type="file" class="form-control" id="inputGroupFile04" aria-describedby="inputGroupFileAddon04" aria-label="Upload">
<button class="btn btn-outline-secondary" type="button" id="inputGroupFileAddon04">Button</button>
</div>
<button type="submit" class="btn btn-primary d-none">Identify you</button>
</div>

Binary file not shown.

View File

@ -19,6 +19,50 @@ const conf = require(`${process.env.dirtown}/conf.json`);
const Pagans = {}; const Pagans = {};
Pagans.getalias = (alias) => {
console.log(`${conf.dirapi}/nationchains/pagans/itm/${alias}.json`);
if (fs.existsSync(`${conf.dirapi}/nationchains/pagans/itm/${alias}.json`)) {
return {
status: 200,
ref: "Pagans",
msg: "aliasexist",
data: fs.readJsonSync(
`${conf.dirapi}/nationchains/pagans/itm/${alias}.json`
),
};
} else {
return {
status: 404,
ref: "Pagans",
msg: "aliasdoesnotexist",
data: { alias },
};
}
};
Pagans.getperson = (alias, tribeid) => {
if (
fs.existsSync(`${conf.dirtown}/tribes/${tribeid}/person/itm/${alias}.json`)
) {
const person = fs.readJsonSync(
`${conf.dirtown}/tribes/${tribeid}/person/itm/${alias}.json`
);
return {
status: 200,
ref: "Pagans",
msg: "personexist",
data: person,
};
} else {
return {
status: 404,
ref: "Pagans",
msg: "persondoesnotexist",
data: { alias, tribeid },
};
}
};
Pagans.create = (alias, publicKey) => { Pagans.create = (alias, publicKey) => {
/** /**
* @param {string} alias a unique alias that identify an identity * @param {string} alias a unique alias that identify an identity

View File

@ -47,6 +47,15 @@ Delete idem
Owner means it can be Write/Delete if field OWNER contain the UUID that try to act on this object. Usefull to allow someone to fully manage its objects. Owner means it can be Write/Delete if field OWNER contain the UUID that try to act on this object. Usefull to allow someone to fully manage its objects.
*/ */
router.get("/alias/:alias", (req, res) => {
res.send(Pagans.getalias(req.params.alias));
});
router.get("/person/:alias", (req, res) => {
// check accessright for req.session.header.xalias to see if jhe can get person data
// if req.param.alias == req.session.header.xalias => Owner
// else need accessright to on person set at R
res.send(Pagans.getperson(req.params.alias, req.session.header.xtribe));
});
router.get("/isauth", checkHeaders, isAuthenticated, (req, res) => { router.get("/isauth", checkHeaders, isAuthenticated, (req, res) => {
/** /**

View File

@ -180,14 +180,23 @@ if (
) { ) {
setconf(param); setconf(param);
} }
// From git setup-xx is set to nationId:ant townId:farmdev (keyword for dev) // setup_xx.json is gitignore so at first install we are in dev configuration
let infotown = {nationId:"ants",townId:"devfarm",dns:["devfarm-ants"],comment:"Auto generate setup from apxtrib after node apxtrib nationId:value townId:value dns:domaine_to_access"} let infotown = {
nationId: "ants",
townId: "devfarm",
dns: ["devfarm-ants"],
comment:
"Auto generate setup from apxtrib after node apxtrib nationId:value townId:value dns:domaine_to_access",
};
if (fs.existsSync(`${__dirname}/adminapi/www/adminapx/conf/setup_xx.json`)) { if (fs.existsSync(`${__dirname}/adminapi/www/adminapx/conf/setup_xx.json`)) {
infotown = fs.readJsonSync( infotown = fs.readJsonSync(
`${__dirname}/adminapi/www/adminapx/conf/setup_xx.json` `${__dirname}/adminapi/www/adminapx/conf/setup_xx.json`
); );
} else { } else {
fs.outputJsonSync(`${__dirname}/adminapi/www/adminapx/conf/setup_xx.json`,infotown); fs.outputJsonSync(
`${__dirname}/adminapi/www/adminapx/conf/setup_xx.json`,
infotown
);
} }
if ( if (
@ -198,7 +207,7 @@ if (
) || ) ||
!fs.existsSync(`${__dirname}/adminapi/www/nginx_adminapx.conf`) !fs.existsSync(`${__dirname}/adminapi/www/nginx_adminapx.conf`)
) { ) {
// Run setup with information setup_xx.json // Case of new town or request a reset of dns to access adminapx
setconf(infotown); setconf(infotown);
} }
const conf = require(path.resolve( const conf = require(path.resolve(