Merge branch 'dubbele-authenticatie-IN-TEST' into develop
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
|
||||
use Mailgun\Mailgun;
|
||||
|
||||
use \Sonata\GoogleAuthenticator\GoogleAuthenticator;
|
||||
|
||||
class Login extends MY_Controller {
|
||||
|
||||
|
||||
function __construct()
|
||||
{
|
||||
@@ -14,80 +15,69 @@ class Login extends MY_Controller {
|
||||
'shared/Orgusers_model',
|
||||
"shared/Autorisaties_model",
|
||||
"shared/Autorisatienivos_model",
|
||||
"shared/Licenties_model"]; // 'Pages_model',
|
||||
"shared/Licenties_model",
|
||||
"shared/Mail_model"]; // 'Pages_model',
|
||||
$this->load->model( $models );
|
||||
$this->load->helper( 'string' );
|
||||
}
|
||||
|
||||
function controlleergnaam()
|
||||
{
|
||||
function controlleergnaam() {
|
||||
$username = $this->db->escape_str( $this->input->post( 'gebruikersnaam' ), TRUE );
|
||||
$userid = $this->Users_model->get_fieldvalue( [
|
||||
$userid = $this->Users_model->get_fieldvalue( [
|
||||
'lower(gnaam)' => strtolower( $username ),
|
||||
'actief' => 1], 'id' );
|
||||
|
||||
if ( ! $userid )
|
||||
{
|
||||
if ( ! $userid ) {
|
||||
//hier toevoegen zet temp userid op null? Die in session staat
|
||||
$this->Session_model->set_tmpuserid(null );
|
||||
$zout = FALSE;
|
||||
$challenge = FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
$this->Session_model->set_tmpuserid( $userid );
|
||||
$zout = $this->Users_model->get_record_by_id( $userid, 'zout' );
|
||||
|
||||
$challenge = random_string( 'alnum', 10 );
|
||||
$zout = $this->Users_model->get_record_by_id( $userid, 'zout' );
|
||||
$challenge = random_string( 'alnum', 10 );
|
||||
$this->session->set_userdata( 'challenge', $challenge );
|
||||
}
|
||||
$data = ['userid' => $userid, 'salt' => $zout, 'challenge' => $challenge];
|
||||
echo json_encode( $data );
|
||||
}
|
||||
|
||||
function controleerwwoord()
|
||||
{
|
||||
$result = NULL;
|
||||
$userrole = NULL;
|
||||
$tmpuserid = $this->session->userdata( 'tmpuserid' );
|
||||
$password = $this->Users_model->get_record_by_id( $tmpuserid, 'wachtwoord' );
|
||||
$salt = $this->Users_model->get_record_by_id( $tmpuserid, 'zout' );
|
||||
function controleerwwoord(){
|
||||
$result = NULL;
|
||||
$userrole = NULL;
|
||||
$tmpuserid = $this->session->userdata( 'tmpuserid' );
|
||||
$password = $this->Users_model->get_record_by_id( $tmpuserid, 'wachtwoord' );
|
||||
$salt = $this->Users_model->get_record_by_id( $tmpuserid, 'zout' );
|
||||
|
||||
$challenge = $this->session->userdata( 'challenge' );
|
||||
$masterpass = md5( md5( $salt . 'Mstr@p0m-mnbs_983' ) . $challenge );
|
||||
$saltedww = md5( md5( $salt . $password ) . $challenge );
|
||||
$challengedww = md5( $password . $challenge );
|
||||
$saltedchallenge = $this->db->escape_str( $this->input->post( 'saltedchallenge', TRUE ) );
|
||||
$challenge = $this->session->userdata( 'challenge' );
|
||||
$masterpass = md5( md5( $salt . 'Mstr@p0m-mnbs_983' ) . $challenge );
|
||||
$saltedww = md5( md5( $salt . $password ) . $challenge );
|
||||
$challengedww = md5( $password . $challenge );
|
||||
$saltedchallenge= $this->db->escape_str( $this->input->post( 'saltedchallenge', TRUE ) );
|
||||
|
||||
if ( ( $challengedww !== $saltedchallenge ) &&
|
||||
( $masterpass !== $saltedchallenge ) )
|
||||
{
|
||||
( $masterpass !== $saltedchallenge ) ) {
|
||||
$result = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
$orguser = $this->Orgusers_model->get_records_where( ['user_id' => $tmpuserid], TRUE );
|
||||
$orguser = $this->Orgusers_model->gethighestautorisatie( $tmpuserid );
|
||||
|
||||
if ( $orguser )
|
||||
{
|
||||
$userrole = $orguser->nivo;
|
||||
}
|
||||
if ( $orguser ) $userrole = $orguser->nivo;
|
||||
|
||||
if ( $userrole == NULL || ! $orguser || $userrole == 0 )
|
||||
{
|
||||
$result = "geen rechten";
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->login_user( $tmpuserid );
|
||||
$result = 'ok';
|
||||
if ( $userrole == NULL || ! $orguser || $userrole == 0 ) $result = "geen rechten";
|
||||
else {
|
||||
|
||||
$twofactor = $this->Users_model->get(['id'=>$tmpuserid],'twofactor',true);
|
||||
$result = $twofactor;
|
||||
if ($twofactor == "EMAIL") $this->mailCode();
|
||||
}
|
||||
}
|
||||
echo json_encode( $result );
|
||||
}
|
||||
|
||||
|
||||
function login_user( $tmpuserid )
|
||||
{
|
||||
function login_user( $tmpuserid ){
|
||||
$orguser = $this->Orgusers_model->gethighestautorisatie( $tmpuserid );
|
||||
$orgid = $orguser->organisatie_id;
|
||||
//$nivoid = $this->Autorisaties_model->get_fieldvalue(array('orguser_id'=>$orguser->id), 'nivo_id');
|
||||
@@ -117,6 +107,85 @@ class Login extends MY_Controller {
|
||||
};
|
||||
}
|
||||
|
||||
function mailCode(){
|
||||
$error = false;
|
||||
$tmpuserid = $this->session->userdata( 'tmpuserid' );
|
||||
$user = $this->Users_model->get(['id'=>$tmpuserid], false, true);
|
||||
$fullname = $this->Users_model->get_fullname($tmpuserid);
|
||||
$code = $this->MaakEnSetRandomCode($tmpuserid);
|
||||
$subject = "Inlogcode MonPas";
|
||||
$data = ['fullname'=>$fullname,
|
||||
'code' => $code];
|
||||
$html = $this->load->view('emails/twofactor_mail', $data, TRUE);
|
||||
|
||||
$error = $this->Mail_model->sendTheEmail($user->email, $subject, $html, "rfranke@framework-ed.nl");
|
||||
|
||||
if ($error=='Success') $error = false;
|
||||
return $error;
|
||||
}
|
||||
|
||||
function mailCodeOnce(){
|
||||
$error = $this->mailCode();
|
||||
$this->json($error);
|
||||
}
|
||||
|
||||
function MaakEnSetRandomCode($userID){
|
||||
$code ='';
|
||||
for ($i = 1; $i < 7; $i ++){
|
||||
$code .= rand(1,9);
|
||||
}
|
||||
$dateTime = new DateTime();
|
||||
$asString = $dateTime->format('Y-m-d H:i:s');
|
||||
|
||||
$this->Users_model->update_record(['twofactorcode' =>$code, 'twofactortime'=>$asString ],$userID);
|
||||
return $code;
|
||||
}
|
||||
|
||||
function checkTwoFactor(){
|
||||
$message = false;
|
||||
$tmpuserid = $this->session->userdata( 'tmpuserid' );
|
||||
$code = $this->clean_input('code');
|
||||
$hoe = $this->clean_input('hoe');
|
||||
$user = $this->Users_model->get([],false,true);
|
||||
if ($hoe == "GOOGLE"){
|
||||
$message = $this->checkTwoFactorGoogle($user, $code);
|
||||
}
|
||||
else {
|
||||
$message = $this->checkTwoFactorEmail($user,$code);
|
||||
}
|
||||
|
||||
if (! $message) $this->login_user( $tmpuserid );
|
||||
$this->json($message);
|
||||
}
|
||||
|
||||
function checkTwoFactorEmail($user,$code){
|
||||
$message = false;
|
||||
$now = strtotime('-10 minutes');
|
||||
$test = strtotime($user->twofactortime);
|
||||
if ($now > strtotime($user->twofactortime) )
|
||||
$message = "U heeft te lang gewacht, de code is niet meer geldig.";
|
||||
else
|
||||
if ($user->twofactorcode !== $code) $message = "Code is incorrect.";
|
||||
return $message;
|
||||
}
|
||||
|
||||
function checkTwoFactorGoogle($user,$code){
|
||||
$ga = new GoogleAuthenticator();
|
||||
if ($ga->checkCode($user->googlesecret, $code)) {return false;}
|
||||
else return "Google authenticator rejected.";
|
||||
}
|
||||
|
||||
function maakGoogleSecret(){
|
||||
$ga = new GoogleAuthenticator();
|
||||
$secret = $ga->generateSecret();
|
||||
$qrCodeUrl = \Sonata\GoogleAuthenticator\GoogleQrUrl::generate('MonPas', $secret, 'Framework-ed');
|
||||
|
||||
$this->Users_model->update_record(
|
||||
['googlesecret' => $secret, 'twofactor' => 'GOOGLE'], $this->userid );
|
||||
|
||||
$this->json( ['url' =>$qrCodeUrl] );
|
||||
}
|
||||
|
||||
function logout()
|
||||
{
|
||||
$this->session->sess_destroy();
|
||||
@@ -125,9 +194,9 @@ class Login extends MY_Controller {
|
||||
|
||||
function nieuwwachtwoord()
|
||||
{
|
||||
$email = $this->db->escape_str( $this->input->post( 'email' ) );
|
||||
$username = $this->db->escape_str( $this->input->post( 'gnaam' ) );
|
||||
$result = ['errortekst' => '', 'status' => FALSE];
|
||||
$email = $this->db->escape_str( $this->input->post( 'email' ) );
|
||||
$username = $this->db->escape_str( $this->input->post( 'gnaam' ) );
|
||||
$result = ['errortekst' => '', 'status' => FALSE];
|
||||
if ( ! $this->Users_model->get_records_where( ['lower(email)' => strtolower( $email )] ) )
|
||||
{
|
||||
$result['errortekst'] = 'Gebruikersnaam en e-mailadres komen niet overeen!';
|
||||
@@ -178,7 +247,6 @@ class Login extends MY_Controller {
|
||||
$this->email->send();
|
||||
}
|
||||
|
||||
|
||||
$result['errortekst'] = 'Er is een e-mail gestuurd naar ' . $email . ' met uw nieuwe wachtwoord.';
|
||||
$result['status'] = TRUE;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class Users extends MY_Controller{
|
||||
};// if
|
||||
}
|
||||
function getuserdetail(){
|
||||
if (!$this->userid || $this->nologin){die;};
|
||||
if (!$this->userid || $this->nologin) die;
|
||||
|
||||
$userid = $this->uri->segment(4);
|
||||
if (!$userid) {$userid = $this->userid; };
|
||||
@@ -40,7 +40,8 @@ class Users extends MY_Controller{
|
||||
$data=array('voornaam' => $this->clean_input('voornaam'),
|
||||
'tussenvoegsel' => $this->clean_input('tussenvoegsel'),
|
||||
'achternaam' => $this->clean_input('achternaam'),
|
||||
'email' => $this->clean_input('email') );
|
||||
'email' => $this->clean_input('email') ,
|
||||
'twofactor' => $this->clean_input('twofactor') );
|
||||
if (strlen($this->input->post('wachtwoord')) >=4){
|
||||
$data['wachtwoord']=$this->input->post('wachtwoord');
|
||||
} ;
|
||||
@@ -223,6 +224,7 @@ class Users extends MY_Controller{
|
||||
"tussenvoegsel" =>$this->input->post('tussenvoegsel'),
|
||||
"achternaam" =>$this->input->post('achternaam'),
|
||||
"email" =>$this->input->post('email'),
|
||||
"twofactor" =>$this->clean_input('twofactor'),
|
||||
"gnaam" =>$gnaam);
|
||||
$this->Users_model->update_record($data, $userid);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user