add apiKey management
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
<?php
|
||||
|
||||
function processPostData($db, $post, $redirectLocation = "."){
|
||||
function processPostData($db, $post, $redirectLocation = '.')
|
||||
{
|
||||
sleep(1);
|
||||
if($post['action']){
|
||||
if ($post['action']) {
|
||||
// if there is a redirectlocation, set it
|
||||
if($post['redirectLocation']){
|
||||
if ($post['redirectLocation']) {
|
||||
$redirectLocation = $post['redirectLocation'];
|
||||
}
|
||||
|
||||
|
||||
// change a users password
|
||||
if($post['action']=="changePassword"){
|
||||
if ($post['action'] == 'changePassword') {
|
||||
$success = changePassword(
|
||||
$db,
|
||||
$post['changerId'],
|
||||
@@ -19,68 +20,70 @@ function processPostData($db, $post, $redirectLocation = "."){
|
||||
$post['newPasswordAgain']
|
||||
);
|
||||
// append success to the redirectlocation
|
||||
if($success){
|
||||
$redirectLocation .= "?changePasswordSuccess=true";
|
||||
}
|
||||
else{
|
||||
$redirectLocation .= "?changePasswordSuccess=false";
|
||||
if ($success) {
|
||||
$redirectLocation .= '?changePasswordSuccess=true';
|
||||
} else {
|
||||
$redirectLocation .= '?changePasswordSuccess=false';
|
||||
}
|
||||
}// end changePassword
|
||||
|
||||
|
||||
// redirect to the redirectlocation
|
||||
header("Location: ".$redirectLocation);
|
||||
header('Location: ' . $redirectLocation);
|
||||
}// end processing action
|
||||
return;
|
||||
return;
|
||||
}
|
||||
|
||||
function sendEmail($toEmail, $emailText, $emailSubject){
|
||||
try{
|
||||
$date=new DateTime();
|
||||
function sendEmail($toEmail, $emailText, $emailSubject)
|
||||
{
|
||||
try {
|
||||
$date = new DateTime();
|
||||
mail(
|
||||
$toEmail,
|
||||
$emailSubject,
|
||||
$emailText
|
||||
);
|
||||
}
|
||||
catch(Exception $e) {
|
||||
echo 'Message: ' .$e->getMessage();
|
||||
} catch(Exception $e) {
|
||||
echo 'Message: ' . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
function attendancesAssocArray2text($attendancesAssocArray){
|
||||
$ret = "";
|
||||
foreach($attendancesAssocArray as $date => $attendees){
|
||||
$ret .= $date."\n";
|
||||
foreach($attendees as $a){
|
||||
function attendancesAssocArray2text($attendancesAssocArray)
|
||||
{
|
||||
$ret = '';
|
||||
foreach ($attendancesAssocArray as $date => $attendees) {
|
||||
$ret .= $date . "\n";
|
||||
foreach ($attendees as $a) {
|
||||
$ret .= "\n";
|
||||
$ret .= "Name: ".$a['name'].", ".$a['vorname']."\n";
|
||||
$ret .= "PLZ: ".$a['corona_PLZ']."\n";
|
||||
$ret .= "Tel.: ".$a['corona_telephon']."\n";
|
||||
$ret .= "eMail: ".$a['corona_eMail']."\n";
|
||||
$ret .= 'Name: ' . $a['name'] . ', ' . $a['vorname'] . "\n";
|
||||
$ret .= 'PLZ: ' . $a['corona_PLZ'] . "\n";
|
||||
$ret .= 'Tel.: ' . $a['corona_telephon'] . "\n";
|
||||
$ret .= 'eMail: ' . $a['corona_eMail'] . "\n";
|
||||
}
|
||||
$ret .= "\n";
|
||||
}
|
||||
return $ret;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
function attendancesAssocArray2mdList($attendancesAssocArray, $date=null){
|
||||
if($date == null)
|
||||
$date=new DateTime();
|
||||
$ret = "# Anwesenheitsliste zur Corona-Kontaktverfolgung der Abteilung Judo des CWSV vom ".$date->format("Y-m-d")."\n\n";
|
||||
foreach($attendancesAssocArray as $d => $attendees){
|
||||
$ret .= "## ".$d."\n";
|
||||
$i=0;
|
||||
foreach($attendees as $a){
|
||||
function attendancesAssocArray2mdList($attendancesAssocArray, $date = null)
|
||||
{
|
||||
if ($date == null) {
|
||||
$date = new DateTime();
|
||||
}
|
||||
$ret = '# Anwesenheitsliste zur Corona-Kontaktverfolgung der Abteilung Judo des CWSV vom ' . $date->format('Y-m-d') . "\n\n";
|
||||
foreach ($attendancesAssocArray as $d => $attendees) {
|
||||
$ret .= '## ' . $d . "\n";
|
||||
$i = 0;
|
||||
foreach ($attendees as $a) {
|
||||
$i += 1;
|
||||
$ret .= "\n";
|
||||
$ret .= $i." ".$a['name'].", ".$a['vorname']."\n";
|
||||
$ret .= " - PLZ: ".$a['corona_PLZ']."\n";
|
||||
$ret .= " - Tel.: ".$a['corona_telephon']."\n";
|
||||
$ret .= " - eMail: ".$a['corona_eMail']."\n";
|
||||
$ret .= $i . ' ' . $a['name'] . ', ' . $a['vorname'] . "\n";
|
||||
$ret .= ' - PLZ: ' . $a['corona_PLZ'] . "\n";
|
||||
$ret .= ' - Tel.: ' . $a['corona_telephon'] . "\n";
|
||||
$ret .= ' - eMail: ' . $a['corona_eMail'] . "\n";
|
||||
}
|
||||
$ret .= "\n";
|
||||
}
|
||||
return $ret;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
//! Checks if multiple keys exist in an array
|
||||
@@ -89,19 +92,20 @@ return $ret;
|
||||
//! @param array|string $keys keys to check for
|
||||
//!
|
||||
//! @return bool true, if *all* keys are set in the array
|
||||
function array_keys_exist( array $array, $keys ) {
|
||||
if ( ! is_array( $keys ) ) {
|
||||
function array_keys_exist(array $array, $keys)
|
||||
{
|
||||
if (!is_array($keys)) {
|
||||
$keys = func_get_args();
|
||||
array_shift( $keys );
|
||||
array_shift($keys);
|
||||
}
|
||||
$count = 0;
|
||||
foreach ( $keys as $key ) {
|
||||
if ( isset( $array[$key] ) || array_key_exists( $key, $array ) ) {
|
||||
foreach ($keys as $key) {
|
||||
if (isset($array[$key]) || array_key_exists($key, $array)) {
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count( $keys ) === $count;
|
||||
return count($keys) === $count;
|
||||
}
|
||||
|
||||
/// updates users password without checking any rights
|
||||
@@ -109,22 +113,22 @@ function array_keys_exist( array $array, $keys ) {
|
||||
/// - $db : pdoDbConnection to use
|
||||
/// - $userId : id of the user with the password to change
|
||||
/// - $password : the password to set
|
||||
function updateUserPassword($db, $userId, $password){
|
||||
function updateUserPassword($db, $userId, $password)
|
||||
{
|
||||
// we don't save the actual password but it's hash
|
||||
if($password != ""){
|
||||
$password = password_hash( $password, PASSWORD_DEFAULT);
|
||||
if ($password != '') {
|
||||
$password = password_hash($password, PASSWORD_DEFAULT);
|
||||
} else {
|
||||
$password = null;
|
||||
}
|
||||
else{
|
||||
$password = NULL;
|
||||
}
|
||||
|
||||
$query = "UPDATE `cwsvjudo`.`wkParticipo_Users` SET `pwHash`=:val WHERE `id`=:id;";
|
||||
$params = array(
|
||||
':val' => array('value'=>$password, 'data_type'=>PDO::PARAM_STR),
|
||||
':id' => array('value'=>$userId, 'data_type'=>PDO::PARAM_INT)
|
||||
);
|
||||
|
||||
$query = 'UPDATE `cwsvjudo`.`wkParticipo_Users` SET `pwHash`=:val WHERE `id`=:id;';
|
||||
$params = [
|
||||
':val' => ['value' => $password, 'data_type' => PDO::PARAM_STR],
|
||||
':id' => ['value' => $userId, 'data_type' => PDO::PARAM_INT]
|
||||
];
|
||||
dbConnector::query($query, $params);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -134,43 +138,42 @@ function updateUserPassword($db, $userId, $password){
|
||||
/// - $changerId: userId who changes the password
|
||||
/// - $changeeId: userId whose password should be changed
|
||||
/// - $ownPassword: password of the user who changes the password
|
||||
/// - $newPasword: the new password
|
||||
/// - $newPassword: the new password
|
||||
/// - $newPasswordAgain: controllInput of the new password
|
||||
function changePassword($db, $changerId, $changeeId, $changerPassword, $newPassword, $newPasswordAgain){
|
||||
function changePassword($db, $changerId, $changeeId, $changerPassword, $newPassword, $newPasswordAgain)
|
||||
{
|
||||
// we need a dbConnection
|
||||
if( !$db ){
|
||||
if (!$db) {
|
||||
// echo("No DB!");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
$changerInfo = getUserData($db, $changerId);
|
||||
|
||||
|
||||
// check the password of the changer
|
||||
if( !password_verify( $changerPassword, $changerInfo['pwHash']) ){
|
||||
if (!password_verify($changerPassword, $changerInfo['pwHash'])) {
|
||||
// echo("Wrong changerPasswod");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// check if the changer is allowed to change the changees password
|
||||
if ( $changerId != $changeeId ){
|
||||
if ($changerId != $changeeId) {
|
||||
$changersKidsIds = getUsersKidsIds($db, $changerId);
|
||||
|
||||
|
||||
// if( !in_array($changeeId, $changersKidsIds) ){
|
||||
if( !isUserInKidIds($changeeId, $changersKidsIds) ){
|
||||
if (!isUserInKidIds($changeeId, $changersKidsIds)) {
|
||||
// echo("not your child: ".$changeeId." not in "); var_dump($changersKidsIds);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// check if the two inputs are the same
|
||||
if( $newPassword != $newPasswordAgain ){
|
||||
if ($newPassword != $newPasswordAgain) {
|
||||
// echo("new pw missmatch");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
updateUserPassword($db, $changeeId, $newPassword);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user