Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Cadastro extends DB{
- public $erro;
- private $dados;
- private $_tabela;
- /*Extende a classe*/
- function __construct(array $dados, $table='usuarios'){
- $this->_tabela = $table;
- $this->dados = $dados;
- $this->register();
- }
- private function crip($senha){
- return sha1($senha);
- }
- private function check($email){
- $check = self::getConn()->prepare('SELECT `id` FROM `'.$this->_tabela.'` WHERE `email`=? LIMIT 1');
- $check->execute(array($email));
- return $check->rowCount()==0 ? true : false;
- }
- /*Checa se o email é valido "Se já esta cadastrado"*/
- private function validar(){
- session_start();
- if(strtolower($this->dados['captcha'])<>strtolower($_SESSION['securimage_code_value'])){
- $this->erro[] = 'O captcha não confere com a imagem!';
- }
- foreach($this->dados as $colunm=>$value){
- if($colunm == 'senha'){
- $this->dados[$colunm] = $this->crip($value);
- }
- if($value==''){
- $this->erro[] = 'O campo <strong>'.$colunm.'</strong> é obrigatório!';
- }
- }
- if($colunm=='email' AND !preg_match("/^[a-z0-9_\.\-]+@[a-z0-9_\.\-]*[a-z0-9_\-]+\.[a-z]{2,4}$/i",$value)){
- $this->erro[] = 'O email digitado não é válido!';
- }
- }
- /*Valida se todos os campos foram preenchidos*/
- private function setCampos(){
- return '`'.implode('`=?, `',array_keys($this->dados)).'`=?';
- }
- private function register(){
- $this->validar();
- if($this->check($this->dados['email'])){
- if(empty($this->erro)){
- unset($this->dados['captcha']);
- $inserir = self::getConn()->prepare('INSERT INTO '.$this->_tabela.' SET '.$this->setCampos().', `cadastro`=NOW()');
- if($inserir->execute(array_values($this->dados))){
- header('Location: ./');
- exit();
- }else{
- $this->erro[] = 'Não foi possivel fazer seus cadastro agora! Tente mais tarde!';
- }
- }
- }else{
- $this->erro[] = 'O email digitado ja está cadastrado!';
- }
- }
- function getErros(){
- return implode('<br />', $this->erro);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement