procMemberRegisterDevice(기기 등록)모듈 커밋

This commit is contained in:
choyeon 2020-06-18 12:06:18 +09:00
parent 3c75e7eafb
commit e5fdd73d3d
7 changed files with 137 additions and 0 deletions

View file

@ -26,6 +26,7 @@
<action name="procMemberInsert" type="controller" ruleset="@insertMember" />
<action name="procMemberCheckValue" type="controller" />
<action name="procMemberLogin" type="controller" ruleset="@login" />
<action name="procMemberRegisterDevice" type="controller" />
<action name="procMemberFindAccount" type="controller" method="GET|POST" ruleset="findAccount" />
<action name="procMemberFindAccountByQuestion" type="controller" method="GET|POST" />
<action name="procMemberAuthAccount" type="controller" method="GET|POST" />

View file

@ -19,6 +19,9 @@ $lang->managed_email_host['allowed'] = 'Only %s e-mail accounts are allowed. (%s
$lang->managed_email_host['prohibited'] = 'E-mail accounts at %s are not allowed. (%s)';
$lang->null_user_id = 'Please enter your ID.';
$lang->null_password = 'Please enter your password.';
$lang->null_device_token = 'Please enter your token value.';
$lang->not_supported_os = 'This device is not supported.';
$lang->invalid_device_token = 'The token does not fit the format';
$lang->invalid_authorization = 'The account is not activated.';
$lang->invalid_email_address = 'You have entered an invalid email address. There is no member who has the email, entered.';
$lang->invalid_user_id = 'You have entered an invalid ID.';

View file

@ -19,6 +19,9 @@ $lang->managed_email_host['allowed'] = '%s 사이트 이메일 계정만 사용
$lang->managed_email_host['prohibited'] = '%s 사이트 이메일 계정은 사용할 수 없습니다. (%s)';
$lang->null_user_id = '회원 아이디를 입력해주세요.';
$lang->null_password = '비밀번호를 입력해주세요.';
$lang->null_device_token = '기기의 토큰을 입력해주세요.';
$lang->not_supported_os = '지원하지 않는 OS입니다.';
$lang->invalid_device_token = '기기의 토큰이 형식에 맞지 않습니다.';
$lang->invalid_authorization = '인증이 필요한 계정입니다.';
$lang->invalid_email_address = '이메일 주소와 일치하는 회원이 없습니다.';
$lang->invalid_user_id = '존재하지 않는 회원 아이디입니다.';

View file

@ -80,6 +80,99 @@ class memberController extends member
return $this->setRedirectUrl($returnUrl, $output);
}
/**
* Register device
*/
function procMemberRegisterDevice()
{
Context::setResponseMethod('JSON');
// Check user_id, password, device_token
$user_id = Context::get('user_id');
$password = Context::get('password');
$device_token = Context::get('device_token');
$device_model = escape(Context::get('device_model'));
// Return an error when id and password doesn't exist
if(!$user_id) throw new Rhymix\Framework\Exception('null_user_id');
if(!$password) throw new Rhymix\Framework\Exception('null_password');
if(!$device_token) throw new Rhymix\Framework\Exception('null_device_token');
$browserInfo = Rhymix\Framework\UA::getBrowserInfo();
$device_type = strtolower($browserInfo->os);
if('android' !== $device_type && 'ios' !== $device_type)
{
throw new \Rhymix\Framework\Exception('not_supported_os');
}
if('ios' === $device_type)
{
if(preg_match("/^[0-9a-z]{64}$/", $device_token))
{
throw new \Rhymix\Framework\Exception('invalid_device_token');
}
}
else if('android' === $device_type)
{
if(preg_match("/^[0-9a-zA-Z:_-]+$/", $device_token))
{
throw new \Rhymix\Framework\Exception('invalid_device_token');
}
}
else
{
throw new \Rhymix\Framework\Exception('not_supported_os');
}
$device_version = $browserInfo->version;
$output = $this->procMemberLogin($user_id, $password);
if(!$output->toBool())
{
return new BaseObject(-1, 'Login failed');
}
$logged_info = Context::get('logged_info');
var_dump($logged_info);exit;
$random_key = Rhymix\Framework\Security::getRandom();
$device_key = hash_hmac('sha256', $random_key, $device_token);
// Start transaction
$oDB = DB::getInstance();
$oDB->begin();
// Remove duplicated token key
$args = new stdClass;
$args->device_token = $device_token;
executeQuery('member.deleteMemberDeviceByToken', $args);
// Create member_device
$args = new stdClass;
$args->device_srl = getNextSequence();
$args->member_srl = $logged_info->member_srl;
$args->device_token = $device_token;
$args->device_key = $device_key;
$args->device_type = $device_type;
$args->device_version = $device_version;
$args->device_model = $device_model;
$output3 = executeQuery('member.insertMemberDevice', $args);
if(!$output3->toBool())
{
$oDB->rollback();
return $output3;
}
$oDB->commit();
// Set parameters
$this->add('member_srl', $logged_info->member_srl);
$this->add('user_id', $logged_info->user_id);
$this->add('user_name', $logged_info->user_name);
$this->add('nick_name', $logged_info->nick_name);
$this->add('device_key', $random_key);
}
/**
* Log-out
*

View file

@ -0,0 +1,8 @@
<query id="deleteMemberDeviceByToken" action="delete">
<tables>
<table name="member_devices" />
</tables>
<conditions>
<condition operation="equal" column="device_token" var="device_token" />
</conditions>
</query>

View file

@ -0,0 +1,17 @@
<query id="insertMemberDevice" action="insert">
<tables>
<table name="member_devices" />
</tables>
<columns>
<column name="device_srl" var="device_srl" notnull="notnull" />
<column name="member_srl" var="member_srl" notnull="notnull" />
<column name="device_token" var="device_token" notnull="notnull" />
<column name="device_key" var="device_key" notnull="notnull" />
<column name="device_type" var="device_type" notnull="notnull" />
<column name="device_version" var="device_version" notnull="notnull" />
<column name="device_model" var="device_model" notnull="notnull" />
<column name="device_description" var="device_description" />
<column name="ipaddress" var="ipaddress" default="ipaddress()" />
<column name="regdate" var="regdate" default="curdate()" />
</columns>
</query>

View file

@ -0,0 +1,12 @@
<table name="member_device">
<column name="device_srl" type="number" notnull="notnull" primary_key="primary_key" />
<column name="member_srl" type="number" notnull="notnull" index="idx_member_srl" />
<column name="device_token" type="varchar" size="200" notnull="notnull" />
<column name="device_key" type="char" size="64" notnull="notnull" />
<column name="device_type" type="date" notnull="notnull" index="idx_device_type" />
<column name="device_version" type="varchar" size="20" notnull="notnull" />
<column name="device_model" type="varchar" size="40" notnull="notnull" />
<column name="device_description" type="varchar" size="200" />
<column name="regdate" type="varchar" size="14" notnull="notnull" index="idx_regdate" />
<column name="ipaddress" type="varchar" size="120" notnull="notnull" />
</table>