등록된 기기에서 접속하면 자동으로 로그인시켜 주는 액션 구현

This commit is contained in:
choyeon 2020-06-18 16:02:22 +09:00
parent 286ea1913f
commit e1b207f085
5 changed files with 62 additions and 16 deletions

View file

@ -27,6 +27,7 @@
<action name="procMemberCheckValue" type="controller" />
<action name="procMemberLogin" type="controller" ruleset="@login" />
<action name="procMemberRegisterDevice" type="controller" />
<action name="procMemberLoginWithDevice " 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,9 +19,6 @@ $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,9 +19,6 @@ $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

@ -94,46 +94,44 @@ class memberController extends member
$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');
if(!$user_id) return new BaseObject(-1, 'NULL_USER_ID');
if(!$password) return new BaseObject(-1, 'NULL_PASSWORD');
if(!$device_token) return new BaseObject(-1, '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');
return new BaseObject(-1, 'NOT_SUPPORTED_OS');
}
if('ios' === $device_type)
{
if(preg_match("/^[0-9a-z]{64}$/", $device_token))
{
throw new \Rhymix\Framework\Exception('invalid_device_token');
return new BaseObject(-1, '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');
return new BaseObject(-1, 'INVALID_DEVICE_TOKEN');
}
}
else
{
throw new \Rhymix\Framework\Exception('not_supported_os');
return new BaseObject(-1, 'NOT_SUPPORTED_OS');
}
$device_version = $browserInfo->version;
$output = $this->procMemberLogin($user_id, $password);
if(!$output->toBool())
{
return new BaseObject(-1, 'Login failed');
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);
@ -173,6 +171,46 @@ class memberController extends member
$this->add('device_key', $random_key);
}
/**
* Automatically log-in to registered device
*/
function procMemberLoginWithDevice()
{
Context::setResponseMethod('JSON');
// Check member_srl, device_token, device_key
$member_srl = Context::get('member_srl');
$device_token = escape(Context::get('device_token'));
$random_key = escape(Context::get('device_key'));
// Return an error when id, password and device_key doesn't exist
if(!$member_srl) return new BaseObject(-1, 'NULL_MEMBER_SRL');
if(!$device_token) return new BaseObject(-1, 'NULL_DEVICE_TOKEN');
if(!$random_key) return new BaseObject(-1, 'NULL_DEVICE_KEY');
$args = new stdClass;
$args->member_srl = $member_srl;
$args->device_token = $device_token;
$args->device_key = hash_hmac('sha256', $random_key, $device_token);
$output = executeQueryArray('member.getMemberDevice', $args);
if(!$output->toBool())
{
return new BaseObject(-1, 'DEVICE_RETRIEVE_FAILED');
}
if(!$output->data)
{
return new BaseObject(-1, 'UNREGISTERED_DEVICE');
}
// Log-in
$member_info = MemberModel::getMemberInfoByMemberSrl($member_srl);
$output = $this->doLogin($member_info->user_id);
if(!$output->toBool())
{
return new BaseObject(-1, 'LOGIN_FAILED');
}
}
/**
* Log-out
*

View file

@ -0,0 +1,13 @@
<query id="getMemberDevice" action="select">
<tables>
<table name="member_devices" />
</tables>
<columns>
<column name="*" />
</columns>
<conditions>
<condition operation="equal" column="member_srl" var="member_srl" notnull="notnull" />
<condition operation="equal" column="device_token" var="device_token" notnull="notnull" pipe="and" />
<condition operation="equal" column="device_key" var="device_key" notnull="notnull" pipe="and" />
</conditions>
</query>