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); if ( ! element('user_id', $sessionuser)) { $this->CI->apilib->make_error("로그인 한 회원만 접근이 가능합니다"); } $user_id = element('user_id', $sessionuser); $this->CI->load->model(array('User_model')); $user_username = $this->CI->input->post('user_username'); $user_old_pw = $this->CI->input->post('user_old_pw'); $user_pw1 = $this->CI->input->post('user_pw1'); $user_pw2 = $this->CI->input->post('user_pw2'); if ( ! $user_old_pw) { $this->CI->apilib->make_error("이전 비밀번호가 입력되지 않았습니다"); } if ( ! password_verify($user_old_pw, element('user_password', $sessionuser))) { $this->CI->apilib->make_error("이전 비밀번호가 일치하지 않습니다"); } if ( ! $user_username) { $this->CI->apilib->make_error("닉네임이 입력되지 않았습니다"); } if ($user_pw1 && $user_pw1 != $user_pw2) { $this->CI->apilib->make_error("2개의 비밀번호가 일치하지 않아 업데이트할 수 없습니다"); } if (mb_strlen($user_username) > 25) { $this->CI->apilib->make_error("25자 이내로 입력해주세요"); } if ($user_username != element('user_username', $sessionuser)) { $userwhere = array( 'app_id' => $app_id, 'user_username' => $user_username, ); $row = $this->CI->User_model->get_one('', 'user_id', $userwhere); if (element('user_id', $row)) { $this->CI->apilib->make_error("이미 사용중인 닉네임입니다. 다른 닉네임을 입력해주세요."); } } $updatedata = array( 'user_username' => $user_username, ); if ($user_pw1 && $user_pw1 == $user_pw2) { $updatedata['user_password'] = password_hash($user_pw1, PASSWORD_BCRYPT); } $user = $this->CI->User_model->update(element('user_id', $sessionuser), $updatedata); $arr = array( 'result' => 'ok', 'token' => $token, 'app_id' => $app_id, 'user_username' => $user_username, 'datetime' => cdate('Y-m-d H:i:s'), ); return $arr; } }