forked from code-dot-org/code-dot-org
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashEmail.js
More file actions
21 lines (18 loc) · 719 Bytes
/
hashEmail.js
File metadata and controls
21 lines (18 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* global CryptoJS */
import $ from 'jquery';
var EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
module.exports = function hashEmail(options) {
// Hash the email, if it is an email.
var email = $(options.email_selector).val().toLowerCase().trim();
if (email !== '' && EMAIL_REGEX.test(email)) {
var hashed_email = CryptoJS.MD5(email);
$(options.hashed_email_selector).val(hashed_email);
// Unless we want to deliberately skip the step of clearing the email.
if (!options.skip_clear_email) {
// If age < 13, don't send the plaintext email.
if (!options.age_selector || $(options.age_selector).val() < 13) {
$(options.email_selector).val('');
}
}
}
};