Used CKEditor for being able to edit the post body. Added the ability to make a post and send it to the backend. Formatted post on backend by moving images into respective directory with the post name and unique ID. Showed message if errored or succeeded.

Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
2023-06-26 03:54:25 +01:00
parent 88c5cc9508
commit 61b8d3a987
174 changed files with 895 additions and 187 deletions
+13 -13
View File
@@ -17,16 +17,16 @@ class userData
* @param $password string - Password
* @return bool - True if logged in, false if not
*/
function checkUser(string $username, string $password): bool
public function checkUser(string $username, string $password): bool
{
$conn = dbConn();
$stmt = $conn->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(":username", $username);
$stmt->execute();
// set the resulting array to associative
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
if ($result)
{
if (password_verify($password, $result[0]["password"]))
@@ -43,15 +43,15 @@ class userData
* @param $username string - Username
* @return string - JWT token
*/
function createToken(string $username): string
public function createToken(string $username): string
{
$now = time();
$future = strtotime('+6 hour',$now);
$future = strtotime('+6 hour', $now);
$secretKey = getSecretKey();
$payload = [
"jti"=>$username,
"iat"=>$now,
"exp"=>$future
"jti" => $username,
"iat" => $now,
"exp" => $future
];
return JWT::encode($payload,$secretKey,"HS256");
@@ -62,7 +62,7 @@ class userData
* @param string $email - Email to check
* @return bool - True if email exists, false if not
*/
function checkEmail(string $email): bool
public function checkEmail(string $email): bool
{
$conn = dbConn();
$stmt = $conn->prepare("SELECT * FROM users WHERE email = :email");
@@ -84,14 +84,14 @@ class userData
* @param $email - email address of the userData
* @return string - verification code
*/
function sendResetEmail($email): string
public function sendResetEmail($email): string
{
//generate a random token and email the address
$token = uniqid("rpe-");
$headers1 = "From: noreply@rohitpai.co.uk\r\n";
$headers1 .= "MIME-Version: 1.0\r\n";
$headers1 .= "Content-Type: text/html; charset=UTF-8\r\n";
$message = "
<!doctype html>
<html lang='en'>
@@ -119,14 +119,14 @@ class userData
* @param $password string Password
* @return bool - true if the password was changed, false if not
*/
function changePassword(string $email, string $password): bool
public function changePassword(string $email, string $password): bool
{
$conn = dbConn();
$stmt = $conn->prepare("UPDATE users SET password = :password WHERE email = :email");
$newPwd = password_hash($password, PASSWORD_BCRYPT);
$stmt->bindParam(":password", $newPwd);
$stmt->bindParam(":email", $email);
if ($stmt->execute())
{
return true;