Created
December 9, 2014 10:25
-
-
Save Tjoosten/1254c03284ab530c6119 to your computer and use it in GitHub Desktop.
migration_laravel.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
ini_set('display_errors',0); | |
require_once('Spinternet/Api.php'); | |
//try { | |
$spinternet = Spinternet_Api::getInstance(); | |
$mm = $spinternet->getMemberManagement('jorisp@spinternet.be','sn1145', 'sn1145tAjgcNFWvMBDR48P9IhncE40uUsD6h', false); | |
/* | |
} catch (Exception $ex) { | |
printf('<p class="pre">%s</p>', $ex->__toString()); | |
} | |
*/ | |
include_once 'Auth/Auth.php'; | |
include_once 'Auth/Container.php'; | |
$messages = array(); | |
class CustomAuthContainer extends Auth_Container{ | |
var $loginFunction = ''; | |
var $mm; // member management object | |
/** | |
* Constructor | |
*/ | |
function CustomAuthContainer($mm){ | |
$this->mm=$mm; | |
// Init Here | |
} | |
function fetchData($username, $password, $isChallengeResponse=false){ | |
//global $mm; | |
$user = $this->mm->authPerson($username, $password); | |
//Use reference to the auth object if exists | |
// This is because the auth session variable can change so a static call to setAuthData does not make sense | |
$this->_auth_obj->setAuthData('person', $user); | |
$personid = $user['id']; | |
if ($personid>0){ | |
return true; | |
}else{ | |
return false; | |
} | |
} | |
} | |
function loginFunction($username = null, $status = null, &$auth = null){ | |
/* | |
* Change the HTML output so that it fits to your | |
* application. | |
*/ | |
echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">"; | |
echo "Username: <input type=\"text\" name=\"sn_username\"><br/>"; | |
echo "Password: <input type=\"password\" name=\"sn_password\"><br/>"; | |
echo "<input type=\"submit\" value=\"Aanmelden\">"; | |
echo "</form>"; | |
echo "<br /><br />Wachtwoord vergeten ?<br /><br />\n"; | |
echo "<form method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">\n"; | |
echo "Username: <input type=\"text\" name=\"sn_username\"><br/>\n"; | |
echo "<input type=\"hidden\" name=\"reset_password\" value=\"reset\" />\n"; | |
echo "<input type=\"submit\" value=\"Aanvraag nieuw wachtwoord\">\n"; | |
echo "</form><br /><br />\n"; | |
if (isset($_GET['q'])){$code=$_GET['q'];} | |
echo "<br /><br />Ontving je reeds een activatie code ? Dan kan je die hier doorsturen.<br /><br />\n"; | |
// form | |
echo "<form class=\"form-horizontal\" method=\"post\" action=\"".$_SERVER['PHP_SELF']."\">\n"; | |
echo "<div class=\"form-group\">\n"; | |
echo "<label for=\"Input1\" class=\"col-md-2 control-label\">Activatie code:</label>\n"; | |
echo "<div class=\"col-md-3\">\n"; | |
echo "<input class=\"form-control\" id=\"Input1\" type=\"text\" name=\"code\" value=\"$code\"><br />\n"; | |
echo "</div>\n"; | |
echo "</div>\n"; | |
echo "<div class=\"form-group\">\n"; | |
echo "<div class=\"col-sm-offset-2 col-sm-10\">\n"; | |
echo "<input class=\"btn btn-default\" type=\"submit\" value=\"Bevestiging activatie\">\n"; | |
echo "</div>\n;"; | |
echo "</div>\n"; | |
echo "</form>\n"; | |
} | |
$options = array( | |
'postUsername' => 'sn_username', | |
'postPassword' => 'sn_password', | |
'enableLogging' => false | |
); | |
$auth_container = new CustomAuthContainer($mm); | |
$myauth = new Auth($auth_container, $options , "loginFunction"); | |
//$myauth->setAllowLogin(true); // default true | |
$myauth->setShowLogin(false); | |
$myauth->start(); | |
if (isset($_POST['reset_password']) && $_POST['reset_password'] == 'reset' && !$myauth->checkAuth()) { | |
/* | |
if ($mm->reqNewPassword($_POST['sn_username'])==1){ | |
echo "Reset request sent. Check your mailbox for instructions.<br />"; | |
}else{ | |
echo "Reset request failed.<br />"; | |
} | |
*/ | |
try { | |
$test = $mm->reqNewPassword(trim($_POST['sn_username'])); | |
$warnings = $mm->getWarnings(); | |
if (count($warnings)>0){ | |
foreach ($warnings as $key => $value){ | |
$messages[] = "[warning] $value [$key]"; | |
} | |
} | |
if ($test>0){ | |
$messages[] = "Reset request sent. Check your mailbox for instructions.<br />"; | |
}else{ | |
$messages[] = "Reset request failed.<br />"; | |
} | |
} catch (Exception $ex) { | |
printf('<p class="pre">%s</p>', $ex->__toString()); | |
} | |
} | |
if (isset($_POST['code']) && !$myauth->checkAuth()) { | |
if ($mm->checkValidationcode($_POST['code'])==1){ | |
$messages[] = "New credentials sent to your mailbox.<br />"; | |
}else{ | |
$messages[] = "Code request failed.<br />"; | |
} | |
} | |
if (isset($_GET['action']) && $_GET['action'] == 'logout' && $myauth->checkAuth()) { | |
$myauth->logout(); | |
$myauth->start(); | |
}//else{ | |
if ((isset($_POST['sn_password_reset']))&&($_POST['sn_password_reset']!='') && ($myauth->checkAuth())){ | |
$person = $myauth->getAuthData('person'); | |
try { | |
$u = $mm->updateMemberPassword($person['id'],$person['account']['id'][0],$person['username'],$_POST['sn_password_reset']); | |
//var_dump($u); | |
$warnings = $mm->getWarnings(); | |
//var_dump($warnings); | |
if (count($warnings)>0){ | |
foreach ($warnings as $key => $value){ | |
$messages[] = "[warning] $value [$key]"; | |
} | |
} | |
if ($u){ | |
$messages[] = "Member password update done."; | |
} | |
} catch (Exception $ex) { | |
printf('<br /><span class="error">%s</span><br />', $ex->getMessage()); | |
} | |
} | |
//print_r($_SERVER); | |
switch ($_SERVER['HTTP_HOST']){ | |
case 'my.scoutsinfo.be': | |
$mark = "Spinternet Test"; | |
break; | |
case 'my.scoutnet.be': | |
$mark = "Scoutnet"; | |
break; | |
case 'my.spinternet.be': | |
$mark = "Spinternet"; | |
break; | |
case 'my.jeugdwerker.be': | |
$mark = "Jeugdwerker"; | |
break; | |
case 'my.kljnet.be': | |
$mark = "KLJ Net"; | |
break; | |
case 'my.ksanet.be': | |
$mark = "KSA Net"; | |
break; | |
default: | |
$mark = "Spinternet"; | |
} | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | |
<head> | |
<title><?php echo $mark;?> ID</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<link type="text/css" rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/black-tie/jquery-ui.css" /> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> | |
<script type="text/javascript" src="../js/jquery-1.7.2.js"></script> | |
<script type="text/javascript" src="global.js?v=1"></script> | |
</head> | |
<body> | |
<div class="container"> | |
<?php if (count($messages)>0): ?> | |
<?php foreach ($messages as $message): ?> | |
<span class=""><?php echo $message; ?></span> | |
<?php endif; ?> | |
<?php endif; ?> | |
<?php | |
if ($myauth->getAuth()){ | |
echo "<br />Hallo ".$myauth->getUsername(). " <a href=\"?action=logout\">afmelden</a><br />"; | |
$person = $myauth->getAuthData('person'); | |
echo "<br />Momenteel kan je hier enkel het wachtwoord van je $mark ID resetten: <br /><br />"; | |
//print_r ($person); | |
//echo $myauth->getUsername(); | |
//echo $myauth->getStatus(); | |
?> | |
<form method="post" action=""> | |
<input type="hidden" name="new_password" value="new_password" /> | |
<input type="hidden" name="sn_username" id="sn_username" value="<?php echo $person['username'];?>" /> | |
<input type="button" class="btn btn-danger" value="generate new password" onclick="generate_password()" /><input name="sn_password_reset" id="sn_password" type="text" size="24" maxlength="20" value="" autocomplete="off" class="password1" /> | |
<input type="submit" class="btn btn-danger" value="Wachtwoord wijzigen"> | |
</form><br /><br /> | |
<?php | |
// OPGELET sn0611 kan enkel maar de personen ophalen die een orgnum (= koepel ID, dus bv. het Scouts en Gidsen Vlaanderen ID-nummer) hebben. | |
if ($person['member']==1){ | |
//print_r($mm->getMember($person['id'],124)); | |
} | |
}else{ | |
echo "<br /><br />Je bent nog niet aangemeld:<br /><br /><br />\n"; | |
loginFunction(); | |
//$myauth->start(); | |
} | |
//} | |
?> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment