<?php
$login = new login();
$login->init();
namespace users;
class Login extends \Controller{
private $Key;
private $values ;
private $visitor;
public function init(){
$this->vars();
$this->getModel();
if(isset($this->visitor)&&$this->visitor->islogin()){
$this->redirect('users/Profile/');
}
if(isset($_POST['username'])){
$this->values['title']=$this->_view->get_AtranslationB('login.started');
$user = new User($this->visitor->getloginkey());
if($user->login($this->values['username'],$this->values['password'],$this->values['cripty'])){
$this->setSessionUser($user);
$this->redirect('users/Profile/');
}else{
$this->visitor->ItryLogin();
session_regenerate_id();
$this->setSessionVisitor($this->visitor);
$this->redirect('users/Register/');
}
}
$this->prepare($this->_loc,$this->_action,$this->values);
}
private function prepare($loc,$action,$values,$find =null){
print $this->_view->getheader($loc,$action);
print $this->_view->getform_head($this->_loc,$action);
print $this->_view->get_template($loc,$action,$this->values);
print $this->_view->getfooter($action);
}
private function vars(){
$this->values['title']='Login';
$this->values = $this->_view->get_translations($this->values);
if(isset($_POST['username'])&&ctype_alnum($_POST['username'])){
$this->values['username']=filter_input(INPUT_POST, 'username');
}else{
$this->values['username']='';
}
$this->visitor = $this->getVisitor();
$this->values['loginkey']=$this->visitor->getloginkey();
$this->values['cripty']=$this->funrandencript();
if(isset($_POST['pwx'])){
$this->values['password']=filter_input(INPUT_POST, 'pwx');
}
}
private function funrandencript(){
$i = 0;//TODO rand (0, 1) ;
switch ($i):
case 0:return 'md5';
break;
case 1:return 'sha1';
break;
case 2:return 'Base64.encode';
break;
default:
print 'i is niet gelijk aan 0, 1 of 2';
endswitch;
}
private function ishash($type,$tohach,$code){
switch ($type):
case 'md5':
return(md5($tohach)=== $code);
break;
case 'sha1':
return(sha1($tohach) === $code);
break;
case 'Base64.encode':
return(base64_encode($tohach) === $code);
break;
default :
return($tohach === $code);
endswitch;
}
}
?>