77 * Module Dependencies.
88 */
99
10+ var path = require ( 'path' ) ;
11+ var SG = require ( 'strong-globalize' ) ;
12+ var g = SG ( ) ;
13+
1014var loopback = require ( '../../lib/loopback' ) ;
1115var utils = require ( '../../lib/utils' ) ;
12- var path = require ( 'path' ) ;
1316var SALT_WORK_FACTOR = 10 ;
1417var crypto = require ( 'crypto' ) ;
1518
@@ -203,22 +206,22 @@ module.exports = function(User) {
203206 realmDelimiter ) ;
204207
205208 if ( realmRequired && ! query . realm ) {
206- var err1 = new Error ( 'realm is required' ) ;
209+ var err1 = new Error ( g . f ( 'realm is required' ) ) ;
207210 err1 . statusCode = 400 ;
208211 err1 . code = 'REALM_REQUIRED' ;
209212 fn ( err1 ) ;
210213 return fn . promise ;
211214 }
212215 if ( ! query . email && ! query . username ) {
213- var err2 = new Error ( 'username or email is required' ) ;
216+ var err2 = new Error ( g . f ( 'username or email is required' ) ) ;
214217 err2 . statusCode = 400 ;
215218 err2 . code = 'USERNAME_EMAIL_REQUIRED' ;
216219 fn ( err2 ) ;
217220 return fn . promise ;
218221 }
219222
220223 self . findOne ( { where : query } , function ( err , user ) {
221- var defaultError = new Error ( 'login failed' ) ;
224+ var defaultError = new Error ( g . f ( 'login failed' ) ) ;
222225 defaultError . statusCode = 401 ;
223226 defaultError . code = 'LOGIN_FAILED' ;
224227
@@ -248,7 +251,7 @@ module.exports = function(User) {
248251 if ( self . settings . emailVerificationRequired && ! user . emailVerified ) {
249252 // Fail to log in if email verification is not done yet
250253 debug ( 'User email has not been verified' ) ;
251- err = new Error ( 'login failed as the email has not been verified' ) ;
254+ err = new Error ( g . f ( 'login failed as the email has not been verified' ) ) ;
252255 err . statusCode = 401 ;
253256 err . code = 'LOGIN_FAILED_EMAIL_NOT_VERIFIED' ;
254257 fn ( err ) ;
@@ -295,7 +298,7 @@ module.exports = function(User) {
295298 } else if ( accessToken ) {
296299 accessToken . destroy ( fn ) ;
297300 } else {
298- fn ( new Error ( 'could not find accessToken' ) ) ;
301+ fn ( new Error ( g . f ( 'could not find accessToken' ) ) ) ;
299302 }
300303 } ) ;
301304 return fn . promise ;
@@ -432,10 +435,14 @@ module.exports = function(User) {
432435
433436 options . text = options . text . replace ( / \{ h r e f \} / g, options . verifyHref ) ;
434437
438+ options . text = g . f ( options . text ) ;
439+
435440 options . to = options . to || user . email ;
436441
437442 options . subject = options . subject || 'Thanks for Registering' ;
438443
444+ options . subject = g . f ( options . subject ) ;
445+
439446 options . headers = options . headers || { } ;
440447
441448 var template = loopback . template ( options . template ) ;
@@ -496,11 +503,11 @@ module.exports = function(User) {
496503 } ) ;
497504 } else {
498505 if ( user ) {
499- err = new Error ( 'Invalid token: ' + token ) ;
506+ err = new Error ( g . f ( 'Invalid token: %s' , token ) ) ;
500507 err . statusCode = 400 ;
501508 err . code = 'INVALID_TOKEN' ;
502509 } else {
503- err = new Error ( 'User not found: ' + uid ) ;
510+ err = new Error ( g . f ( 'User not found: %s' , uid ) ) ;
504511 err . statusCode = 404 ;
505512 err . code = 'USER_NOT_FOUND' ;
506513 }
@@ -529,7 +536,7 @@ module.exports = function(User) {
529536
530537 options = options || { } ;
531538 if ( typeof options . email !== 'string' ) {
532- var err = new Error ( 'Email is required' ) ;
539+ var err = new Error ( g . f ( 'Email is required' ) ) ;
533540 err . statusCode = 400 ;
534541 err . code = 'EMAIL_REQUIRED' ;
535542 cb ( err ) ;
@@ -541,7 +548,7 @@ module.exports = function(User) {
541548 return cb ( err ) ;
542549 }
543550 if ( ! user ) {
544- err = new Error ( 'Email not found' ) ;
551+ err = new Error ( g . f ( 'Email not found' ) ) ;
545552 err . statusCode = 404 ;
546553 err . code = 'EMAIL_NOT_FOUND' ;
547554 return cb ( err ) ;
@@ -577,7 +584,7 @@ module.exports = function(User) {
577584 if ( typeof plain === 'string' && plain ) {
578585 return true ;
579586 }
580- var err = new Error ( 'Invalid password: ' + plain ) ;
587+ var err = new Error ( g . f ( 'Invalid password: %s' , plain ) ) ;
581588 err . statusCode = 422 ;
582589 throw err ;
583590 } ;
@@ -636,20 +643,21 @@ module.exports = function(User) {
636643 UserModel . remoteMethod (
637644 'login' ,
638645 {
639- description : 'Login a user with username/email and password.' ,
646+ description : g . f ( 'Login a user with username/email and password.' ) ,
640647 accepts : [
641648 { arg : 'credentials' , type : 'object' , required : true , http : { source : 'body' } } ,
642649 { arg : 'include' , type : [ 'string' ] , http : { source : 'query' } ,
643- description : 'Related objects to include in the response. ' +
644- 'See the description of return value for more details.' } ,
650+ description : g . f ( 'Related objects to include in the response. ' +
651+ 'See the description of return value for more details.' ) } ,
645652 ] ,
646653 returns : {
647654 arg : 'accessToken' , type : 'object' , root : true ,
648655 description :
649- 'The response body contains properties of the AccessToken created on login.\n' +
656+ g . f ( 'The response body contains properties of the AccessToken created on login.\n' +
650657 'Depending on the value of `include` parameter, the body may contain ' +
651658 'additional properties:\n\n' +
652- ' - `user` - `{User}` - Data of the currently logged in user. (`include=user`)\n\n' ,
659+ ' - `user` - `U+007BUserU+007D` - Data of the currently logged in user. ' +
660+ '(`include=user`)\n\n' ) ,
653661 } ,
654662 http : { verb : 'post' } ,
655663 }
@@ -658,16 +666,16 @@ module.exports = function(User) {
658666 UserModel . remoteMethod (
659667 'logout' ,
660668 {
661- description : 'Logout a user with access token.' ,
669+ description : g . f ( 'Logout a user with access token.' ) ,
662670 accepts : [
663671 { arg : 'access_token' , type : 'string' , required : true , http : function ( ctx ) {
664672 var req = ctx && ctx . req ;
665673 var accessToken = req && req . accessToken ;
666674 var tokenID = accessToken && accessToken . id ;
667675
668676 return tokenID ;
669- } , description : 'Do not supply this argument, it is automatically extracted ' +
670- 'from request headers.' ,
677+ } , description : g . f ( 'Do not supply this argument, it is automatically extracted ' +
678+ 'from request headers.' ) ,
671679 } ,
672680 ] ,
673681 http : { verb : 'all' } ,
@@ -677,7 +685,7 @@ module.exports = function(User) {
677685 UserModel . remoteMethod (
678686 'confirm' ,
679687 {
680- description : 'Confirm a user registration with email verification token.' ,
688+ description : g . f ( 'Confirm a user registration with email verification token.' ) ,
681689 accepts : [
682690 { arg : 'uid' , type : 'string' , required : true } ,
683691 { arg : 'token' , type : 'string' , required : true } ,
@@ -690,7 +698,7 @@ module.exports = function(User) {
690698 UserModel . remoteMethod (
691699 'resetPassword' ,
692700 {
693- description : 'Reset password for a user with email.' ,
701+ description : g . f ( 'Reset password for a user with email.' ) ,
694702 accepts : [
695703 { arg : 'options' , type : 'object' , required : true , http : { source : 'body' } } ,
696704 ] ,
@@ -701,7 +709,7 @@ module.exports = function(User) {
701709 UserModel . afterRemote ( 'confirm' , function ( ctx , inst , next ) {
702710 if ( ctx . args . redirect !== undefined ) {
703711 if ( ! ctx . res ) {
704- return next ( new Error ( 'The transport does not support HTTP redirects.' ) ) ;
712+ return next ( new Error ( g . f ( 'The transport does not support HTTP redirects.' ) ) ) ;
705713 }
706714 ctx . res . location ( ctx . args . redirect ) ;
707715 ctx . res . status ( 302 ) ;
@@ -719,7 +727,7 @@ module.exports = function(User) {
719727 // email validation regex
720728 var re = / ^ ( ( [ ^ < > ( ) [ \] \\ . , ; : \s @ \" ] + ( \. [ ^ < > ( ) [ \] \\ . , ; : \s @ \" ] + ) * ) | ( \" .+ \" ) ) @ ( ( \[ [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } \] ) | ( ( [ a - z A - Z \- 0 - 9 ] + \. ) + [ a - z A - Z ] { 2 , } ) ) $ / ;
721729
722- UserModel . validatesFormatOf ( 'email' , { with : re , message : 'Must provide a valid email' } ) ;
730+ UserModel . validatesFormatOf ( 'email' , { with : re , message : g . f ( 'Must provide a valid email' ) } ) ;
723731
724732 // FIXME: We need to add support for uniqueness of composite keys in juggler
725733 if ( ! ( UserModel . settings . realmRequired || UserModel . settings . realmDelimiter ) ) {
0 commit comments