<?php
	/*
	Hezecom Email Solution
	Author: Hezecom Technologies (http://hezecom.com) info@hezecom.net
	COPYRIGHT 2014 ALL RIGHTS RESERVED
	
	You must have purchased a valid license from CodeCanyon.com in order to have 
	access this file.

	You may only use this file according to the respective licensing terms 
	you agreed to when purchasing this item.
	*/
	session_start();	
	include('../config/config.php');
	include('../language/eng.php');
	include('../libraries/functions.php');
	include_once('../libraries/class_dbcon.php');
	include_once('../libraries/upload_class.php');	

	
	$db=DB::getInstance();
	$dbc=new dboptions();

	
	if(empty($_POST) === false) {
	$username = trim(post('username'));
	$password = trim(post('password'));

	if (empty($username) === true || empty($password) === true) {
		die('<div class="alert alert-danger">'.LANG_LOGIN_REQUIRE_USER_PASS.'</div>');
	} else if ($dbc->user_exist_checker($username,'mailusers') === false) {
		die('<div class="alert alert-danger">'.LANG_LOGIN_USER_NOT_EXIST.'</div>');
	} else if ($dbc->account_activation($username,'mailusers') === false) {
		die('<div class="alert alert-danger">'.LANG_LOGIN_USER_NOT_ACTIVE.'</div>');
	} else {
		if (strlen($password) > 30) {
			die('<div class="alert alert-danger">'.LANG_LOGIN_PASSWORD_SHORT.'</div>');
		}
		$login = $dbc->HezeLogin($username, $password,'mailusers');
		if ($login === false) {
			die('<div class="alert alert-danger">'.LANG_LOGIN_INVALID_USER_AND_PASS.'</div>');
		}else {
			$_SESSION['mail_username'] =  $login;
			$_SESSION['mail_password']= UserProfile($_SESSION['mail_username'])->cpassword;
			echo'<script>window.location.replace("login.php");</script>';
			die('<div class="alert alert-success"><i class="fa fa-spinner fa-spin fa-2x"></i> Login in</div>');
			exit();
		}
	}
} 
	
?>