mailgun api

This commit is contained in:
2021-07-16 11:11:58 +02:00
parent 352ceb6785
commit 52172f8116
3 changed files with 160 additions and 103 deletions
+134 -80
View File
@@ -1,128 +1,182 @@
<?php <?php
class Login extends MY_Controller{
function __construct(){ use Mailgun\Mailgun;
class Login extends MY_Controller {
function __construct()
{
parent::__construct(); parent::__construct();
$models = array("shared/Users_model", $models = [
"shared/Users_model",
'shared/Session_model', 'shared/Session_model',
'shared/Orgusers_model', 'shared/Orgusers_model',
"shared/Autorisaties_model", "shared/Autorisaties_model",
"shared/Autorisatienivos_model", "shared/Autorisatienivos_model",
"shared/Licenties_model"); // 'Pages_model', "shared/Licenties_model"]; // 'Pages_model',
$this->load->model($models); $this->load->model( $models );
$this->load->helper('string'); $this->load->helper( 'string' );
} }
function controlleergnaam(){ function controlleergnaam()
$username = $this->db->escape_str($this->input->post('gebruikersnaam'), TRUE); {
$userid = $this->Users_model->get_fieldvalue(array('lower(gnaam)'=> strtolower($username), $username = $this->db->escape_str( $this->input->post( 'gebruikersnaam' ), TRUE );
'actief' => 1), 'id'); $userid = $this->Users_model->get_fieldvalue( [
'lower(gnaam)' => strtolower( $username ),
'actief' => 1], 'id' );
if(!$userid){ if ( ! $userid )
{
$zout = FALSE; $zout = FALSE;
$challenge = FALSE; $challenge = FALSE;
}else{
$this->Session_model->set_tmpuserid($userid);
$zout = $this->Users_model->get_record_by_id($userid, 'zout');
$challenge = random_string('alnum', 10);
$this->session->set_userdata('challenge', $challenge);
} }
$data = array('userid'=>$userid, 'salt'=>$zout, 'challenge'=>$challenge); else
echo json_encode($data); {
$this->Session_model->set_tmpuserid( $userid );
$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');
$challenge = $this->session->userdata('challenge'); function controleerwwoord()
$masterpass = md5(md5($salt.'Mstr@p0m-mnbs_983').$challenge); {
$saltedww = md5(md5($salt.$password).$challenge); $result = NULL;
$challengedww = md5($password.$challenge); $userrole = NULL;
$saltedchallenge= $this->db->escape_str($this->input->post('saltedchallenge', TRUE)); $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' );
if (($challengedww !==$saltedchallenge) && $challenge = $this->session->userdata( 'challenge' );
($masterpass !==$saltedchallenge)){ $masterpass = md5( md5( $salt . 'Mstr@p0m-mnbs_983' ) . $challenge );
$result = null; $saltedww = md5( md5( $salt . $password ) . $challenge );
}else{ $challengedww = md5( $password . $challenge );
$orguser = $this->Orgusers_model->get_records_where(array('user_id'=>$tmpuserid), TRUE); $saltedchallenge = $this->db->escape_str( $this->input->post( 'saltedchallenge', TRUE ) );
$orguser = $this->Orgusers_model->gethighestautorisatie($tmpuserid);
if ($orguser) { if ( ( $challengedww !== $saltedchallenge ) &&
( $masterpass !== $saltedchallenge ) )
{
$result = NULL;
}
else
{
$orguser = $this->Orgusers_model->get_records_where( ['user_id' => $tmpuserid], TRUE );
$orguser = $this->Orgusers_model->gethighestautorisatie( $tmpuserid );
if ( $orguser )
{
$userrole = $orguser->nivo; $userrole = $orguser->nivo;
} }
if ($userrole == null || !$orguser || $userrole ==0){ if ( $userrole == NULL || ! $orguser || $userrole == 0 )
$result="geen rechten"; {
$result = "geen rechten";
} }
else { else
$this->login_user($tmpuserid); {
$result='ok'; $this->login_user( $tmpuserid );
$result = 'ok';
} }
} }
echo json_encode($result); echo json_encode( $result );
} }
function login_user($tmpuserid){ function login_user( $tmpuserid )
$orguser = $this->Orgusers_model->gethighestautorisatie($tmpuserid); {
$orguser = $this->Orgusers_model->gethighestautorisatie( $tmpuserid );
$orgid = $orguser->organisatie_id; $orgid = $orguser->organisatie_id;
//$nivoid = $this->Autorisaties_model->get_fieldvalue(array('orguser_id'=>$orguser->id), 'nivo_id'); //$nivoid = $this->Autorisaties_model->get_fieldvalue(array('orguser_id'=>$orguser->id), 'nivo_id');
//$userrole = $this->Autorisatienivos_model->get_fieldvalue(array('id'=>$nivoid), "nivo"); //$userrole = $this->Autorisatienivos_model->get_fieldvalue(array('id'=>$nivoid), "nivo");
$userrole = $orguser->nivo; $userrole = $orguser->nivo;
$modules = $this->Licenties_model->get_licentie($orgid); $modules = $this->Licenties_model->get_licentie( $orgid );
$this->Session_model->set_userid($tmpuserid); $this->Session_model->set_userid( $tmpuserid );
$this->Session_model->set_orgid($orgid); $this->Session_model->set_orgid( $orgid );
$this->Session_model->set_role($userrole); $this->Session_model->set_role( $userrole );
$this->session->set_userdata(array('language'=>'dutchijk')); $this->session->set_userdata( ['language' => 'dutchijk'] );
if (!$modules) {$this->Session_model->set_module(-1);} if ( ! $modules )
else { if (count($modules) == 1) {$this->Session_model->set_module($modules[0]->sysnr);} {
else {$this->Session_model->set_module(0); } ; $this->Session_model->set_module( - 1 );
}
else
{
if ( count( $modules ) == 1 )
{
$this->Session_model->set_module( $modules[0]->sysnr );
}
else
{
$this->Session_model->set_module( 0 );
};
}; };
} }
function logout(){ function logout()
{
$this->session->sess_destroy(); $this->session->sess_destroy();
redirect(base_url().'index.php/toner'); redirect( base_url() . 'index.php/toner' );
} }
function nieuwwachtwoord(){
$email = $this->db->escape_str($this->input->post('email')); function nieuwwachtwoord()
$username = $this->db->escape_str($this->input->post('gnaam')); {
$result = array('errortekst'=>'', 'status'=>false); $email = $this->db->escape_str( $this->input->post( 'email' ) );
if(!$this->Users_model->get_records_where(array('lower(email)'=> strtolower($email)))){ $username = $this->db->escape_str( $this->input->post( 'gnaam' ) );
$result['errortekst']= 'Gebruikersnaam en e-mailadres komen niet overeen!'; $result = ['errortekst' => '', 'status' => FALSE];
if ( ! $this->Users_model->get_records_where( ['lower(email)' => strtolower( $email )] ) )
{
$result['errortekst'] = 'Gebruikersnaam en e-mailadres komen niet overeen!';
} }
elseif(!$this->Users_model->get_records_where(array('lower(gnaam)'=> strtolower($username)))){ elseif ( ! $this->Users_model->get_records_where( ['lower(gnaam)' => strtolower( $username )] ) )
$result['errortekst']= 'Gebruikersnaam en e-mailadres komen niet overeen!'; {
$result['errortekst'] = 'Gebruikersnaam en e-mailadres komen niet overeen!';
} }
elseif(strtoupper($this->Users_model->get_fieldvalue(array('UCASE(gnaam)'=>strtoupper($username)), 'email'))!=strtoupper($email)){ elseif ( strtoupper( $this->Users_model->get_fieldvalue( ['UCASE(gnaam)' => strtoupper( $username )], 'email' ) ) != strtoupper( $email ) )
$result['errortekst']= 'Gebruikersnaam en e-mailadres komen niet overeen!'; {
}else{ $result['errortekst'] = 'Gebruikersnaam en e-mailadres komen niet overeen!';
$userid = $this->Users_model->get_fieldvalue(array('lower(gnaam)'=> strtolower($username)), 'id'); }
else
{
$userid = $this->Users_model->get_fieldvalue( ['lower(gnaam)' => strtolower( $username )], 'id' );
$salt = $this->Users_model->get_record_by_id($userid, 'zout'); $salt = $this->Users_model->get_record_by_id( $userid, 'zout' );
$password = random_string('alnum', 8); $password = random_string( 'alnum', 8 );
$this->Users_model->update_record(array('wachtwoord'=>md5($salt.$password)), $userid); $this->Users_model->update_record( ['wachtwoord' => md5( $salt . $password )], $userid );
$data = array('username'=>$username, 'password'=>$password, 'fullname'=>$this->Users_model->get_fullname($userid)); $data = ['username' => $username, 'password' => $password, 'fullname' => $this->Users_model->get_fullname( $userid )];
$this->load->library('email'); $html = $this->load->view( 'emails/newpassword_mail', $data, TRUE );
$mg = Mailgun::create( '8d6b5f67d2eb98a75211e2557b00fbfb-e31dc3cc-046e9e0d' ); // For US servers
$mg->messages()->send( 'mg.monpas.nl', [
'from' => 'info@monpas.nl',
'to' => 't.weijmer@pensare.nl',
'subject' => 'Inloggegevens MonPas',
'html' => $html,
'inline' => [
[
'filename' => 'monpasklein.png',
'filePath' => '@css/images/']
]
] );
$this->email->from('noreply@framework.nl', 'Framework+ MonPas'); return;
$this->email->to($email); $this->load->library( 'email' );
$this->email->subject('Inloggegevens MonPas');
$this->email->message($this->load->view('emails/newpassword_mail', $data, TRUE)); $this->email->from( 'noreply@framework.nl', 'Framework+ MonPas' );
$this->email->bcc("rfranke@framework-ed.nl"); $this->email->to( $email );
$this->email->subject( 'Inloggegevens MonPas' );
$this->email->message( $this->load->view( 'emails/newpassword_mail', $data, TRUE ) );
$this->email->bcc( "rfranke@framework-ed.nl" );
$this->email->send(); $this->email->send();
$result['errortekst']= 'Er is een e-mail gestuurd naar '.$email.' met uw nieuwe wachtwoord.'; $result['errortekst'] = 'Er is een e-mail gestuurd naar ' . $email . ' met uw nieuwe wachtwoord.';
$result['status']=true; $result['status'] = TRUE;
} }
echo json_encode($result); echo json_encode( $result );
} }
} }
@@ -10,7 +10,7 @@
<table width="600px" style="background-color:#ffffff;border:4px solid #930f50;margin:10 0 60px 0;"> <table width="600px" style="background-color:#ffffff;border:4px solid #930f50;margin:10 0 60px 0;">
<tr> <tr>
<td colspan="4"> <td colspan="4">
<img src="<?=base_url()?>css/images/monpasklein.png" style="margin:20px; height: 60px;" /> <img src="cid:monpasklein.png" style="margin:20px; height: 60px;" />
<div style="border:2px solid #930f50;width:500px;height;400px;margin-top:20px;padding:20px;margin-left:25px;background-color:#f1f4f7log;"> <div style="border:2px solid #930f50;width:500px;height;400px;margin-top:20px;padding:20px;margin-left:25px;background-color:#f1f4f7log;">
<p style="font-family:arial;font-size:14px;color:#031a3c;"> <p style="font-family:arial;font-size:14px;color:#031a3c;">
Beste <?=$fullname?>,<br /><br /> Beste <?=$fullname?>,<br /><br />
+4 -1
View File
@@ -11,7 +11,10 @@
"source": "https://github.com/bcit-ci/CodeIgniter" "source": "https://github.com/bcit-ci/CodeIgniter"
}, },
"require": { "require": {
"php": ">=7.0" "php": ">=7.0",
"mailgun/mailgun-php": "^3.5",
"kriswallsmith/buzz": "^1.2",
"nyholm/psr7": "^1.4"
}, },
"suggest": { "suggest": {
"paragonie/random_compat": "Provides better randomness in PHP 5.x" "paragonie/random_compat": "Provides better randomness in PHP 5.x"