'Inactive', 1 => 'Active', ]; } public function type_mapping () { return [ 0 => 'Forgot_token', 1 => 'Access token', 2 => 'Refresh_token', 3 => 'Other', 4 => 'Api Key', 5 => 'Api Secret', 6 => 'Verify', ]; } const NOT_FOUND = 0; const EXPIRED = 1; const FOUND = 2; public function create_verify_token ($user_id, $phone) { $code = rand(100000,999999); $expire_at = date('Y-m-j H:i:s', time() + 60 * 5); $token = $this->create([ 'token' => $code, 'data' => json_encode([ 'code' => $code, 'phone' => $phone ]), 'type' => 6, 'user_id' => $user_id, 'ttl' => 5 * 60, 'issue_at' => date('Y-m-j H:i:s'), 'expire_at' => $expire_at, 'status' => 1 ]); return $code; } public function check_verify_token ($code) { $exist = $this->get_by_field('token', $code); if (!$exist) { return NOT_FOUND; } $expire_at = strtotime($exist->expire_at); if ($expire_at < time()) { return EXPIRED; } return json_decode($exist->data, TRUE); } public function get_user ($where) { return $this->_join ('user', 'user_id', $where, []); } public function get_user_paginated ($page, $limit, $where, $order_by, $direction) { return $this->_join_paginate ('user', 'user_id', $where, $page, $limit, $order_by, $direction, []); } public function count_paginated ($where) { return count($this->_join ('user', 'user_id', $where, [])); } }