Created
April 16, 2016 01:50
-
-
Save jlamim/25a788d755d52073a981f4917d560763 to your computer and use it in GitHub Desktop.
Model Tokens - Tokens únicos com CodeIgniter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('BASEPATH') OR exit('No direct script access allowed'); | |
class Tokens_model extends CI_Model{ | |
/** | |
* Function SaveToken | |
* | |
* Salva o token gerado no banco de dados | |
* | |
* @param (string) token Token a ser gravado | |
* @return (boolean) | |
*/ | |
function SaveToken($token){ | |
if($this->db->insert('tokens',array('token' => $token))) | |
return true; | |
else | |
return false; | |
} | |
/** | |
* Function IsUniqueToken | |
* | |
* Checa se o token gerado é único, se for grava no banco de dados | |
* | |
* @param (string) token Token a ser gravado | |
* @return (boolean) | |
*/ | |
function IsUniqueToken($token){ | |
$this->db->select('*')->from('tokens')->where('token',$token); | |
if($this->db->count_all_results() == 0) | |
$status = self::SaveToken($token); | |
else | |
$status = false; | |
return $status; | |
} | |
/** | |
* Function ListTokens | |
* | |
* Lista os tokens gerados | |
* | |
* @param (integer) limit Limite de registros a serem exibidos | |
* @return (array) tokens | |
*/ | |
function ListTokens($limit = 10){ | |
$this->db->select('*')->from('tokens')->order_by('token','RAND')->limit($limit); | |
return $this->db->get()->result(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment