Skip to content

Commit

Permalink
Misc db updates (steemit#331)
Browse files Browse the repository at this point in the history
* add phone to identities; make email non unique

* extend confirmation token's life span to one month

* allow to confirm email address only once
  • Loading branch information
Valentine Zavgorodnev authored Sep 23, 2016
1 parent d151977 commit cf28411
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
4 changes: 4 additions & 0 deletions db/migrations/20160420133848-create-identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ module.exports = {
email: {
type: Sequelize.STRING
},
phone: {
type: Sequelize.STRING(32)
},
confirmation_code: {
type: Sequelize.STRING
},
Expand All @@ -47,6 +50,7 @@ module.exports = {
}
}).then(function () {
queryInterface.addIndex('identities', ['email']);
queryInterface.addIndex('identities', ['phone']);
queryInterface.addIndex('identities', ['confirmation_code']);
});
},
Expand Down
4 changes: 3 additions & 1 deletion db/migrations/20160420151336-create-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ module.exports = {
type: Sequelize.STRING
},
ignored: {
type: Sequelize.BOOLEAN
type: Sequelize.BOOLEAN,
defaultValue: false,
allowNull: false
},
created_at: {
allowNull: false,
Expand Down
5 changes: 3 additions & 2 deletions db/models/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ module.exports = function (sequelize, DataTypes) {
field: 'user_id'
},
provider: DataTypes.STRING,
provider_user_id: {type: DataTypes.STRING, unique: true},
provider_user_id: {type: DataTypes.STRING},
name: DataTypes.STRING,
email: {type: DataTypes.STRING, unique: true},
email: {type: DataTypes.STRING},
phone: {type: DataTypes.STRING(32)},
confirmation_code: {type: DataTypes.STRING, unique: true},
verified: DataTypes.BOOLEAN,
score: DataTypes.INTEGER
Expand Down
2 changes: 1 addition & 1 deletion db/models/user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function (sequelize, DataTypes) {
var User = sequelize.define('User', {
name: DataTypes.STRING,
email: {type: DataTypes.STRING, unique: true},
email: {type: DataTypes.STRING},
uid: {type: DataTypes.STRING(64)},
first_name: DataTypes.STRING,
last_name: DataTypes.STRING,
Expand Down
10 changes: 4 additions & 6 deletions server/server_pages/enter_confirm_email.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function *confirmEmailHandler() {
const confirmation_code = this.params && this.params.code ? this.params.code : this.request.body.code;
console.log('-- /confirm_email -->', this.session.uid, this.session.user, confirmation_code);
const eid = yield models.Identity.findOne(
{attributes: ['id', 'user_id', 'email', 'verified', 'updated_at'], where: {confirmation_code}, order: 'id DESC'}
{attributes: ['id', 'user_id', 'email', 'updated_at'], where: {confirmation_code, verified: false}, order: 'id DESC'}
);
if (!eid) {
this.status = 401;
Expand All @@ -47,15 +47,13 @@ function *confirmEmailHandler() {
}
this.session.user = eid.user_id;
const hours_ago = (Date.now() - eid.updated_at) / 1000.0 / 3600.0;
if (hours_ago > 240.0) {
if (hours_ago > 24.0 * 30) {
this.status = 401;
this.body = 'confirmation code not found or expired';
return;
}
if (!eid.verified) {
yield eid.update({verified: true});
yield models.User.update({email: eid.email, waiting_list: false}, {where: {id: eid.user_id}});
}
yield eid.update({verified: true});
yield models.User.update({email: eid.email, waiting_list: false}, {where: {id: eid.user_id}});
this.redirect('/create_account');
}

Expand Down

0 comments on commit cf28411

Please sign in to comment.