Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
144 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<template> | ||
<ff-layout-box> | ||
<form class="px-4 sm:px-6 lg:px-8 mt-8 space-y-6 max-w-md" @submit.prevent> | ||
<p> | ||
Before you can access the platform, we need to verify your email | ||
address. | ||
</p> | ||
<p> | ||
We sent you an email with a link to click when you signed up. | ||
</p> | ||
<ff-button :disabled="sent" @click="resend"> | ||
<span v-if="!sent">Resend email</span> | ||
<span v-else>Sent</span> | ||
</ff-button> | ||
</form> | ||
</ff-layout-box> | ||
</template> | ||
|
||
<script> | ||
import { mapState } from 'vuex' | ||
import userApi from '@/api/user' | ||
import FFLayoutBox from '@/layouts/Box' | ||
export default { | ||
name: 'UnverifiedEmail', | ||
methods: { | ||
async resend () { | ||
if (!this.sent) { | ||
this.sent = true | ||
await userApi.triggerVerification() | ||
} | ||
} | ||
}, | ||
computed: mapState('account', ['user']), | ||
data () { | ||
return { | ||
sent: false | ||
} | ||
}, | ||
components: { | ||
'ff-layout-box': FFLayoutBox | ||
} | ||
} | ||
</script> |
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,92 @@ | ||
const should = require('should') // eslint-disable-line | ||
const setup = require('../setup') | ||
const FF_UTIL = require('flowforge-test-utils') | ||
const { Roles } = FF_UTIL.require('forge/lib/roles') | ||
|
||
describe('User API', async function () { | ||
let app | ||
const TestObjects = {} | ||
|
||
beforeEach(async function () { | ||
app = await setup({ features: { devices: true } }) | ||
|
||
// alice : admin, team owner | ||
// bob | ||
// chris : (unverified_email) | ||
|
||
// ATeam ( alice (owner), bob (owner), chris) | ||
// BTeam ( bob (owner), chris) | ||
|
||
// Alice create in setup() | ||
TestObjects.alice = await app.db.models.User.byUsername('alice') | ||
TestObjects.bob = await app.db.models.User.create({ username: 'bob', name: 'Bob Solo', email: 'bob@example.com', email_verified: true, password: 'bbPassword', admin: true }) | ||
TestObjects.chris = await app.db.models.User.create({ username: 'chris', name: 'Chris Kenobi', email: 'chris@example.com', password: 'ccPassword' }) | ||
|
||
// ATeam create in setup() | ||
TestObjects.ATeam = await app.db.models.Team.byName('ATeam') | ||
TestObjects.BTeam = await app.db.models.Team.create({ name: 'BTeam' }) | ||
|
||
// Alice set as ATeam owner in setup() | ||
await TestObjects.ATeam.addUser(TestObjects.bob, { through: { role: Roles.Owner } }) | ||
await TestObjects.ATeam.addUser(TestObjects.chris, { through: { role: Roles.Member } }) | ||
await TestObjects.BTeam.addUser(TestObjects.bob, { through: { role: Roles.Owner } }) | ||
await TestObjects.BTeam.addUser(TestObjects.chris, { through: { role: Roles.Member } }) | ||
|
||
TestObjects.tokens = {} | ||
}) | ||
|
||
async function login (username, password) { | ||
const response = await app.inject({ | ||
method: 'POST', | ||
url: '/account/login', | ||
payload: { username, password, remember: false } | ||
}) | ||
response.cookies.should.have.length(1) | ||
response.cookies[0].should.have.property('name', 'sid') | ||
TestObjects.tokens[username] = response.cookies[0].value | ||
} | ||
|
||
afterEach(async function () { | ||
await app.close() | ||
}) | ||
|
||
describe('User settings', async function () { | ||
it('returns 401 on /user if not logged in', async function () { | ||
// await login('alice', 'aaPassword') | ||
// await login('bob', 'bbPassword') | ||
// await login('chris', 'ccPassword') | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: '/api/v1/user' | ||
}) | ||
response.statusCode.should.equal(401) | ||
}) | ||
it('return user info for logged in user', async function () { | ||
await login('alice', 'aaPassword') | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: '/api/v1/user', | ||
cookies: { sid: TestObjects.tokens.alice } | ||
}) | ||
response.statusCode.should.equal(200) | ||
const result = response.json() | ||
result.should.have.property('id', TestObjects.alice.hashid) | ||
result.should.have.property('username', TestObjects.alice.username) | ||
result.should.have.property('email', TestObjects.alice.email) | ||
}) | ||
it('return user info for unverified_email user', async function () { | ||
await login('chris', 'ccPassword') | ||
const response = await app.inject({ | ||
method: 'GET', | ||
url: '/api/v1/user', | ||
cookies: { sid: TestObjects.tokens.chris } | ||
}) | ||
response.statusCode.should.equal(200) | ||
const result = response.json() | ||
result.should.have.property('id', TestObjects.chris.hashid) | ||
result.should.have.property('username', TestObjects.chris.username) | ||
result.should.have.property('email', TestObjects.chris.email) | ||
result.should.have.property('email_verified', false) | ||
}) | ||
}) | ||
}) |