rename 'verified' to 'emailVerified'

This commit is contained in:
Danny Coates 2014-01-14 10:59:37 -08:00
Родитель 4b0bb50e2b
Коммит 19da97e705
14 изменённых файлов: 37 добавлений и 136 удалений

Просмотреть файл

@ -1,95 +0,0 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
const config = require('../config').root()
const Client = require('../client')
process.on('message', function (message) {
if (message.action === 'crash') {
throw new Error('FML')
}
else if (message.action === 'session/create') {
Client.login(
config.publicUrl,
message.email,
message.password
)
.done(
function (client) {
process.send({
uid: client.uid,
verified: client.verified,
sessionToken: client.sessionToken.toString('hex')
})
},
function (err) {
process.send({ err: err })
}
)
}
else if (message.action === 'account/create') {
Client.create(
config.publicUrl,
message.email,
message.password,
message.options || {}
)
.done(
function (client) {
process.send({ uid: client.uid })
},
function (err) {
process.send({ err: err })
}
)
}
else if (message.action === 'password/change') {
Client.changePassword(
config.publicUrl,
message.email,
message.oldPassword,
message.newPassword
)
.done(
function (client) {
process.send({})
},
function (err) {
process.send({ err: err })
}
)
}
else if (message.action === 'password/reset') {
var client = new Client()
client.setupCredentials(message.email, message.newPassword)
.then(
function () {
var stretching = message.passwordStretching
stretching.salt = client.passwordSalt
process.send({
srp: client.srp,
passwordStretching: stretching
})
},
function (err) {
process.send({ err: err })
}
)
}
else {
return process.send({ err: { message: 'unknown action' } })
}
})
process.on(
'uncaughtException',
function (err) {
process.exit(8)
}
)

Просмотреть файл

@ -13,7 +13,7 @@ function Client(origin) {
this.uid = null this.uid = null
this.api = new ClientApi(origin) this.api = new ClientApi(origin)
this.email = null this.email = null
this.verified = false this.emailVerified = false
this.authToken = null this.authToken = null
this.sessionToken = null this.sessionToken = null
this.accountResetToken = null this.accountResetToken = null
@ -64,7 +64,6 @@ Client.create = function (origin, email, password, options) {
Client.login = function (origin, email, password) { Client.login = function (origin, email, password) {
var c = new Client(origin) var c = new Client(origin)
return c.setupCredentials(email, password) return c.setupCredentials(email, password)
.then( .then(
function (c) { function (c) {
@ -126,7 +125,7 @@ Client.prototype.auth = function () {
this.uid = data.uid this.uid = data.uid
this.sessionToken = data.sessionToken this.sessionToken = data.sessionToken
this.keyFetchToken = data.keyFetchToken this.keyFetchToken = data.keyFetchToken
this.verified = data.verified this.emailVerified = data.verified
return this return this
}.bind(this) }.bind(this)
) )

Просмотреть файл

@ -160,7 +160,7 @@ module.exports = function (
if (!account) { return P.reject(error.unknownAccount()) } if (!account) { return P.reject(error.unknownAccount()) }
sessionToken.email = account.email sessionToken.email = account.email
sessionToken.emailCode = account.emailCode sessionToken.emailCode = account.emailCode
sessionToken.verified = account.verified sessionToken.emailVerified = account.emailVerified
return P(sessionToken) return P(sessionToken)
} }
@ -172,7 +172,7 @@ module.exports = function (
if (!account) { return P.reject(error.unknownAccount()) } if (!account) { return P.reject(error.unknownAccount()) }
keyFetchToken.kA = account.kA keyFetchToken.kA = account.kA
keyFetchToken.wrapWrapKb = account.wrapWrapKb keyFetchToken.wrapWrapKb = account.wrapWrapKb
keyFetchToken.verified = account.verified keyFetchToken.emailVerified = account.emailVerified
return P(keyFetchToken) return P(keyFetchToken)
} }
@ -320,7 +320,7 @@ module.exports = function (
Heap.prototype.verifyEmail = function (account) { Heap.prototype.verifyEmail = function (account) {
log.trace({ op: 'Heap.verifyEmail', uid: account && account.uid }) log.trace({ op: 'Heap.verifyEmail', uid: account && account.uid })
account.verified = true account.emailVerified = true
return P(true) return P(true)
} }

Просмотреть файл

@ -121,7 +121,7 @@ module.exports = function (
// CREATE // CREATE
var CREATE_ACCOUNT = 'INSERT INTO accounts' + var CREATE_ACCOUNT = 'INSERT INTO accounts' +
' (uid, normalizedEmail, email, emailCode, verified,' + ' (uid, normalizedEmail, email, emailCode, emailVerified,' +
' kA, wrapWrapKb, authSalt, verifyHash, verifierSetAt)' + ' kA, wrapWrapKb, authSalt, verifyHash, verifierSetAt)' +
' VALUES (?, LOWER(?), ?, ?, ?, ?, ?, ?, ?, ?)' ' VALUES (?, LOWER(?), ?, ?, ?, ?, ?, ?, ?, ?)'
@ -146,7 +146,7 @@ module.exports = function (
data.normalizedEmail, data.normalizedEmail,
data.email, data.email,
data.emailCode, data.emailCode,
data.verified, data.emailVerified,
data.kA, data.kA,
data.wrapWrapKb, data.wrapWrapKb,
data.authSalt, data.authSalt,
@ -373,7 +373,7 @@ module.exports = function (
} }
var SESSION_TOKEN = 'SELECT t.tokendata, t.uid, t.createdAt,' + var SESSION_TOKEN = 'SELECT t.tokendata, t.uid, t.createdAt,' +
' a.verified, a.email, a.emailCode, a.verifierSetAt' + ' a.emailVerified, a.email, a.emailCode, a.verifierSetAt' +
' FROM sessionTokens t, accounts a' + ' FROM sessionTokens t, accounts a' +
' WHERE t.tokenid = ? AND t.uid = a.uid' ' WHERE t.tokenid = ? AND t.uid = a.uid'
@ -404,7 +404,7 @@ var SESSION_TOKEN = 'SELECT t.tokendata, t.uid, t.createdAt,' +
} }
var KEY_FETCH_TOKEN = 'SELECT t.authKey, t.uid, t.keyBundle, t.createdAt,' + var KEY_FETCH_TOKEN = 'SELECT t.authKey, t.uid, t.keyBundle, t.createdAt,' +
' a.verified, a.verifierSetAt' + ' a.emailVerified, a.verifierSetAt' +
' FROM keyfetchTokens t, accounts a' + ' FROM keyfetchTokens t, accounts a' +
' WHERE t.tokenid = ? AND t.uid = a.uid' ' WHERE t.tokenid = ? AND t.uid = a.uid'
@ -523,7 +523,7 @@ var KEY_FETCH_TOKEN = 'SELECT t.authKey, t.uid, t.keyBundle, t.createdAt,' +
}) })
} }
var EMAIL_RECORD = 'SELECT uid, email, normalizedEmail, verified,' + var EMAIL_RECORD = 'SELECT uid, email, normalizedEmail, emailVerified,' +
' emailCode, kA, wrapWrapKb, verifyHash, authSalt, verifierSetAt' + ' emailCode, kA, wrapWrapKb, verifyHash, authSalt, verifierSetAt' +
' FROM accounts' + ' FROM accounts' +
' WHERE normalizedEmail = LOWER(?)' ' WHERE normalizedEmail = LOWER(?)'
@ -547,7 +547,7 @@ var KEY_FETCH_TOKEN = 'SELECT t.authKey, t.uid, t.keyBundle, t.createdAt,' +
email: result.email, email: result.email,
normalizedEmail: result.normalizedEmail, normalizedEmail: result.normalizedEmail,
emailCode: result.emailCode, emailCode: result.emailCode,
verified: !!result.verified, emailVerified: !!result.emailVerified,
kA: result.kA, kA: result.kA,
wrapWrapKb: result.wrapWrapKb, wrapWrapKb: result.wrapWrapKb,
verifyHash: result.verifyHash, verifyHash: result.verifyHash,
@ -560,7 +560,7 @@ var KEY_FETCH_TOKEN = 'SELECT t.authKey, t.uid, t.keyBundle, t.createdAt,' +
}) })
} }
var ACCOUNT = 'SELECT email, normalizedEmail, emailCode, verified, kA,' + var ACCOUNT = 'SELECT email, normalizedEmail, emailCode, emailVerified, kA,' +
' wrapWrapKb, verifyHash, authSalt, verifierSetAt ' + ' wrapWrapKb, verifyHash, authSalt, verifierSetAt ' +
' FROM accounts WHERE uid = ?' ' FROM accounts WHERE uid = ?'
@ -584,7 +584,7 @@ var KEY_FETCH_TOKEN = 'SELECT t.authKey, t.uid, t.keyBundle, t.createdAt,' +
email: result.email, email: result.email,
normalizedEmail: result.normalizedEmail, normalizedEmail: result.normalizedEmail,
emailCode: result.emailCode, emailCode: result.emailCode,
verified: !!result.verified, emailVerified: !!result.emailVerified,
kA: result.kA, kA: result.kA,
wrapWrapKb: result.wrapWrapKb, wrapWrapKb: result.wrapWrapKb,
verifyHash: result.verifyHash, verifyHash: result.verifyHash,
@ -834,7 +834,7 @@ var KEY_FETCH_TOKEN = 'SELECT t.authKey, t.uid, t.keyBundle, t.createdAt,' +
}) })
} }
var VERIFY_EMAIL = 'UPDATE accounts SET verified = true WHERE uid = ?' var VERIFY_EMAIL = 'UPDATE accounts SET emailVerified = true WHERE uid = ?'
MySql.prototype.verifyEmail = function (account) { MySql.prototype.verifyEmail = function (account) {
log.trace({ op: 'MySql.verifyEmail', uid: account && account.uid }) log.trace({ op: 'MySql.verifyEmail', uid: account && account.uid })

Просмотреть файл

@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS accounts (
normalizedEmail VARCHAR(255) NOT NULL UNIQUE KEY, normalizedEmail VARCHAR(255) NOT NULL UNIQUE KEY,
email VARCHAR(255) NOT NULL, email VARCHAR(255) NOT NULL,
emailCode BINARY(16) NOT NULL, emailCode BINARY(16) NOT NULL,
verified BOOLEAN NOT NULL DEFAULT FALSE, emailVerified BOOLEAN NOT NULL DEFAULT FALSE,
kA BINARY(32) NOT NULL, kA BINARY(32) NOT NULL,
wrapWrapKb BINARY(32) NOT NULL, wrapWrapKb BINARY(32) NOT NULL,
authSalt BINARY(32) NOT NULL, authSalt BINARY(32) NOT NULL,
@ -20,7 +20,6 @@ CREATE TABLE IF NOT EXISTS sessionTokens (
INDEX session_uid (uid) INDEX session_uid (uid)
) ENGINE=InnoDB; ) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS keyfetchTokens ( CREATE TABLE IF NOT EXISTS keyfetchTokens (
tokenid BINARY(32) PRIMARY KEY, tokenid BINARY(32) PRIMARY KEY,
authKey BINARY(32) NOT NULL, authKey BINARY(32) NOT NULL,
@ -30,7 +29,6 @@ CREATE TABLE IF NOT EXISTS keyfetchTokens (
INDEX key_uid (uid) INDEX key_uid (uid)
) ENGINE=InnoDB; ) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS resetTokens ( CREATE TABLE IF NOT EXISTS resetTokens (
tokenid BINARY(32) PRIMARY KEY, tokenid BINARY(32) PRIMARY KEY,
tokendata BINARY(32) NOT NULL, tokendata BINARY(32) NOT NULL,
@ -38,7 +36,6 @@ CREATE TABLE IF NOT EXISTS resetTokens (
createdAt BIGINT UNSIGNED NOT NULL createdAt BIGINT UNSIGNED NOT NULL
) ENGINE=InnoDB; ) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS passwordForgotTokens ( CREATE TABLE IF NOT EXISTS passwordForgotTokens (
tokenid BINARY(32) PRIMARY KEY, tokenid BINARY(32) PRIMARY KEY,
tokendata BINARY(32) NOT NULL, tokendata BINARY(32) NOT NULL,

Просмотреть файл

@ -64,7 +64,7 @@ module.exports = function (
uid: uuid.v4('binary'), uid: uuid.v4('binary'),
email: email, email: email,
emailCode: crypto.randomBytes(16), emailCode: crypto.randomBytes(16),
verified: form.preVerified || false, emailVerified: form.preVerified || false,
kA: crypto.randomBytes(32), kA: crypto.randomBytes(32),
wrapWrapKb: crypto.randomBytes(32), wrapWrapKb: crypto.randomBytes(32),
devices: {}, devices: {},
@ -78,7 +78,7 @@ module.exports = function (
) )
.then( .then(
function (account) { function (account) {
if (!account.verified) { if (!account.emailVerified) {
mailer.sendVerifyCode( mailer.sendVerifyCode(
account, account,
account.emailCode, account.emailCode,
@ -147,7 +147,7 @@ module.exports = function (
uid: emailRecord.uid, uid: emailRecord.uid,
email: emailRecord.email, email: emailRecord.email,
emailCode: emailRecord.emailCode, emailCode: emailRecord.emailCode,
verified: emailRecord.verified emailVerified: emailRecord.emailVerified
} }
) )
} }
@ -178,7 +178,7 @@ module.exports = function (
uid: emailRecord.uid, uid: emailRecord.uid,
kA: emailRecord.kA, kA: emailRecord.kA,
wrapKb: wrapKb, wrapKb: wrapKb,
verified: emailRecord.verified emailVerified: emailRecord.emailVerified
} }
) )
} }
@ -204,7 +204,7 @@ module.exports = function (
uid: tokens.sessionToken.uid.toString('hex'), uid: tokens.sessionToken.uid.toString('hex'),
sessionToken: tokens.sessionToken.data.toString('hex'), sessionToken: tokens.sessionToken.data.toString('hex'),
keyFetchToken: tokens.keyFetchToken ? tokens.keyFetchToken.data.toString('hex') : undefined, keyFetchToken: tokens.keyFetchToken ? tokens.keyFetchToken.data.toString('hex') : undefined,
verified: tokens.sessionToken.verified verified: tokens.sessionToken.emailVerified
} }
) )
}, },
@ -286,7 +286,7 @@ module.exports = function (
log.begin('Account.keys', request) log.begin('Account.keys', request)
var reply = request.reply.bind(request) var reply = request.reply.bind(request)
var keyFetchToken = request.auth.credentials var keyFetchToken = request.auth.credentials
if (!keyFetchToken.verified) { if (!keyFetchToken.emailVerified) {
// don't delete the token on use until the account is verified // don't delete the token on use until the account is verified
return reply(error.unverifiedAccount()) return reply(error.unverifiedAccount())
} }
@ -318,7 +318,7 @@ module.exports = function (
request.reply( request.reply(
{ {
email: sessionToken.email, email: sessionToken.email,
verified: sessionToken.verified verified: sessionToken.emailVerified
} }
) )
}, },

Просмотреть файл

@ -60,7 +60,7 @@ module.exports = function (log, isA, error, db, redirectDomain, mailer) {
uid: emailRecord.uid, uid: emailRecord.uid,
kA: emailRecord.kA, kA: emailRecord.kA,
wrapKb: wrapKb, wrapKb: wrapKb,
verified: emailRecord.verified emailVerified: emailRecord.emailVerified
} }
) )
.then( .then(
@ -89,7 +89,7 @@ module.exports = function (log, isA, error, db, redirectDomain, mailer) {
{ {
keyFetchToken: tokens.keyFetchToken.data.toString('hex'), keyFetchToken: tokens.keyFetchToken.data.toString('hex'),
passwordChangeToken: tokens.passwordChangeToken.data.toString('hex'), passwordChangeToken: tokens.passwordChangeToken.data.toString('hex'),
verified: tokens.keyFetchToken.verified verified: tokens.keyFetchToken.emailVerified
} }
) )
}, },

Просмотреть файл

@ -37,7 +37,7 @@ module.exports = function (log, isA, error, signer, domain) {
var publicKey = request.payload.publicKey var publicKey = request.payload.publicKey
var duration = request.payload.duration var duration = request.payload.duration
if (!sessionToken.verified) { if (!sessionToken.emailVerified) {
return request.reply(error.unverifiedAccount()) return request.reply(error.unverifiedAccount())
} }

Просмотреть файл

@ -26,7 +26,7 @@ var ACCOUNT = {
uid: uuid.v4('binary'), uid: uuid.v4('binary'),
email: 'foo@bar.com', email: 'foo@bar.com',
emailCode: zeroBuffer16, emailCode: zeroBuffer16,
verified: false, emailVerified: false,
verifyHash: zeroBuffer32, verifyHash: zeroBuffer32,
authSalt: zeroBuffer32, authSalt: zeroBuffer32,
kA: zeroBuffer32, kA: zeroBuffer32,
@ -71,7 +71,7 @@ DB.connect(config[config.db.backend])
t.deepEqual(account.uid, ACCOUNT.uid) t.deepEqual(account.uid, ACCOUNT.uid)
t.equal(account.email, ACCOUNT.email) t.equal(account.email, ACCOUNT.email)
t.deepEqual(account.emailCode, ACCOUNT.emailCode) t.deepEqual(account.emailCode, ACCOUNT.emailCode)
t.equal(account.verified, ACCOUNT.verified) t.equal(account.emailVerified, ACCOUNT.emailVerified)
t.deepEqual(account.kA, ACCOUNT.kA) t.deepEqual(account.kA, ACCOUNT.kA)
t.deepEqual(account.wrapWrapKb, ACCOUNT.wrapWrapKb) t.deepEqual(account.wrapWrapKb, ACCOUNT.wrapWrapKb)
t.deepEqual(account.verifyHash, ACCOUNT.verifyHash) t.deepEqual(account.verifyHash, ACCOUNT.verifyHash)
@ -100,7 +100,7 @@ DB.connect(config[config.db.backend])
t.deepEqual(sessionToken.uid, ACCOUNT.uid) t.deepEqual(sessionToken.uid, ACCOUNT.uid)
t.equal(sessionToken.email, ACCOUNT.email) t.equal(sessionToken.email, ACCOUNT.email)
t.deepEqual(sessionToken.emailCode, ACCOUNT.emailCode) t.deepEqual(sessionToken.emailCode, ACCOUNT.emailCode)
t.equal(sessionToken.verified, ACCOUNT.verified) t.equal(sessionToken.emailVerified, ACCOUNT.emailVerified)
return sessionToken return sessionToken
}) })
.then(function(sessionToken) { .then(function(sessionToken) {
@ -127,7 +127,7 @@ DB.connect(config[config.db.backend])
.then(function(keyFetchToken) { .then(function(keyFetchToken) {
t.deepEqual(keyFetchToken.tokenid, tokenid, 'token id matches') t.deepEqual(keyFetchToken.tokenid, tokenid, 'token id matches')
t.deepEqual(keyFetchToken.uid, ACCOUNT.uid) t.deepEqual(keyFetchToken.uid, ACCOUNT.uid)
t.equal(keyFetchToken.verified, ACCOUNT.verified) t.equal(keyFetchToken.emailVerified, ACCOUNT.emailVerified)
return keyFetchToken return keyFetchToken
}) })
.then(function(keyFetchToken) { .then(function(keyFetchToken) {
@ -213,7 +213,7 @@ DB.connect(config[config.db.backend])
return db.account(ACCOUNT.uid) return db.account(ACCOUNT.uid)
}) })
.then(function(account) { .then(function(account) {
t.ok(account.verified, 'account should now be verified') t.ok(account.emailVerified, 'account should now be emailVerified')
}) })
} }
) )

Просмотреть файл

@ -147,7 +147,7 @@ TestServer.start(config.publicUrl)
function (x) { function (x) {
client = x client = x
t.ok(client.uid, 'got a uid') t.ok(client.uid, 'got a uid')
t.equal(client.verified, true, 'email is verified') t.equal(client.emailVerified, true, 'email is verified')
return client.keys() return client.keys()
} }
) )

Просмотреть файл

@ -13,7 +13,7 @@ var ACCOUNT = {
uid: 'xxx', uid: 'xxx',
kA: Buffer('0000000000000000000000000000000000000000000000000000000000000000', 'hex'), kA: Buffer('0000000000000000000000000000000000000000000000000000000000000000', 'hex'),
wrapKb: Buffer('0000000000000000000000000000000000000000000000000000000000000000', 'hex'), wrapKb: Buffer('0000000000000000000000000000000000000000000000000000000000000000', 'hex'),
verified: true emailVerified: true
} }
@ -41,7 +41,7 @@ test(
t.deepEqual(token.uid, token2.uid) t.deepEqual(token.uid, token2.uid)
t.deepEqual(token.kA, token2.kA) t.deepEqual(token.kA, token2.kA)
t.deepEqual(token.wrapKb, token2.wrapKb) t.deepEqual(token.wrapKb, token2.wrapKb)
t.equal(token.verified, token2.verified) t.equal(token.emailVerified, token2.emailVerified)
} }
) )
} }

Просмотреть файл

@ -13,7 +13,7 @@ var ACCOUNT = {
uid: 'xxx', uid: 'xxx',
email: Buffer('test@example.com').toString('hex'), email: Buffer('test@example.com').toString('hex'),
emailCode: '123456', emailCode: '123456',
verified: true emailVerified: true
} }
@ -41,7 +41,7 @@ test(
t.deepEqual(token.uid, token2.uid) t.deepEqual(token.uid, token2.uid)
t.equal(token.email, token2.email) t.equal(token.email, token2.email)
t.equal(token.emailCode, token2.emailCode) t.equal(token.emailCode, token2.emailCode)
t.equal(token.verified, token2.verified) t.equal(token.emailVerified, token2.emailVerified)
} }
) )
} }

Просмотреть файл

@ -7,7 +7,7 @@ module.exports = function (log, inherits, Token, P, error) {
function KeyFetchToken(keys, details) { function KeyFetchToken(keys, details) {
Token.call(this, keys, details) Token.call(this, keys, details)
this.keyBundle = details.keyBundle this.keyBundle = details.keyBundle
this.verified = !!details.verified this.emailVerified = !!details.emailVerified
} }
inherits(KeyFetchToken, Token) inherits(KeyFetchToken, Token)

Просмотреть файл

@ -8,7 +8,7 @@ module.exports = function (log, inherits, Token) {
Token.call(this, keys, details) Token.call(this, keys, details)
this.email = details.email || null this.email = details.email || null
this.emailCode = details.emailCode || null this.emailCode = details.emailCode || null
this.verified = !!details.verified this.emailVerified = !!details.emailVerified
} }
inherits(SessionToken, Token) inherits(SessionToken, Token)