password reset
This commit is contained in:
68
php/php-dog/getPwToken.php
Normal file
68
php/php-dog/getPwToken.php
Normal file
@ -0,0 +1,68 @@
|
||||
<?php
|
||||
header("Access-Control-Allow-Origin: *");
|
||||
header("Access-Control-Allow-Headers: access");
|
||||
header("Access-Control-Allow-Methods: POST");
|
||||
header("Content-Type: application/json; charset=UTF-8");
|
||||
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
|
||||
|
||||
session_start();
|
||||
|
||||
require __DIR__.'/classes/Database.php';
|
||||
require __DIR__.'/classes/lib.php';
|
||||
|
||||
$db_connection = new Database();
|
||||
$conn = $db_connection->dbConnection();
|
||||
|
||||
$data = json_decode(file_get_contents("php://input"));
|
||||
|
||||
$returnData = new CMsg(0);
|
||||
|
||||
//IF REQUEST METHOD IS NOT EQUAL TO POST
|
||||
if($_SERVER["REQUEST_METHOD"] != "POST")
|
||||
{
|
||||
$returnData = new CMsg(0,404,'Page Not Found! REQUEST_METHOD');
|
||||
echo $returnData->jsonarray();
|
||||
return;
|
||||
}
|
||||
|
||||
// CHECKING EMPTY FIELDS
|
||||
if(
|
||||
!isset($data->pwtoken)
|
||||
|| empty(trim($data->pwtoken))
|
||||
)
|
||||
{
|
||||
$fields = ['fields' => ['pwtoken']];
|
||||
$returnData = new CMsg(0,422,'Please Fill in all Required Fields!',$fields);
|
||||
echo $returnData->jsonarray();
|
||||
return;
|
||||
}
|
||||
|
||||
// IF THERE ARE NO EMPTY FIELDS THEN-
|
||||
$pwtoken = trim($data->pwtoken);
|
||||
|
||||
try
|
||||
{
|
||||
$stmt = $conn->prepare("SELECT * FROM `dogs` WHERE `pwtoken`=?");
|
||||
$stmt->execute([$pwtoken]);
|
||||
|
||||
if($stmt->rowCount())
|
||||
{
|
||||
$row = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
}
|
||||
else
|
||||
{
|
||||
$returnData = new CMsg(
|
||||
0,
|
||||
406,
|
||||
'Passwordtoken: '. $pwtoken . ' not valid, nothing changed!'
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
catch(PDOException $e)
|
||||
{
|
||||
$returnData = new CMsg(0,500,$e->getMessage());
|
||||
}
|
||||
|
||||
echo $returnData->jsonarray();
|
||||
?>
|
||||
Reference in New Issue
Block a user