@@ -37,16 +37,15 @@ const addMemberValidations = {
37
37
*
38
38
* @returns {Boolean } true if two emails are same
39
39
*/
40
- const compareEmail = ( email1 , email2 , options = { } ) => {
41
- const opts = _ . assign ( {
42
- UNIQUE_GMAIL_VALIDATION : config . get ( 'UNIQUE_GMAIL_VALIDATION' ) ,
43
- } , options ) ;
44
- if ( opts . UNIQUE_GMAIL_VALIDATION ) {
40
+ const compareEmail = ( email1 , email2 , options = { UNIQUE_GMAIL_VALIDATION : false } ) => {
41
+ if ( options . UNIQUE_GMAIL_VALIDATION ) {
45
42
// email is gmail
46
- const emailSplit = / ( ^ [ \w . + \ -] + ) @ g m a i l \. ( .* .) $ / g. exec ( email1 ) ; // eslint-disable-line
43
+ const emailSplit = / ( ^ [ \w . + - ] + ) ( @ g m a i l \. .* .) $ / g. exec ( email1 ) ;
47
44
if ( emailSplit ) {
48
45
const address = emailSplit [ 1 ] ;
49
- const regex = new RegExp ( _ . toLower ( address ) . replace ( '.' , '' ) . split ( '' ) . join ( '.?' ) ) ;
46
+ const emailDomain = emailSplit [ 2 ] ;
47
+ const regexAddress = _ . toLower ( address ) . replace ( '.' , '' ) . split ( '' ) . join ( '\.?' ) ; // eslint-disable-line no-useless-escape
48
+ const regex = new RegExp ( `${ regexAddress } ${ emailDomain } ` ) ;
50
49
return regex . test ( _ . toLower ( email2 ) ) ;
51
50
}
52
51
}
@@ -110,7 +109,8 @@ const buildCreateInvitePromises = (req, invite, invites, data, failed) => {
110
109
111
110
// remove invites for users that are invited already
112
111
_ . remove ( nonExistentUserEmails , email =>
113
- _ . some ( invites , i => compareEmail ( i . email , email ) ) ) ;
112
+ _ . some ( invites , i =>
113
+ compareEmail ( i . email , email , { UNIQUE_GMAIL_VALIDATION : config . get ( 'UNIQUE_GMAIL_VALIDATION' ) } ) ) ) ;
114
114
nonExistentUserEmails . forEach ( ( email ) => {
115
115
const dataNew = _ . clone ( data ) ;
116
116
0 commit comments