Fix #229 (Whitespaces removed

This commit is contained in:
Alex Pica 2014-04-10 06:01:58 +03:00
parent 2c23a57b11
commit 1c1364636d
1 changed files with 26 additions and 23 deletions

View File

@ -112,7 +112,7 @@ var options = {
* Extends from the built in `loopback.Model` type.
*
* Default `User` ACLs.
*
*
* - DENY EVERYONE `*`
* - ALLOW EVERYONE `create`
* - ALLOW OWNER `removeById`
@ -160,11 +160,11 @@ User.login = function (credentials, include, fn) {
err.statusCode = 400;
return fn(err);
}
this.findOne({where: query}, function(err, user) {
var defaultError = new Error('login failed');
defaultError.statusCode = 401;
if(err) {
debug('An error is reported from User.findOne: %j', err);
fn(defaultError);
@ -269,7 +269,7 @@ User.prototype.verify = function (options, fn) {
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.from, 'Must include options.from when calling user.verify() or the user must have an email property');
options.redirect = options.redirect || '/';
options.template = path.resolve(options.template || path.join(__dirname, '..', '..', 'templates', 'verify.ejs'));
options.user = this;
@ -280,13 +280,16 @@ User.prototype.verify = function (options, fn) {
+ '://'
+ options.host
+ User.http.path
+ User.confirm.http.path;
+ User.confirm.http.path
+ '?uid='
+ options.user.id
+ '&redirect='
+ options.redirect;
// Email model
var Email = options.mailer || this.constructor.email || loopback.getModelByType(loopback.Email);
crypto.randomBytes(64, function(err, buf) {
if(err) {
fn(err);
@ -296,20 +299,20 @@ User.prototype.verify = function (options, fn) {
if(err) {
fn(err);
} else {
sendEmail(user);
sendEmail(user);
}
});
}
});
// TODO - support more verification types
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.replace('{href}', options.verifyHref);
var template = loopback.template(options.template);
Email.send({
to: options.to || user.email,
@ -412,7 +415,7 @@ User.setup = function () {
// We need to call the base class's setup method
Model.setup.call(this);
var UserModel = this;
// max ttl
this.settings.maxTTL = this.settings.maxTTL || DEFAULT_MAX_TTL;
this.settings.ttl = DEFAULT_TTL;
@ -421,7 +424,7 @@ User.setup = function () {
var salt = bcrypt.genSaltSync(this.constructor.settings.saltWorkFactor || SALT_WORK_FACTOR);
this.$password = bcrypt.hashSync(plain, salt);
}
loopback.remoteMethod(
UserModel.login,
{
@ -441,7 +444,7 @@ User.setup = function () {
http: {verb: 'post'}
}
);
loopback.remoteMethod(
UserModel.logout,
{
@ -460,7 +463,7 @@ User.setup = function () {
http: {verb: 'all'}
}
);
loopback.remoteMethod(
UserModel.confirm,
{
@ -472,7 +475,7 @@ User.setup = function () {
http: {verb: 'get', path: '/confirm'}
}
);
loopback.remoteMethod(
UserModel.resetPassword,
{
@ -492,16 +495,16 @@ User.setup = function () {
}
});
});
// default models
UserModel.email = require('./email');
UserModel.accessToken = require('./access-token');
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,}))$/;
UserModel.validatesFormatOf('email', {with: re, message: 'Must provide a valid email'});
return UserModel;
}