Skip to content

Commit

Permalink
Merge pull request #207 from openaddresses/tilebase2
Browse files Browse the repository at this point in the history
Tilebase & Resend Email
  • Loading branch information
ingalls authored Oct 1, 2021
2 parents d25c6a7 + 54d3d6e commit 47e5427
Show file tree
Hide file tree
Showing 15 changed files with 297 additions and 66 deletions.
22 changes: 22 additions & 0 deletions api/doc/api_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -3011,6 +3011,27 @@ define({ "api": [
"field": ":job",
"description": "<p>Job ID</p>"
}
],
"Query": [
{
"group": "Query",
"type": "Boolean",
"optional": true,
"field": "dl",
"description": "<p>Optional param to set content-disposition - forcing the browser to download</p>"
},
{
"group": "Query",
"type": "String",
"allowedValues": [
"\"json\"",
"\"csv\""
],
"optional": true,
"field": "format",
"defaultValue": "json",
"description": ""
}
]
}
},
Expand Down Expand Up @@ -4660,6 +4681,7 @@ define({ "api": [
"type": "String",
"allowedValues": [
"\"close\"",
"\"fabric\"",
"\"scale\"",
"\"level\"",
"\"collect\"",
Expand Down
22 changes: 22 additions & 0 deletions api/doc/api_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -3011,6 +3011,27 @@
"field": ":job",
"description": "<p>Job ID</p>"
}
],
"Query": [
{
"group": "Query",
"type": "Boolean",
"optional": true,
"field": "dl",
"description": "<p>Optional param to set content-disposition - forcing the browser to download</p>"
},
{
"group": "Query",
"type": "String",
"allowedValues": [
"\"json\"",
"\"csv\""
],
"optional": true,
"field": "format",
"defaultValue": "json",
"description": ""
}
]
}
},
Expand Down Expand Up @@ -4660,6 +4681,7 @@
"type": "String",
"allowedValues": [
"\"close\"",
"\"fabric\"",
"\"scale\"",
"\"level\"",
"\"collect\"",
Expand Down
2 changes: 1 addition & 1 deletion api/doc/api_project.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion api/doc/api_project.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"apidoc": "0.3.0",
"generator": {
"name": "apidoc",
"time": "2021-09-30T01:40:14.063Z",
"time": "2021-10-01T16:52:23.494Z",
"url": "https://apidocjs.com",
"version": "0.29.0"
}
Expand Down
13 changes: 8 additions & 5 deletions api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,17 +286,20 @@ async function server(args, config, cb) {
res: 'res.User.json'
}, async (req, res) => {
try {
const usr = await user.register(req.body);
if (req.body.password) {
await user.register(req.body);
}

const forgot = await user.forgot(usr.username, 'verify');
const forgot = await user.forgot(req.body.username, 'verify');

if (args.email) await email.verify({
username: usr.username,
email: usr.email,
username: forgot.username,
email: forgot.email,
token: forgot.token
});

res.json(usr);
delete forgot.token;
res.json(forgot);
} catch (err) {
return Err.respond(err, res);
}
Expand Down
10 changes: 10 additions & 0 deletions api/lib/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,16 @@ async function trigger(event) {
environment: []
}
};
} else if (event.type === 'fabric') {
params = {
jobDefinition: jobDefinition,
jobQueue: mega_queue,
jobName: 'OA_Fabric',
containerOverrides: {
command: ['./fabric.js'],
environment: []
}
};
} else if (event.type === 'sources') {
params = {
jobDefinition: jobDefinition,
Expand Down
28 changes: 11 additions & 17 deletions api/lib/schedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Schedule {
static async event(pool, event) {
if (event.type === 'collect') {
await Schedule.collect();
} else if (event.type === 'sources') {
await Schedule.sources(pool);
} else if (['fabric', 'collect', 'sources'].includes(event.type)) {
await Schedule.batch(event.type, pool);
} else if (event.type === 'close') {
await Schedule.close(pool);
} else if (event.type === 'level') {
Expand All @@ -30,13 +30,19 @@ class Schedule {
}
}

static async collect() {
/**
* Generic function for triggering a batch job
* @param {String} type Type of batch job to trigger
*/
static async batch(type, pool) {
if (type === 'sources') await JobError.clear(pool);

try {
return await batch.trigger({
type: 'collect'
type: type
});
} catch (err) {
throw new Err(500, err, 'failed to submit collect job to batch');
throw new Err(500, err, 'Failed to submit job to batch');
}
}

Expand All @@ -50,18 +56,6 @@ class Schedule {
}
}

static async sources(pool) {
await JobError.clear(pool);

try {
return await batch.trigger({
type: 'sources'
});
} catch (err) {
throw new Err(500, err, 'failed to submit sources job to batch');
}
}

static async close(pool) {
// TODO Close old run/jobs

Expand Down
16 changes: 13 additions & 3 deletions api/lib/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,11 @@ class User {
SELECT
id,
username,
email
email,
validated,
flags,
level,
access
FROM
users
WHERE
Expand All @@ -200,7 +204,10 @@ class User {

if (pgres.rows.length !== 1) return;
const u = pgres.rows[0];
u.id = parseInt(u.id);

if (action === 'verify' && u.validated) {
throw new Err(400, null, 'User is already verified');
}

try {
await this.pool.query(sql`
Expand Down Expand Up @@ -229,9 +236,12 @@ class User {
`);

return {
uid: u.id,
id: u.id,
username: u.username,
email: u.email,
flags: u.flags,
level: u.level,
access: u.access,
token: buffer.toString('hex')
};
} catch (err) {
Expand Down
52 changes: 32 additions & 20 deletions api/schema/req.body.CreateUser.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,35 @@
{
"type": "object",
"required": [
"username",
"password",
"email"
],
"additionalProperties": false,
"properties": {
"username": {
"type": "string",
"description": "username"
},
"password": {
"type": "string",
"description": "password"
},
"email": {
"type": "string",
"description": "email"
"oneOf": [{
"type": "object",
"required": [
"username",
"password",
"email"
],
"additionalProperties": false,
"properties": {
"username": {
"type": "string",
"description": "username"
},
"password": {
"type": "string",
"description": "password"
},
"email": {
"type": "string",
"description": "email"
}
}
}
},{
"type": "object",
"required": [ "username" ],
"additionalProperties": false,
"properties": {
"username": {
"type": "string",
"description": "username"
}
}
}]
}
1 change: 1 addition & 0 deletions api/schema/req.body.Schedule.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"type": "string",
"enum": [
"close",
"fabric",
"scale",
"level",
"collect",
Expand Down
61 changes: 51 additions & 10 deletions api/web/src/components/Register.vue
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<template>
<div class='col col--12 grid pt12'>
<template v-if='loading'>
<template v-if='loading.page'>
<div class='flex flex--center-main w-full py24'>
<div class='loading'></div>
<div class='loading.page'></div>
</div>
</template>
<template v-else-if='success'>
Expand All @@ -13,9 +13,23 @@
<p class='txt-h4 py6'>Please check your email for a verification link!</p>
</div>
<div class='col col--12 flex flex--center-main'>
<div class='w240 col col--12 grid grid--gut12'>
<button @click='login' class='mt12 w-full color-gray color-green-on-hover btn btn--stroke round'>Login</button>
</div>
<button :disabled='loading.resend || resent' @click='resend' class='mt12 w-full color-gray color-green-on-hover btn btn--stroke round'>
<template v-if='!loading.resend'>
Resend Email
</template>
<template v-else-if='resent'>
Email Resent
</template>
<template v-else>
<div class='col col--12 flex flex--center-main'>
<div class='loading loading--s'></div>
</div>
</template>
</button>
</div>

<div class='col col--12 flex flex--center-main'>
<button @click='login' class='mt12 w-full color-gray color-green-on-hover btn btn--stroke round'>Login</button>
</div>
</template>
<template v-else>
Expand Down Expand Up @@ -55,8 +69,12 @@ export default {
data: function() {
return {
success: false,
resent: false,
attempted: false,
loading: false,
loading: {
page: false,
resend: false
},
email: '',
username: '',
password: ''
Expand All @@ -66,16 +84,38 @@ export default {
login: function() {
this.$router.push('/login');
},
resend: async function() {
try {
if (!this.success) return;
if (!this.username.length) return;
this.loading.resend = true;
await window.std('/api/user', {
method: 'POST',
body: {
username: this.username,
}
});
this.resent = true;
} catch (err) {
this.$emit('err', err);
}
this.loading.resend = false;
},
register: async function() {
try {
this.attempted = true;
if (!this.username.length) return;
if (!this.password.length) return;
if (!this.email.length) return;
this.loading = true;
await window.std('/api/user', {
this.loading.page = true;
this.created = await window.std('/api/user', {
method: 'POST',
body: {
username: this.username,
Expand All @@ -84,11 +124,12 @@ export default {
}
});
this.loading = false;
this.success = true;
} catch (err) {
return this.$emit('err', err);
this.$emit('err', err);
}
this.loading.page = false;
}
}
}
Expand Down
Loading

0 comments on commit 47e5427

Please sign in to comment.