<?php
//base path learning to resources

require_once '../base_path_include.php';
require_once $base_path_to_learning_resources . "includes/connect.php";

require_once $base_path_to_learning_resources . 'lib/function.php';
require_once $base_path_to_learning_resources . 'lib/validate_api_signature.php';

$data = json_decode(file_get_contents('php://input'), true);

validateCurlSignature($data['api_signature']);

$postdata = $data['user'];

$username = $postdata['username'];
$workspace_id = $postdata['workspace_id'];
$password = $postdata['password'];

$excute_sql = $conn_rjllearning->prepare("SELECT * FROM users WHERE  username = ? and workspace_id = ? and status = ?");
$excute_sql->execute(array($username, $workspace_id, 1));
$result_users = $excute_sql->fetchAll();
if (count($result_users) != 1) {
  return false;
}
$sql = "UPDATE users SET  password = ? WHERE username = ? and workspace_id = ?";
$conn_rjllearning->prepare($sql)->execute(array($password, $username, $workspace_id));

return true;
