96 lines
2.9 KiB
PHP
96 lines
2.9 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Login
|
|
*/
|
|
|
|
|
|
class Login extends CI_Controller
|
|
{
|
|
|
|
private $CI;
|
|
|
|
function __construct()
|
|
{
|
|
$this->CI = & get_instance();
|
|
|
|
}
|
|
|
|
function main()
|
|
{
|
|
|
|
if ( ! $this->CI->input->post_get('token')) {
|
|
$this->CI->apilib->make_error("토큰 값이 넘어오지 않았습니다");
|
|
}
|
|
$token = $this->CI->input->post_get('token');
|
|
|
|
|
|
$app_id = (int) trim($this->CI->input->post_get('app_id'));
|
|
if (empty($app_id)) {
|
|
$this->CI->apilib->make_error("어플 아이디가 넘어오지 않았습니다");
|
|
}
|
|
|
|
|
|
$sessionuser = $this->CI->User_model->get_by_token($app_id, $token);
|
|
$this->CI->load->helper('email');
|
|
|
|
if ( ! $this->CI->input->post('user_email')) {
|
|
$this->CI->apilib->make_error("회원 이메일이 입력되지 않았습니다");
|
|
}
|
|
if ( ! valid_email($this->CI->input->post('user_email')) ) {
|
|
$this->CI->apilib->make_error("이메일이 형식에 맞지 않습니다.");
|
|
}
|
|
if ( ! $this->CI->input->post('user_password')) {
|
|
$this->CI->apilib->make_error("비밀번호를 입력해주십시오.");
|
|
}
|
|
if ( ! $this->CI->input->post('fcm_token')) {
|
|
//$this->CI->apilib->make_error("fcm_token 값이 입력되지 않았습니다");
|
|
}
|
|
|
|
$user_email = trim($this->CI->input->post('user_email'));
|
|
$user_password = trim($this->CI->input->post('user_password'));
|
|
|
|
$userinfo = $this->CI->User_model->get_by_api_email($app_id, $user_email, 'user_id, user_email, user_denied, user_password');
|
|
$hash = password_hash($user_password, PASSWORD_BCRYPT);
|
|
|
|
if ( ! element('user_id', $userinfo) OR ! element('user_password', $userinfo)) {
|
|
$this->CI->apilib->make_error("회원 아이디와 비밀번호가 일치하지 않습니다.");
|
|
} elseif ( ! password_verify($user_password, element('user_password', $userinfo))) {
|
|
$this->CI->apilib->make_error("회원 아이디와 비밀번호가 일치하지 않습니다.");
|
|
} elseif (element('user_denied', $userinfo)) {
|
|
$this->CI->apilib->make_error("회원님의 아이디는 접근이 금지된 아이디입니다");
|
|
}
|
|
|
|
$updatedata = array(
|
|
'user_token' => '',
|
|
);
|
|
$upwhere = array(
|
|
'user_token' => $token,
|
|
);
|
|
$this->CI->User_model->update('', $updatedata, $upwhere);
|
|
|
|
$updatedata = array(
|
|
'user_token' => $token,
|
|
'user_lastlogin_datetime' => cdate('Y-m-d H:i:s'),
|
|
);
|
|
$this->CI->User_model->update(element('user_id', $userinfo), $updatedata);
|
|
|
|
//fcm token 등록하기
|
|
if ($this->CI->input->post('fcm_token')) {
|
|
$this->CI->load->library('Fcm_library');
|
|
$this->CI->fcm_library->update_token(element('user_id', $userinfo), $this->CI->input->post('fcm_token'));
|
|
}
|
|
|
|
|
|
$arr = array(
|
|
'result' => 'ok',
|
|
'token' => $token,
|
|
'app_id' => $app_id,
|
|
'user_id' => element('user_id', $userinfo),
|
|
);
|
|
return $arr;
|
|
|
|
}
|
|
}
|