Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Nerdmonkey

Avaliação de classe de login

Recommended Posts

Gostaria que você avaliassem a classe que fiz para logar usuários no meu painel, obrigado.

 

 

<?php
/**
 * 
 * 
 * 
 * 
 * 
 * <b>Login.class:</b>
 * 
 * Conect user into panel when the credentials match in database used email and password provideds 
 * 
 * @author App Conection - 2015-08-09
 * 
 * 
 * 
 * 
 * 
 */
class Login {
/**
* @var string $email
*/
private $email;
 
/**
* @var string @password
*/
private $password;
 
/**
* @var int $status
*/
private $status;
 
/**
* @var array $success
*/
private $success;
 
/**
* @var array $errors
*/
private $errors;
 
/**
* @var mixed[] $fields
*/
private $fields;
 
/**
* @var mixed[] $results
*/
private $results;
 
/**
* @var array $session
*/
private $session;
 
/**
* @var string $email
* @var string $password
* @var int $status
* @var mixed $fields
* 
* @return array JSON
*/
public function __construct($email,$password,$status = null){
$this->email = $email;
$this->password = $password;
$this->status = ((int) $status ? (int) $status : 1);
$this->fields = array('email' => $this->email,'password' => $this->password);
$this->verifyAccount();
}
 
/**
     * <b>setErros: </b> Set the errors and return it for AJAX
     * 
     * This return will be focus the field wich this id pass in second param object
     * This work well like this:
     * we explode this json and stores it in an new array where index[0] contains the message
     * and index[1] contains the field what we are focus and change a background
     * 
     * @return \Exception Return this error in json format
     */
    private function setErros() {
        foreach($this->fields as $indice => $val):        
            if($indice != 'action' && $indice != 'id' && empty($val)):
                $e = new Exception("Preecha o campo#{$indice}", E_USER_NOTICE);
                $this->errors=array('erros' => $e->getMessage());
                echo json_encode($this->errors);
                exit;
            endif;
        endforeach;
    }
    
/**
* <b>encondePass():</b>
* 
* Encode the password wich sha1() hash
*/
private function encondePass() {
$this->password = sha1($this->password);
}
 
/**
* <b>readData():</b>
* 
* Read the row from table users searching for credentials passed in email and password and status provided by __construt()
*/
private function readData(){
$read = new Read;
$read->ExeRead('my_table','level,email,password,status','WHERE email = :email AND password = :password AND status = :status',"email={$this->email}&password={$this->password}&status={$this->status}");
 
if($read->getResult()):
$this->results = $read->getResult();
endif;
}
 
/**
* <b>setSession():</b>
* 
* Start a session and create an new indice in a global $_SESSION[] for allow users navigate for locked pages 
*/
private function setSession() {
session_start();
$_SESSION['logado'] = $this->email;
}
 
/**
* <b>defineCallback():</b>
* 
* Define what message show for user
* 
* @return array JSON
*/
private function defineCallback() {
if(!empty($this->results)):
$this->success = array('sucesso' => 'Logado com sucesso, estamos te redirecionando...');
echo json_encode($this->success);
else:
$this->errors = array('erros' => 'Usuário ou senha incorretos. Caso não lembre a senha, clique em recuperar senha ou contacte o administrador para verificar se a conta pode estar com algum bloqueio#exibir_erros');
echo json_encode($this->errors);
endif;
}
 
/**
* <b>verifyAccount():</b>
* 
* Performs all verifications necessary for login an user and provides access for locked pages
* 
* @return array JSON
*/
private function verifyAccount() {
$this->setErros();
$this->encondePass();
$this->readData();
$this->defineCallback();
 
if(!empty($this->results)):
$this->setSession();
endif;
} 
}

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.