generated from Arquisoft/lomap_0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from Arquisoft/documentation-1.1-sara
Documentation - Part 6 checked
- Loading branch information
Showing
14 changed files
with
491 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.buildTestLocationThing = exports.locationToThing = exports.thingToLocation = void 0; | ||
const solid_client_1 = require("@inrupt/solid-client"); | ||
const vocab_common_rdf_1 = require("@inrupt/vocab-common-rdf"); | ||
function thingToLocation(locationThing) { | ||
return { | ||
id: locationThing.url, | ||
name: (0, solid_client_1.getStringNoLocale)(locationThing, vocab_common_rdf_1.SCHEMA_INRUPT.name), | ||
locationType: (0, solid_client_1.getStringNoLocale)(locationThing, vocab_common_rdf_1.SCHEMA_INRUPT.description), | ||
latitude: (0, solid_client_1.getDecimal)(locationThing, vocab_common_rdf_1.SCHEMA_INRUPT.latitude), | ||
longitude: (0, solid_client_1.getDecimal)(locationThing, vocab_common_rdf_1.SCHEMA_INRUPT.longitude) | ||
}; | ||
} | ||
exports.thingToLocation = thingToLocation; | ||
function locationToThing(location) { | ||
return (0, solid_client_1.buildThing)((0, solid_client_1.createThing)({ name: location.name })) | ||
.addStringNoLocale(vocab_common_rdf_1.SCHEMA_INRUPT.name, location.name) | ||
.addStringNoLocale(vocab_common_rdf_1.SCHEMA_INRUPT.description, location.locationType) | ||
.addDecimal(vocab_common_rdf_1.SCHEMA_INRUPT.latitude, location.latitude) | ||
.addDecimal(vocab_common_rdf_1.SCHEMA_INRUPT.longitude, location.longitude) | ||
.addUrl(vocab_common_rdf_1.RDF.type, "https://schema.org/Place") | ||
.build(); | ||
} | ||
exports.locationToThing = locationToThing; | ||
function buildTestLocationThing() { | ||
return (0, solid_client_1.buildThing)((0, solid_client_1.createThing)({ name: "Location2" })) | ||
.addStringNoLocale(vocab_common_rdf_1.SCHEMA_INRUPT.name, 'nuevaLocalizacion2') | ||
.addStringNoLocale(vocab_common_rdf_1.SCHEMA_INRUPT.description, "bar") | ||
.addDecimal(vocab_common_rdf_1.SCHEMA_INRUPT.latitude, 1) | ||
.addDecimal(vocab_common_rdf_1.SCHEMA_INRUPT.longitude, 2) | ||
.addUrl(vocab_common_rdf_1.RDF.type, "https://schema.org/Place") | ||
.build(); | ||
} | ||
exports.buildTestLocationThing = buildTestLocationThing; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LocationType = void 0; | ||
var LocationType; | ||
(function (LocationType) { | ||
LocationType["shop"] = "shop"; | ||
LocationType["bar"] = "bar"; | ||
LocationType["restaurant"] = "restaurant"; | ||
LocationType["sight"] = "sight"; | ||
LocationType["monument"] = "monument"; | ||
})(LocationType = exports.LocationType || (exports.LocationType = {})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const solid_client_authn_node_1 = require("@inrupt/solid-client-authn-node"); | ||
exports.default = { | ||
initLogin: function (req, res) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// create a new Session | ||
const session = new solid_client_authn_node_1.Session(); | ||
req.session.solidSessionId = session.info.sessionId; | ||
console.log(req.query.providerURL); | ||
console.log(req.session.solidSessionId); | ||
//Redirect user to POD provider login | ||
const redirectToSolidIdentityProvider = (providerURL) => { | ||
res.redirect(providerURL); | ||
}; | ||
// redirect handler will handle sending the user to their POD Provider. | ||
yield session.login({ | ||
// If login successfully, redirect here | ||
redirectUrl: 'http://localhost:8082/auth/loginconfirm', | ||
// Set user SOLID identity provider | ||
oidcIssuer: req.query.providerURL, | ||
//oidcIssuer: "https://login.inrupt.com", | ||
// Application name to show when requesting data | ||
clientName: "LoMap", | ||
//handler to redirect to the provider login | ||
handleRedirect: redirectToSolidIdentityProvider | ||
}); | ||
}); | ||
}, | ||
confirmLogin: function (req, res) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// If we get here, the user has logged in successfully | ||
// Recover session information | ||
const session = yield (0, solid_client_authn_node_1.getSessionFromStorage)(req.session.solidSessionId); | ||
// Complete login process using the data appended by the Solid Identity Provider | ||
try { | ||
yield session.handleIncomingRedirect(`http://localhost:8082/auth${req.url}`); | ||
} | ||
catch (e) { | ||
console.log(e); | ||
return res.sendStatus(500); | ||
} | ||
// Session now contains an authenticated Session instance. | ||
if (session.info.isLoggedIn) { | ||
return res.redirect("http://localhost:3000/login/confirm"); | ||
} | ||
return res.sendStatus(401); | ||
}); | ||
}, | ||
logout: function (req, res) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const session = yield (0, solid_client_authn_node_1.getSessionFromStorage)(req.session.solidSessionId); | ||
yield session.logout(); | ||
res.redirect("http://localhost:3000"); | ||
}); | ||
}, | ||
initTestLogin: function (req, res) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// create a new Session | ||
const session = new solid_client_authn_node_1.Session(); | ||
req.session.solidSessionId = session.info.sessionId; | ||
console.log(req.session.solidSessionId); | ||
//Redirect user to POD provider login | ||
const redirectToSolidIdentityProvider = (providerURL) => { | ||
res.redirect(providerURL); | ||
}; | ||
// redirect handler will handle sending the user to their POD Provider. | ||
yield session.login({ | ||
// If login successfully, redirect here | ||
redirectUrl: 'http://localhost:8082/auth/testloginconfirm', | ||
// Set user SOLID identity provider | ||
oidcIssuer: "https://login.inrupt.com", | ||
// Application name to show when requesting data | ||
clientName: "LoMap", | ||
//handler to redirect to the provider login | ||
handleRedirect: redirectToSolidIdentityProvider | ||
}); | ||
}); | ||
}, | ||
confirmTestLogin: function (req, res) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
// If we get here, the user has logged in successfully | ||
// Recover session information | ||
console.log(req.session.solidSessionId); | ||
const session = yield (0, solid_client_authn_node_1.getSessionFromStorage)(req.session.solidSessionId); | ||
// Complete login process using the data appended by the Solid Identity Provider | ||
yield session.handleIncomingRedirect(`http://localhost:8082/auth${req.url}`); | ||
console.log(session === null || session === void 0 ? void 0 : session.info.webId); | ||
// Session now contains an authenticated Session instance. | ||
if (session.info.isLoggedIn) { | ||
return res.redirect("http://localhost:3000"); | ||
} | ||
return res.send("Not able to log in"); | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const solid_client_1 = require("@inrupt/solid-client"); | ||
const solid_client_authn_node_1 = require("@inrupt/solid-client-authn-node"); | ||
const locationBuilder_1 = require("../builders/locationBuilder"); | ||
const locationValidator_1 = require("../validators/locationValidator"); | ||
exports.default = { | ||
saveLocation: function (req, res) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
console.log("saving location"); | ||
console.log(req.session.solidSessionId); | ||
const session = yield (0, solid_client_authn_node_1.getSessionFromStorage)(req.session.solidSessionId); | ||
if (session == undefined) { | ||
console.log("not valid session"); | ||
return res.send('error'); | ||
} | ||
let locationsURL = yield getLocationsURL(session.info.webId); | ||
if (locationsURL == undefined) { | ||
console.log("error accessing the pod"); | ||
return res.send("error"); | ||
} | ||
let location = req.body.location; | ||
console.log(req.body); | ||
if (!(0, locationValidator_1.validateLocation)(location)) { | ||
console.log("not valid location"); | ||
console.log(location); | ||
res.send('error'); | ||
} | ||
let locationsSolidDataset = yield (0, solid_client_1.getSolidDataset)(locationsURL, { fetch: session.fetch } // fetch from authenticated session | ||
); | ||
const locationThing = (0, locationBuilder_1.locationToThing)(location); | ||
locationsSolidDataset = (0, solid_client_1.setThing)(locationsSolidDataset, locationThing); | ||
let newDataset = yield (0, solid_client_1.saveSolidDatasetAt)(locationsURL, locationsSolidDataset, { fetch: session.fetch } // fetch from authenticated Session | ||
); | ||
console.log("location saved"); | ||
return res.send((0, solid_client_1.getThingAll)(newDataset).map(locationThing => (0, locationBuilder_1.thingToLocation)(locationThing))); | ||
}); | ||
}, | ||
getOwnLocations: function (req, res) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const session = yield (0, solid_client_authn_node_1.getSessionFromStorage)(req.session.solidSessionId); | ||
if (session == undefined) | ||
return res.send('error'); | ||
let locationsURL = yield getLocationsURL(session.info.webId); | ||
if (locationsURL == undefined) | ||
return res.send("error"); | ||
let locationsDataset = yield (0, solid_client_1.getSolidDataset)(locationsURL, { fetch: session.fetch } // fetch from authenticated session | ||
); | ||
return res.send((0, solid_client_1.getThingAll)(locationsDataset) | ||
.filter(locationThing => (0, locationValidator_1.validateLocationThing)(locationThing)) | ||
.map(locationThing => (0, locationBuilder_1.thingToLocation)(locationThing))); | ||
}); | ||
}, | ||
saveTestLocation: function (req, res) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const session = yield (0, solid_client_authn_node_1.getSessionFromStorage)(req.session.solidSessionId); | ||
if (session == undefined) | ||
return res.send('error'); | ||
let locationsURL = yield getLocationsURL(session.info.webId); | ||
if (locationsURL == undefined) | ||
return res.send("error"); | ||
const locationThing = (0, locationBuilder_1.buildTestLocationThing)(); | ||
let locationsSolidDataset = yield (0, solid_client_1.getSolidDataset)(locationsURL, { fetch: session.fetch } // fetch from authenticated session | ||
); | ||
locationsSolidDataset = (0, solid_client_1.setThing)(locationsSolidDataset, locationThing); | ||
let newDataset = yield (0, solid_client_1.saveSolidDatasetAt)(locationsURL, locationsSolidDataset, { fetch: session.fetch } // fetch from authenticated Session | ||
); | ||
return res.send((0, solid_client_1.getThingAll)(newDataset).map(locationThing => (0, locationBuilder_1.thingToLocation)(locationThing))); | ||
}); | ||
} | ||
}; | ||
function getLocationsURL(webId) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (webId == undefined) | ||
return undefined; | ||
let webID = decodeURIComponent(webId); | ||
const podURL = yield (0, solid_client_1.getPodUrlAll)(webID); | ||
console.log(podURL); | ||
return podURL + "private/"; | ||
}); | ||
} |
Oops, something went wrong.