Fix #229 (Whitespaces removed
This commit is contained in:
parent
2c23a57b11
commit
1c1364636d
|
@ -112,7 +112,7 @@ var options = {
|
||||||
* Extends from the built in `loopback.Model` type.
|
* Extends from the built in `loopback.Model` type.
|
||||||
*
|
*
|
||||||
* Default `User` ACLs.
|
* Default `User` ACLs.
|
||||||
*
|
*
|
||||||
* - DENY EVERYONE `*`
|
* - DENY EVERYONE `*`
|
||||||
* - ALLOW EVERYONE `create`
|
* - ALLOW EVERYONE `create`
|
||||||
* - ALLOW OWNER `removeById`
|
* - ALLOW OWNER `removeById`
|
||||||
|
@ -160,11 +160,11 @@ User.login = function (credentials, include, fn) {
|
||||||
err.statusCode = 400;
|
err.statusCode = 400;
|
||||||
return fn(err);
|
return fn(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.findOne({where: query}, function(err, user) {
|
this.findOne({where: query}, function(err, user) {
|
||||||
var defaultError = new Error('login failed');
|
var defaultError = new Error('login failed');
|
||||||
defaultError.statusCode = 401;
|
defaultError.statusCode = 401;
|
||||||
|
|
||||||
if(err) {
|
if(err) {
|
||||||
debug('An error is reported from User.findOne: %j', err);
|
debug('An error is reported from User.findOne: %j', err);
|
||||||
fn(defaultError);
|
fn(defaultError);
|
||||||
|
@ -269,7 +269,7 @@ User.prototype.verify = function (options, fn) {
|
||||||
assert(options.type === 'email', 'Unsupported verification type');
|
assert(options.type === 'email', 'Unsupported verification type');
|
||||||
assert(options.to || this.email, 'Must include options.to when calling user.verify() or the user must have an email property');
|
assert(options.to || this.email, 'Must include options.to when calling user.verify() or the user must have an email property');
|
||||||
assert(options.from, 'Must include options.from when calling user.verify() or the user must have an email property');
|
assert(options.from, 'Must include options.from when calling user.verify() or the user must have an email property');
|
||||||
|
|
||||||
options.redirect = options.redirect || '/';
|
options.redirect = options.redirect || '/';
|
||||||
options.template = path.resolve(options.template || path.join(__dirname, '..', '..', 'templates', 'verify.ejs'));
|
options.template = path.resolve(options.template || path.join(__dirname, '..', '..', 'templates', 'verify.ejs'));
|
||||||
options.user = this;
|
options.user = this;
|
||||||
|
@ -280,13 +280,16 @@ User.prototype.verify = function (options, fn) {
|
||||||
+ '://'
|
+ '://'
|
||||||
+ options.host
|
+ options.host
|
||||||
+ User.http.path
|
+ User.http.path
|
||||||
+ User.confirm.http.path;
|
+ User.confirm.http.path
|
||||||
|
+ '?uid='
|
||||||
|
+ options.user.id
|
||||||
|
+ '&redirect='
|
||||||
|
+ options.redirect;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Email model
|
// Email model
|
||||||
var Email = options.mailer || this.constructor.email || loopback.getModelByType(loopback.Email);
|
var Email = options.mailer || this.constructor.email || loopback.getModelByType(loopback.Email);
|
||||||
|
|
||||||
crypto.randomBytes(64, function(err, buf) {
|
crypto.randomBytes(64, function(err, buf) {
|
||||||
if(err) {
|
if(err) {
|
||||||
fn(err);
|
fn(err);
|
||||||
|
@ -296,20 +299,20 @@ User.prototype.verify = function (options, fn) {
|
||||||
if(err) {
|
if(err) {
|
||||||
fn(err);
|
fn(err);
|
||||||
} else {
|
} else {
|
||||||
sendEmail(user);
|
sendEmail(user);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO - support more verification types
|
// TODO - support more verification types
|
||||||
function sendEmail(user) {
|
function sendEmail(user) {
|
||||||
options.verifyHref += '?token=' + user.verificationToken;
|
options.verifyHref += '&token=' + user.verificationToken;
|
||||||
|
|
||||||
options.text = options.text || 'Please verify your email by opening this link in a web browser:\n\t{href}';
|
options.text = options.text || 'Please verify your email by opening this link in a web browser:\n\t{href}';
|
||||||
|
|
||||||
options.text = options.text.replace('{href}', options.verifyHref);
|
options.text = options.text.replace('{href}', options.verifyHref);
|
||||||
|
|
||||||
var template = loopback.template(options.template);
|
var template = loopback.template(options.template);
|
||||||
Email.send({
|
Email.send({
|
||||||
to: options.to || user.email,
|
to: options.to || user.email,
|
||||||
|
@ -412,7 +415,7 @@ User.setup = function () {
|
||||||
// We need to call the base class's setup method
|
// We need to call the base class's setup method
|
||||||
Model.setup.call(this);
|
Model.setup.call(this);
|
||||||
var UserModel = this;
|
var UserModel = this;
|
||||||
|
|
||||||
// max ttl
|
// max ttl
|
||||||
this.settings.maxTTL = this.settings.maxTTL || DEFAULT_MAX_TTL;
|
this.settings.maxTTL = this.settings.maxTTL || DEFAULT_MAX_TTL;
|
||||||
this.settings.ttl = DEFAULT_TTL;
|
this.settings.ttl = DEFAULT_TTL;
|
||||||
|
@ -421,7 +424,7 @@ User.setup = function () {
|
||||||
var salt = bcrypt.genSaltSync(this.constructor.settings.saltWorkFactor || SALT_WORK_FACTOR);
|
var salt = bcrypt.genSaltSync(this.constructor.settings.saltWorkFactor || SALT_WORK_FACTOR);
|
||||||
this.$password = bcrypt.hashSync(plain, salt);
|
this.$password = bcrypt.hashSync(plain, salt);
|
||||||
}
|
}
|
||||||
|
|
||||||
loopback.remoteMethod(
|
loopback.remoteMethod(
|
||||||
UserModel.login,
|
UserModel.login,
|
||||||
{
|
{
|
||||||
|
@ -441,7 +444,7 @@ User.setup = function () {
|
||||||
http: {verb: 'post'}
|
http: {verb: 'post'}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
loopback.remoteMethod(
|
loopback.remoteMethod(
|
||||||
UserModel.logout,
|
UserModel.logout,
|
||||||
{
|
{
|
||||||
|
@ -460,7 +463,7 @@ User.setup = function () {
|
||||||
http: {verb: 'all'}
|
http: {verb: 'all'}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
loopback.remoteMethod(
|
loopback.remoteMethod(
|
||||||
UserModel.confirm,
|
UserModel.confirm,
|
||||||
{
|
{
|
||||||
|
@ -472,7 +475,7 @@ User.setup = function () {
|
||||||
http: {verb: 'get', path: '/confirm'}
|
http: {verb: 'get', path: '/confirm'}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
loopback.remoteMethod(
|
loopback.remoteMethod(
|
||||||
UserModel.resetPassword,
|
UserModel.resetPassword,
|
||||||
{
|
{
|
||||||
|
@ -492,16 +495,16 @@ User.setup = function () {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// default models
|
// default models
|
||||||
UserModel.email = require('./email');
|
UserModel.email = require('./email');
|
||||||
UserModel.accessToken = require('./access-token');
|
UserModel.accessToken = require('./access-token');
|
||||||
|
|
||||||
UserModel.validatesUniquenessOf('email', {message: 'Email already exists'});
|
UserModel.validatesUniquenessOf('email', {message: 'Email already exists'});
|
||||||
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
|
||||||
|
|
||||||
UserModel.validatesFormatOf('email', {with: re, message: 'Must provide a valid email'});
|
UserModel.validatesFormatOf('email', {with: re, message: 'Must provide a valid email'});
|
||||||
|
|
||||||
return UserModel;
|
return UserModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue