Skip to content

Commit bb32474

Browse files
VINADES.,JSChoaquynhtim99
VINADES.,JSC
authored andcommitted
Supported unicode email address (fix nukeviet#2863)
1 parent d431f1b commit bb32474

File tree

32 files changed

+651
-593
lines changed

32 files changed

+651
-593
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
/data/logs/voting_logs/
1818
/data/tmp/*
1919
/uploads/logo_*
20+
/assets/logo_*
2021
/install/default.php
2122

2223
composer.lock

admin/language/edit.php

+15-11
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
die('Stop!!!');
1313
}
1414

15-
$select_options = array();
16-
15+
$select_options = [];
1716
$contents = '';
1817

1918
$xtpl = new XTemplate('edit.tpl', NV_ROOTDIR . '/themes/' . $global_config['module_theme'] . '/modules/' . $module_file);
@@ -27,14 +26,19 @@
2726
$idfile = $nv_Request->get_int('idfile', 'post', 0);
2827

2928
$authorSubmit = isset($_POST['pozauthor']['author']) ? $_POST['pozauthor']['author'] : '';
30-
if (preg_match('/^([^\<]+)\<([^\>]+)\>$/', $authorSubmit, $m) and nv_check_valid_email(trim($m[2])) == '') {
31-
$authorSubmit = trim(strip_tags($m[1])) . ' <' . trim($m[2]) . '>';
29+
if (preg_match('/^([^\<]+)\<([^\>]+)\>$/', $authorSubmit, $m)) {
30+
$check = nv_check_valid_email(trim($m[2]), true);
31+
if ($check[0] == '') {
32+
$authorSubmit = trim(strip_tags($m[1])) . ' <' . $check[1] . '>';
33+
} else {
34+
$authorSubmit = false;
35+
}
3236
} else {
3337
$authorSubmit = false;
3438
}
3539

36-
$lang_translator = $nv_Request->get_array('pozauthor', 'post', array());
37-
$lang_translator_save = array();
40+
$lang_translator = $nv_Request->get_array('pozauthor', 'post', []);
41+
$lang_translator_save = [];
3842

3943
$langtype = isset($lang_translator['langtype']) ? strip_tags($lang_translator['langtype']) : 'lang_module';
4044

@@ -59,7 +63,7 @@
5963

6064
nv_insert_logs(NV_LANG_DATA, $module_name, $lang_module['nv_admin_edit'] . ' -> ' . $language_array[$dirlang]['name'], $module . ' : idfile = ' . $idfile, $admin_info['userid']);
6165

62-
$pozlang = $nv_Request->get_array('pozlang', 'post', array());
66+
$pozlang = $nv_Request->get_array('pozlang', 'post', []);
6367

6468
if (!empty($pozlang)) {
6569
$sth = $db->prepare('UPDATE ' . NV_LANGUAGE_GLOBALTABLE . ' SET lang_' . $dirlang . '= :lang_value WHERE id= :id');
@@ -71,8 +75,8 @@
7175
}
7276
}
7377

74-
$pozlangkey = $nv_Request->get_array('pozlangkey', 'post', array());
75-
$pozlangval = $nv_Request->get_array('pozlangval', 'post', array());
78+
$pozlangkey = $nv_Request->get_array('pozlangkey', 'post', []);
79+
$pozlangval = $nv_Request->get_array('pozlangval', 'post', []);
7680

7781
$sizeof = sizeof($pozlangkey);
7882
$sth = $db->prepare('INSERT INTO ' . NV_LANGUAGE_GLOBALTABLE . ' (idfile, lang_key, lang_' . $dirlang . ') VALUES (' . $idfile . ', :lang_key, :lang_value)');
@@ -102,7 +106,7 @@
102106

103107
if (!empty($dirlang) and !empty($module)) {
104108
if (empty($author_lang)) {
105-
$array_translator = array();
109+
$array_translator = [];
106110
$array_translator['author'] = '';
107111
$array_translator['createdate'] = '';
108112
$array_translator['copyright'] = '';
@@ -161,4 +165,4 @@
161165

162166
include NV_ROOTDIR . '/includes/header.php';
163167
echo nv_admin_theme($contents);
164-
include NV_ROOTDIR . '/includes/footer.php';
168+
include NV_ROOTDIR . '/includes/footer.php';

admin/settings/system.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050
}
5151

5252
$site_email = nv_substr($nv_Request->get_title('site_email', 'post', '', 1), 0, 255);
53-
if (nv_check_valid_email($site_email) == '') {
54-
$array_config_site['site_email'] = $site_email;
53+
$check = nv_check_valid_email($site_email, true);
54+
if ($check[0] == '') {
55+
$array_config_site['site_email'] = $check[1];
5556
}
5657

5758
$array_config_site['site_phone'] = nv_substr($nv_Request->get_title('site_phone', 'post', ''), 0, 20);
@@ -139,8 +140,9 @@
139140

140141
$array_config_global['error_set_logs'] = $nv_Request->get_int('error_set_logs', 'post', 0);
141142
$error_send_email = nv_substr($nv_Request->get_title('error_send_email', 'post', '', 1), 0, 255);
142-
if (nv_check_valid_email($error_send_email) == '') {
143-
$array_config_global['error_send_email'] = $error_send_email;
143+
$check = nv_check_valid_email($error_send_email, true);
144+
if ($check[0] == '') {
145+
$array_config_global['error_send_email'] = $check[1];
144146
}
145147

146148
$array_config_global['cdn_url'] = '';

includes/core/admin_login.php

+10-8
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ function validUserLog($array_user)
5757
);
5858

5959
$stmt = $db->prepare("UPDATE " . NV_USERS_GLOBALTABLE . " SET
60-
checknum = :checknum,
61-
last_login = " . NV_CURRENTTIME . ",
62-
last_ip = :last_ip,
63-
last_agent = :last_agent,
64-
last_openid = '',
65-
remember = 1
66-
WHERE userid=" . $array_user['userid']);
60+
checknum = :checknum,
61+
last_login = " . NV_CURRENTTIME . ",
62+
last_ip = :last_ip,
63+
last_agent = :last_agent,
64+
last_openid = '',
65+
remember = 1
66+
WHERE userid=" . $array_user['userid']);
6767

6868
$stmt->bindValue(':checknum', $checknum, PDO::PARAM_STR);
6969
$stmt->bindValue(':last_ip', NV_CLIENT_IP, PDO::PARAM_STR);
@@ -124,7 +124,9 @@ function validUserLog($array_user)
124124
}
125125
}
126126

127-
if (nv_check_valid_email($nv_username) == '') {
127+
$check_email = nv_check_valid_email($nv_username, true);
128+
if ($check_email[0] == '') {
129+
$nv_username = $check_email[1];
128130
$sql = 't2.email =' . $db->quote($nv_username);
129131
$login_email = true;
130132
} else {

includes/functions.php

+33-12
Original file line numberDiff line numberDiff line change
@@ -411,34 +411,55 @@ function nv_check_valid_pass($pass, $max, $min)
411411
}
412412

413413
/**
414-
* nv_check_valid_email()
414+
* Kiểm tra email có hợp lệ hay không
415+
* Nếu $return = true thì trả về email đã được hợp chuẩn
415416
*
416417
* @param string $mail
417-
* @return
418+
* @param boolean $return
419+
* @return string
418420
*/
419-
function nv_check_valid_email($mail)
421+
function nv_check_valid_email($mail, $return = false)
420422
{
421423
global $lang_global, $global_config;
422424

423-
$mail = strip_tags(trim($mail));
424-
425425
if (empty($mail)) {
426-
return $lang_global['email_empty'];
426+
return $return ? [$lang_global['email_empty'], $mail] : $lang_global['email_empty'];
427+
}
428+
429+
if ($return) {
430+
$mail = nv_strtolower(strip_tags(trim($mail)));
431+
}
432+
433+
// Email quy định ký tự @ xuất hiện 1 lần duy nhất
434+
if (substr_count($mail, '@') !== 1) {
435+
return $return ? [$lang_global['email_incorrect'], $mail] : $lang_global['email_incorrect'];
436+
}
437+
438+
// Cắt email ra làm hai phần để kiểm tra
439+
$_mail = explode('@', $mail);
440+
$_mail_user = $_mail[0];
441+
$_mail_domain = nv_check_domain($_mail[1]);
442+
443+
if (empty($_mail_domain)) {
444+
return $return ? [$lang_global['email_incorrect'], $mail] : $lang_global['email_incorrect'];
427445
}
428446

447+
// Chuyển lại email từ Unicode domain thành IDNA ASCII
448+
$mail = $_mail_user . '@' . $_mail_domain;
449+
429450
if (function_exists('filter_var') and filter_var($mail, FILTER_VALIDATE_EMAIL) === false) {
430-
return $lang_global['email_incorrect'];
451+
return $return ? [$lang_global['email_incorrect'], $mail] : $lang_global['email_incorrect'];
431452
}
432453

433-
if (! preg_match($global_config['check_email'], $mail)) {
434-
return $lang_global['email_incorrect'];
454+
if (!preg_match($global_config['check_email'], $mail)) {
455+
return $return ? [$lang_global['email_incorrect'], $mail] : $lang_global['email_incorrect'];
435456
}
436457

437-
if (! preg_match('/\.([a-z0-9\-]+)$/', $mail)) {
438-
return $lang_global['email_incorrect'];
458+
if (!preg_match('/\.([a-z0-9\-]+)$/', $mail)) {
459+
return $return ? [$lang_global['email_incorrect'], $mail] : $lang_global['email_incorrect'];
439460
}
440461

441-
return '';
462+
return $return ? ['', $mail] : '';
442463
}
443464

444465
/**

install/index.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,9 @@
749749
$array_data['re_password'] = $nv_Request->get_title('re_password', 'post', $array_data['re_password']);
750750
$array_data['lang_multi'] = (int) $nv_Request->get_bool('lang_multi', 'post', $array_data['lang_multi']);
751751

752+
$check_email = nv_check_valid_email($array_data['nv_email'], true);
753+
$array_data['nv_email'] = $check_email[1];
754+
752755
try {
753756
$array_data['question'] = $nv_Request->get_title('question', 'post', $array_data['question'], 1);
754757
$array_data['answer_question'] = $nv_Request->get_title('answer_question', 'post', $array_data['answer_question'], 1);
@@ -773,16 +776,15 @@
773776
} else {
774777
$check_login = nv_check_valid_login($array_data['nv_login'], $global_config['nv_unickmax'], $global_config['nv_unickmin']);
775778
$check_pass = nv_check_valid_pass($array_data['nv_password'], $global_config['nv_upassmax'], $global_config['nv_upassmin']);
776-
$check_email = nv_check_valid_email($array_data['nv_email']);
777779

778780
if (empty($array_data['site_name'])) {
779781
$error = $lang_module['err_sitename'];
780782
} elseif (!empty($check_login)) {
781783
$error = $check_login;
782784
} elseif ("'" . $array_data['nv_login'] . "'" != $db->quote($array_data['nv_login'])) {
783785
$error = sprintf($lang_module['account_deny_name'], '<strong>' . $array_data['nv_login'] . '</strong>');
784-
} elseif (!empty($check_email)) {
785-
$error = $check_email;
786+
} elseif (!empty($check_email[0])) {
787+
$error = $check_email[0];
786788
} elseif (!empty($check_pass)) {
787789
$error = $check_pass;
788790
} elseif ($array_data['nv_password'] != $array_data['re_password']) {

install/tpl/step6.tpl

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ $(document).ready(function(){
4343
<tr>
4444
<th scope="row" class="spec"> {LANG.admin_email} <span class="highlight_red">*</span></th>
4545
<td>
46-
<input type="text" value="{DATA.nv_email}" name="nv_email" class="required email" id="nv_email_iavim"/>
46+
<input type="email" value="{DATA.nv_email}" name="nv_email" class="required email" id="nv_email_iavim"/>
4747
</td>
4848
<td>{LANG.admin_email_note}</td>
4949
</tr>
@@ -106,4 +106,4 @@ $(document).ready(function(){
106106
document.getElementById('site_config').setAttribute("autocomplete", "off");
107107
//]]>
108108
</script>
109-
<!-- END: step -->
109+
<!-- END: step -->

0 commit comments

Comments
 (0)