Store three-letter country code instead of calling code

This commit is contained in:
Kijin Sung 2020-03-18 22:05:19 +09:00
parent 342c011a6c
commit 0e9ce525da
8 changed files with 87 additions and 38 deletions

View file

@ -339,7 +339,11 @@ class memberAdminController extends member
$args->redirect_url = getNotEncodedFullUrl('','mid',$redirectModuleInfo->mid);
}
$args->phone_number_default_country = preg_replace('/[^0-9-]/', '', $args->phone_number_default_country);
$args->phone_number_default_country = preg_replace('/[^A-Z]/', '', $args->phone_number_default_country);
if (!array_key_exists($args->phone_number_default_country, Rhymix\Framework\i18n::listCountries()))
{
return new BaseObject('-1', 'msg_need_default_country');
}
$args->phone_number_hide_country = $args->phone_number_hide_country == 'Y' ? 'Y' : 'N';
$args->phone_number_allow_duplicate = $args->phone_number_allow_duplicate == 'Y' ? 'Y' : 'N';
$args->phone_number_verify_by_sms = $args->phone_number_verify_by_sms == 'Y' ? 'Y' : 'N';

View file

@ -598,24 +598,28 @@ class memberAdminView extends member
else if($formInfo->name == 'phone_number')
{
$formTag->type = 'phone';
$match_country = $memberInfo['phone_country'];
if(!$match_country && $member_config->phone_number_default_country)
{
$match_country = $member_config->phone_number_default_country;
}
if($match_country && !preg_match('/^[A-Z]{3}$/', $match_country))
{
$match_country = Rhymix\Framework\i18n::getCountryCodeByCallingCode($match_country);
}
if(!$match_country && Context::get('lang_type') === 'ko')
{
$match_country = 'KOR';
}
if($member_config->phone_number_hide_country !== 'Y')
{
$inputTag = '<select name="phone_country" id="phone_country" class="phone_country">';
$country_list = Rhymix\Framework\i18n::listCountries(Context::get('lang_type') === 'ko' ? Rhymix\Framework\i18n::SORT_NAME_KOREAN : Rhymix\Framework\i18n::SORT_NAME_ENGLISH);
$match_country = $memberInfo['phone_country'];
if(!$match_country && $member_config->phone_number_default_country)
{
$match_country = $member_config->phone_number_default_country;
}
if(!$match_country && Context::get('lang_type') === 'ko')
{
$match_country = '82';
}
foreach($country_list as $country)
{
if($country->calling_code)
{
$inputTag .= '<option value="' . $country->calling_code . '"' . (str_replace('-', '', $country->calling_code) === $match_country ? ' selected="selected"' : '') . '>';
$inputTag .= '<option value="' . $country->iso_3166_1_alpha3 . '"' . ($country->iso_3166_1_alpha3 === $match_country ? ' selected="selected"' : '') . '>';
$inputTag .= escape(Context::get('lang_type') === 'ko' ? $country->name_korean : $country->name_english) . ' (+' . $country->calling_code . ')</option>';
}
}
@ -623,7 +627,7 @@ class memberAdminView extends member
}
if($memberInfo['phone_number'])
{
if($match_country == '82')
if($match_country === 'KOR')
{
$phone_number = Rhymix\Framework\Korea::formatPhoneNumber($memberInfo['phone_number']);
}

View file

@ -632,6 +632,10 @@ class memberController extends member
{
$phone_country = $config->phone_number_default_country;
}
if ($phone_country && !preg_match('/^[A-Z]{3}$/', $phone_country))
{
$phone_country = Rhymix\Framework\i18n::getCountryCodeByCallingCode($phone_country);
}
if ($phone_country !== $_SESSION['verify_by_sms']['country'])
{
throw new Rhymix\Framework\Exception('verify_by_sms_incomplete');
@ -666,7 +670,7 @@ class memberController extends member
}
if ($val === 'phone_number')
{
$args->phone_country = preg_replace('/[^0-9]/', '', Context::get('phone_country'));
$args->phone_country = preg_replace('/[^A-Z]/', '', Context::get('phone_country'));
}
}
@ -922,7 +926,11 @@ class memberController extends member
{
$phone_country = $config->phone_number_default_country;
}
if (preg_replace('/[^0-9]/', '', $phone_country) !== $logged_info->phone_country)
if ($phone_country && !preg_match('/^[A-Z]{3}$/', $phone_country))
{
$phone_country = Rhymix\Framework\i18n::getCountryCodeByCallingCode($phone_country);
}
if ($phone_country !== $logged_info->phone_country)
{
$phone_verify_needed = true;
}
@ -970,7 +978,7 @@ class memberController extends member
}
if ($val === 'phone_number')
{
$args->phone_country = preg_replace('/[^0-9-]/', '', Context::get('phone_country'));
$args->phone_country = preg_replace('/[^A-Z]/', '', Context::get('phone_country'));
}
}
@ -2195,8 +2203,12 @@ class memberController extends member
return $this->recordLoginError(-1, 'invalid_user_id');
}
if($phone_country && !preg_match('/^[A-Z]{3}$/', $phone_country))
{
$phone_country = Rhymix\Framework\i18n::getCountryCodeByCallingCode($phone_country);
}
$user_id = preg_replace('/[^0-9]/', '', $user_id);
$phone_country = preg_replace('/[^0-9]/', '', $phone_country);
$member_info = $oMemberModel->getMemberInfoByPhoneNumber($user_id, $phone_country);
if(!$user_id || strtolower($member_info->phone_number) !== $user_id)
{
@ -2595,15 +2607,18 @@ class memberController extends member
// Format phone number
if (strval($args->phone_number) !== '')
{
$args->phone_country = trim(preg_replace('/[^0-9-]/', '', $args->phone_country), '-');
$args->phone_country = trim(preg_replace('/[^A-Z]/', '', $args->phone_country), '-');
$args->phone_number = preg_replace('/[^0-9]/', '', $args->phone_number);
$args->phone_type = '';
if ($config->phone_number_hide_country === 'Y' || (!$args->phone_country && $config->phone_number_default_country))
{
$args->phone_country = $config->phone_number_default_country;
}
$args->phone_country = str_replace('-', '', $args->phone_country);
if ($args->phone_country == '82' && !Rhymix\Framework\Korea::isValidPhoneNumber($args->phone_number))
if ($args->phone_country && !preg_match('/^[A-Z]{3}$/', $args->phone_country))
{
$args->phone_country = Rhymix\Framework\i18n::getCountryCodeByCallingCode($args->phone_country);
}
if ($args->phone_country === 'KOR' && !Rhymix\Framework\Korea::isValidPhoneNumber($args->phone_number))
{
return new BaseObject(-1, 'msg_invalid_phone_number');
}
@ -2818,15 +2833,18 @@ class memberController extends member
// Format phone number
if (strval($args->phone_number) !== '')
{
$args->phone_country = trim(preg_replace('/[^0-9-]/', '', $args->phone_country), '-');
$args->phone_country = trim(preg_replace('/[^A-Z]/', '', $args->phone_country), '-');
$args->phone_number = preg_replace('/[^0-9]/', '', $args->phone_number);
$args->phone_type = '';
if ($config->phone_number_hide_country === 'Y' || (!$args->phone_country && $config->phone_number_default_country))
{
$args->phone_country = $config->phone_number_default_country;
}
$args->phone_country = str_replace('-', '', $args->phone_country);
if ($args->phone_country == '82' && !Rhymix\Framework\Korea::isValidPhoneNumber($args->phone_number))
if ($args->phone_country && !preg_match('/^[A-Z]{3}$/', $args->phone_country))
{
$args->phone_country = Rhymix\Framework\i18n::getCountryCodeByCallingCode($args->phone_country);
}
if ($args->phone_country === 'KOR' && !Rhymix\Framework\Korea::isValidPhoneNumber($args->phone_number))
{
return new BaseObject(-1, 'msg_invalid_phone_number');
}
@ -3343,11 +3361,24 @@ class memberController extends member
{
$phone_country = $config->phone_number_default_country;
}
if (!preg_match('/[0-9]{1,}/', $phone_country) || !preg_match('/[0-9]{2,}/', $phone_number))
if (preg_match('/[A-Z]{3}/', $phone_country))
{
$phone_country_calling_code = preg_replace('/[^0-9]/', '', Rhymix\Framework\i18n::getCallingCodeByCountryCode($phone_country));
if (!$phone_country_calling_code)
{
return new BaseObject(-1, 'msg_invalid_phone_number');
}
}
else
{
return new BaseObject(-1, 'msg_invalid_phone_number');
}
if ($phone_country == '82' && !Rhymix\Framework\Korea::isValidPhoneNumber($phone_number))
if (!preg_match('/[0-9]{2,}/', $phone_number))
{
return new BaseObject(-1, 'msg_invalid_phone_number');
}
if ($phone_country === 'KOR' && !Rhymix\Framework\Korea::isValidPhoneNumber($phone_number))
{
return new BaseObject(-1, 'msg_invalid_phone_number');
}
@ -3361,7 +3392,7 @@ class memberController extends member
);
$sms = new Rhymix\Framework\SMS;
$sms->addTo($phone_number, $phone_country);
$sms->addTo($phone_number, $phone_country_calling_code);
$content = '[' . Context::get('site_module_info')->settings->title . '] ' . sprintf(lang('member.verify_by_sms_message'), $code);
$sms->setContent($content);
$result = $sms->send();

View file

@ -304,7 +304,18 @@ class memberModel extends member
function getMemberInfoByPhoneNumber($phone_number, $phone_country = null)
{
if(!$phone_number) return;
if($phone_country)
{
if(preg_match('/^[A-Z]{3}$/', $phone_country))
{
$phone_country = array($phone_country, preg_replace('/[^0-9]/', '', Rhymix\Framework\i18n::getCallingCodeByCountryCode($phone_country)));
}
else
{
$phone_country = array(preg_replace('/[^0-9]/', '', $phone_country), Rhymix\Framework\i18n::getCountryCodeByCallingCode($phone_country));
}
}
$args = new stdClass();
$args->phone_number = $phone_number;
$args->phone_country = $phone_country;

View file

@ -152,13 +152,13 @@ class memberView extends member
}
elseif($formInfo->name == 'phone_number' && $memberInfo->phone_number)
{
if($memberInfo->phone_country == '82')
{
$item->value = Rhymix\Framework\Korea::formatPhoneNumber($item->value);
}
if($memberConfig->phone_number_hide_country !== 'Y')
{
$item->value = '(+' . $memberInfo->phone_country . ') ' . $item->value;
$item->value = Rhymix\Framework\i18n::formatPhoneNumber($item->value, $memberInfo->phone_country);
}
elseif(($memberConfig->phone_number_default_country === 'KOR' || $memberConfig->phone_number_default_country == '82') && ($memberInfo->phone_country === 'KOR' || $memberInfo->phone_country == '82'))
{
$item->value = Rhymix\Framework\Korea::formatPhoneNumber($item->value);
}
}
}

View file

@ -7,6 +7,6 @@
</columns>
<conditions>
<condition operation="equal" column="phone_number" var="phone_number" notnull="notnull" />
<condition operation="equal" column="phone_country" var="phone_country" pipe="and" />
<condition operation="in" column="phone_country" var="phone_country" pipe="and" />
</conditions>
</query>

View file

@ -59,11 +59,10 @@
<td class="nowr" loop="$usedIdentifiers=>$name,$title">
<!--@if($name === 'email_address')-->
<a href="#popup_menu_area" class="member_{$member_info['member_srl']}">{getEncodeEmailAddress($member_info['email_address'])}</a>
<!--@elseif($name === 'phone_number')-->
<!--@if($member_info['phone_country'] && $member_info['phone_country'] != $member_config->phone_number_default_country)-->
(+{$member_info['phone_country']})
<!--@end-->
<!--@if($member_info['phone_country'] == 82)-->
<!--@elseif($name === 'phone_number' && $member_info['phone_number'])-->
<!--@if($config->phone_number_hide_country !== 'Y')-->
{\Rhymix\Framework\i18n::formatPhoneNumber($member_info['phone_number'], $member_info['phone_country'])}
<!--@elseif(($config->phone_number_default_country === 'KOR' || $memberConfig->phone_number_default_country == '82') && ($member_info['phone_country'] === 'KOR' || $member_info['phone_country'] == '82'))-->
{\Rhymix\Framework\Korea::formatPhoneNumber($member_info['phone_number'])}
<!--@else-->
{$member_info['phone_number']}

View file

@ -142,7 +142,7 @@
<select id="phone_number_default_country" name="phone_number_default_country">
<!--@foreach($country_list as $country_info)-->
<!--@if($country_info->calling_code)-->
<option value="{$country_info->calling_code}" selected="selected"|cond="$country_info->calling_code == $config->phone_number_default_country">
<option value="{$country_info->iso_3166_1_alpha3}" selected="selected"|cond="$country_info->iso_3166_1_alpha3 === $config->phone_number_default_country || $country_info->calling_code === $config->phone_number_default_country">
{$lang_type === 'ko' ? $country_info->name_korean : $country_info->name_english} (+{$country_info->calling_code})
</option>
<!--@endif-->