Mini Shell

Direktori : /home/emypro/www/en/admin/core/
Upload File :
Current File : /home/emypro/www/en/admin/core/Auth.php

<?php
/**
 * Auth
 *
 * @author Andrew Esteves <andrew@digitalnativa.com.br>
 * @copyright Digital Nativa (www.digitalnativa.com.br)
 */

class Auth
{
	/**
	 * Login
	 *
	 * @param Array $data
	 * @return HTTP header
	 */
	public static function login($data)
	{
		$users = new User();
		$user = $users->condition($data);

		if($user) {
			ini_set('session.use_only_cookies', true);
			session_start();
			session_regenerate_id(true);

			$_SESSION['AUTH_USER'] = $user[0]->name;
			$_SESSION['AUTH_EMAIL'] = $user[0]->email;
			$_SESSION['AUTH_TOKEN'] = sha1($user[0]->name . $user[0]->email);

			header('Location: '. URL_ADMIN);
		}else {
			header('Location: '. URL_ADMIN .'login.php?error=invalid');
		}
	}

	/**
	 * Logout
	 *
	 * @return HTTP header
	 */
	public static function logout()
	{
		session_start();
		session_destroy();
		header('Location: '. URL_ADMIN .'login.php');
	}

	/**
	 * Check if user is logged in
	 *
	 * @return Boolean
	 */
	public static function check()
	{
		if(!session_id()) {
			session_start();
		}

		if(!isset($_SESSION['AUTH_TOKEN']) && $_SESSION['AUTH_TOKEN'] != sha1($_SESSION['AUTH_USER'] . $_SESSION['AUTH_EMAIL'])) {
			header('Location: '. URL_ADMIN .'login.php');
		}
	}

	/**
	 * User info
	 *
	 * @return Array
	 */
	public static function user()
	{
		return array('name' => $_SESSION['auth.name'], 'email' => $_SESSION['auth.email']);
	}
}

Zerion Mini Shell 1.0