Example #1
0
 /**
  * Get all of the emoticons of a certain channel.
  *
  * @return array
  */
 public function emoticons()
 {
     $endpoint = '/chat/' . $this->channel . '/emoticons';
     $response = $this->app->request()->get($endpoint, [], ['Authorization: OAuth ' . $this->user->accessToken()]);
     return Application::where((array) $response->emoticons, function ($key, $value) {
         return $value['subscriber_only'];
     });
 }
Example #2
0
 function token($nonce)
 {
     // TODO: Add time limit to nonce so it can't be called again (5 min?)
     $a = new Application();
     $application = $a->where('nonce', $nonce)->get();
     if ($application->exists()) {
         $application->user->get();
         $data = array('token' => $application->token, 'role' => $application->role, 'user' => $application->user->first_name . ' ' . $application->user->last_name, 'host' => $_SERVER['HTTP_HOST'], 'ssl' => isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] === 'on' || $_SERVER['HTTPS'] === 1));
     } else {
         $this->error(404, "Token not found.");
         return;
     }
     $this->set_response_data($data);
 }
Example #3
0
<?php

$a = new Application();
$a->where('token', '69ad71aa4e07e9338ac49d33d041941b')->get();
if ($a->exists()) {
    $a->delete();
}
$done = true;
Example #4
0
 function index()
 {
     // GC old sessions
     if ($this->method !== 'delete') {
         $gc = new Application();
         $gc->where('role', 'god')->where('created_on <', strtotime('-14 days'))->get();
         $gc->delete_all();
     }
     if ($this->method == 'get') {
         $auth = $this->authenticate();
         if ($auth) {
             $user_id = $auth[0];
             $u = new User();
             $u->get_by_id($user_id);
             if ($u->exists()) {
                 $this->set_response_data(array('token' => $auth[1], 'user' => $u->to_array()));
             } else {
                 $this->error('404', 'User not found.');
                 return;
             }
         } else {
             $this->error('404', 'Session not found.');
             return;
         }
     } else {
         switch ($this->method) {
             case 'post':
                 $u = new User();
                 if ($this->input->post('email') && $this->input->post('password')) {
                     $u->where('email', $this->input->post('email'))->limit(1)->get();
                     if ($u->exists() && $u->check_password($this->input->post('password'))) {
                         $u->create_session($this->session, $this->input->post('remember') === 'on');
                     } else {
                         $this->error('404', 'User not found.');
                         return;
                     }
                 } else {
                     $this->error('403', 'Required parameters "email" and/or "password" are not present.');
                     return;
                 }
                 $this->redirect("/sessions");
                 break;
             case 'delete':
                 $auth = $this->authenticate();
                 if (!$auth) {
                     $this->error('401', 'Not authorized to perform this action.');
                     return;
                 }
                 $a = new Application();
                 $a->where('token', $auth[1])->get();
                 $a->delete();
                 $user_id = $auth[0];
                 $u = new User();
                 $u->get_by_id($user_id);
                 $u->remember_me = null;
                 $u->save();
                 $this->load->helper('cookie');
                 delete_cookie('remember_me');
                 $this->session->sess_destroy();
                 exit;
                 break;
         }
     }
 }
Example #5
0
 function authenticate($require_king = false)
 {
     $token = false;
     $cookie = false;
     $cookie_auth = isset($_SERVER['HTTP_X_KOKEN_AUTH']) && $_SERVER['HTTP_X_KOKEN_AUTH'] === 'cookie';
     $this->load->helper('cookie');
     if (isset($_COOKIE['koken_session_ci']) && $cookie_auth) {
         $token = $this->session->userdata('token');
         if ($token) {
             $cookie = true;
         }
     } else {
         if (isset($_COOKIE['koken_session']) && !$this->strict_cookie_auth) {
             $cookie = unserialize($_COOKIE['koken_session']);
             $token = $cookie['token'];
         } else {
             if ($this->method == 'get' && preg_match("/token:([a-zA-Z0-9]{32})/", $this->uri->uri_string(), $matches)) {
                 // TODO: deprecate this in favor of X-KOKEN-TOKEN
                 $token = $matches[1];
             } else {
                 if (isset($_REQUEST['token'])) {
                     $token = $_REQUEST['token'];
                 } else {
                     if (isset($_SERVER['HTTP_X_KOKEN_TOKEN'])) {
                         $token = $_SERVER['HTTP_X_KOKEN_TOKEN'];
                     }
                 }
             }
         }
     }
     if ($token && $token === $this->config->item('encryption_key')) {
         return true;
     } else {
         if ($token) {
             $a = new Application();
             $a->where('token', $token)->limit(1)->get();
             if ($a->exists()) {
                 if ($a->role === 'god' && $this->strict_cookie_auth) {
                     if (!$cookie) {
                         return false;
                     }
                 } else {
                     if ($a->single_use) {
                         $a->delete();
                     }
                 }
                 return array($a->user_id, $token, $a->role);
             }
         } else {
             if ($cookie_auth && get_cookie('remember_me')) {
                 $remember_token = get_cookie('remember_me');
                 $u = new User();
                 $u->where('remember_me', $remember_token)->get();
                 if ($u->exists()) {
                     $token = $u->create_session($this->session, true);
                     return array($u->id, $token, 'god');
                 }
             }
         }
     }
     return false;
 }
Example #6
0
 public function scoreInquiry()
 {
     if (Auth::check()) {
         $user = Auth::getUser();
     } else {
         return Response::json(array('errCode' => 1, 'message' => '请登录!'));
     }
     $application = Application::where('user_id', '=', $user->id)->first();
     if (!isset($application)) {
         return Response::json(array('errCode' => 2, 'message' => '您还未报名!'));
     }
     $name = Input::get('name');
     $scorenumber = Input::get('scorenumber');
     $name_of_application = $application->name;
     $scorenumber_of_application = $application->scorenumber;
     $validation = Validator::make(array('name' => $name, 'scorenumber' => $scorenumber), array('name' => 'required', 'scorenumber' => 'required'));
     if ($validation->fails()) {
         return Response::json(array('errCode' => 3, 'message' => '信息填写不完整!'));
     }
     if ($name != $name_of_application) {
         return Response::json(array('errCode' => 4, 'message' => '姓名填写错误!'));
     }
     if ($scorenumber != $scorenumber_of_application) {
         return Response::json(array('errCode' => 5, 'message' => '编号填写错误!'));
     }
     $score = $application->score;
     if (!isset($score)) {
         return Response::json(array('errCode' => 6, 'message' => '成绩还未出来!'));
     }
     return Response::json(array('errCode' => 0, 'application' => $application));
 }
Example #7
0
 public static function get_key_info($key)
 {
     if (!is_null($key)) {
         $row = Application::where('key', '=', $key)->first();
         if ($row) {
             return $row;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }