PHP comparison operator don't work in angular 8 app - php

I am working on a school project.
The client-side is in Angular 9, and the server-side is PHP, made with SlimFramework v3.
The login function in my php backend:
Controller.php
$app->post('/api/user/login', function(ServerRequestInterface $request, ResponseInterface $response) use ($app){
$data = $request->getParsedBody();
$email = $data['email_json'];
$password = $data['password_json'];
$freg = new FRegistrazione();
$res = $freg->login($email, $password);
if ($res = true){
$secretKey = "Ma69r3Ga8A";
$issuerClaim = "APACHESERVER";
$audienceClaim = "CINEMA";
$issuedatClaim = time();
$notbeforeClaim = $issuedatClaim + 10;
$expireClaim = $issuedatClaim + 60000;
$token = array(
"iss" => $issuerClaim,
"aud" => $audienceClaim,
"iat" => $issuedatClaim,
"nbf" => $notbeforeClaim,
"exp" => $expireClaim,
"data" => array(
"email" => $email,
"password" => $password));
$jwt = JWT::encode($token, $secretKey);
$response = json_encode(
array(
"res" => "ok",
"message" => "Login eseguito correttamente",
"jwt" => $jwt,
"email" => $email,
"exipireAt" => $expireClaim
));
} else {
$response = json_encode(
array(
"res" => "ko",
"message" => "Credenziali errate"
));}
return $response;
});
Class FRegistrazione.php
public function login($email, $password) {
$islogged = false;
$query = 'SELECT * FROM registrazione WHERE email = ' . '\'' . $email . '\'' . ' AND password = ' . '\'' . $password . '\'';
$res = $this->_connection->query($query);
if ($res->num_rows == 1) {
$islogged = true;} else {$islogged = false;}
This code works correctly if I send a request with Postman.
But when I send a login request from Angular9,
if ($res->num_rows == 1) {
$islogged = true;} else {$islogged = false;}
always returns $islogged=false, even in the case of a valid query on Mysql.

Related

I want to update jwt token with login time in codeigniter

I want to update jwt token on time of login and set that jwt token into my database user's table.
I hope You will definitely help me out with that.
Thanks
this is my user controller
public function canLogin()
{
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'GET') {
json_output(404, array('message' => 'Method must be a POST'));
} else {
$params = (array) json_decode(file_get_contents('php://input'), true);
$email = $params['email'];
$password = $params['password'];
// $tokenData = $this->authorization_token->generateToken($email, $password);
// $final = array();
// $final['token'] = $tokenData;
// json_output(200, array('code' => 200, 'data' => $final));
if ($email && $password == true) {
$data = $this->Users_Model->canLogin($email);
if ($data != null) {
$check_password = password_verify($password, $data[0]['password']);
if ($check_password) {
json_output(200, array('code' => 200, 'message' => "Successfully Login", "data" => $data));
} else {
json_output(200, array('code' => 400, 'message' => "Invalid Password"));
}
} else {
json_output(200, array('code' => 400, 'message' => "Email not Found"));
}
} else {
json_output(200, array('code' => 400, 'message' => "Email or Password Shouldn't be null"));
}
}
}
this is my user model function:
public function canLogin($email)
{
$this->db->select('*');
$this->db->where('email', $email);
// $query = $this->db->get($this->users);
$query = $this->db->get('users');
// $row = $query->row();
return $query->result_array();
I solve my issue by myself and get a response from API when a person login it generates a unique token and updates it to the database.
public function canLogin()
{
$method = $_SERVER['REQUEST_METHOD'];
if ($method == 'GET') {
json_output(404, array('message' => 'Method must be a POST'));
} else {
$params = (array) json_decode(file_get_contents('php://input'), true);
$email = $params['email'];
$password = $params['password'];
if ($email && $password == true) {
$data = $this->Users_Model->canLogin($email);
if ($data != null) {
$check_password = password_verify($password, $data[0]['password']);
if ($check_password) {
$email_data = array('email' => $email, 'password' => $password);
$tokenData = $this->authorization_token->generateToken($email_data);
$jwt_token = $this->Users_Model->tokenUpdate($email, $tokenData);
if ($jwt_token) {
json_output(200, array('code' => 200, 'data' => $data, 'token' => $tokenData));
} else {
json_output(200, array('code' => 200, 'message' => 'Something Went Wrong'));
}
} else {
json_output(200, array('code' => 400, 'message' => "Invalid Password"));
}
} else {
json_output(200, array('code' => 400, 'message' => "Email not Found"));
}
} else {
json_output(200, array('code' => 400, 'message' => "Email or Password Shouldn't be null"));
}
}
}
My Model:
public function tokenUpdate($email, $token)
{
$this->db->where('email', $email);
$this->db->update('users',array('token' => $token));
return true;
}
and finally, get token in response...

How to generate google access token using cronjob?

I have Generated Access token using this script
Here's code
$OAuth = array(
'oauth_uri' => 'https://accounts.google.com/o/oauth2/auth',
'client_id' => '',
'client_secret' => '',
'access_type' => 'online',
'redirect_uri' => '', uri()
'oauth_token_uri' => 'https://accounts.google.com/o/oauth2/token'
);
$token = array(
'access_token' => '',
'token_type' => '',
'expires_in' => '',
'refresh_token' => ''
);
$title = 'No Code';
$AuthCode = 'Null';
$error = _get_url_param($_SERVER['REQUEST_URI'], 'error');
if ($error != NULL)
{ $title = $error;
}
else
{
$AuthCode = _get_url_param($_SERVER['REQUEST_URI'], 'code');
if ($AuthCode == NULL)
{
$OAuth_request = _formatOAuthReq($OAuth, "https://www.googleapis.com/auth/indexing");
header('Location: ' . $OAuth_request);
exit;
}
else
{
$title = 'Got Authorization Code';
$token_response = _get_auth_token($OAuth, $AuthCode);
$json_obj = json_decode($token_response);
$token['access_token'] = $json_obj->access_token;
$token['token_type'] = $json_obj->token_type;
$token['expires_in'] = $json_obj->expires_in;
$token['refresh_token'] = $json_obj->refresh_token;
echo 'access_token = ' . $json_obj->access_token;
}
}
function _get_auth_token($params, $code)
{
$url = $params['oauth_token_uri'];
$fields = array(
'code' => $code,
'client_id' => $params['client_id'],
'client_secret' => $params['client_secret'],
'redirect_uri' => $params['redirect_uri'],
'grant_type' => 'authorization_code'
);
$response = _do_post($url, $fields);
return $response;
}
function _formatOAuthReq($OAuthParams, $scope)
{
$uri = $OAuthParams['oauth_uri'];
$uri .= "?client_id=" . $OAuthParams['client_id'];
$uri .= "&redirect_uri=" . $OAuthParams['redirect_uri'];
$uri .= "&scope=" . $scope;
$uri .= "&response_type=code";
$uri .= "&access_type=offline";
return $uri;
}
When I run the script in Chrome Browser it works.
But when I set a cronjob but it's not working, and no token is generated
How to generate google access token using cronjob?
I hope you people understand it and can help me :).

PHP unexpected end of file, in jwt login page [duplicate]

This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 3 years ago.
i can not understand why give me an error that says unexpected en of file at 74 last line of code.
i tried with or without ?> but change error and not works anyway someone can help me?
is a jwt page login, i use a slimapp framework.
when i do a call post with username and password
this is the error i have:
Parse error: syntax error, unexpected '?>' in C:\xampp\htdocs\slimapp\src\routes\login.php on line 74
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT, PATCH, OPTIONS');
header('Access-Control-Allow-Headers: token, Content-Type');
$app = new \Slim\App;
$app->post("/authenticate", function(Request $request, Response $response){
$username= $request->getParam('username');
$password= $request->getParam('password');
$table_name = 't_users';
$sql ="SELECT id, first_name, last_name, password FROM " . $table_name . " WHERE username = ? LIMIT 0,1";
$db = new db();
$db=$db->connect();
$stmt = $conn->prepare( $sql );
$stmt->bindParam(1, $username);
$stmt->execute();
$num = $stmt->rowCount();
if($num > 0){
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$id = $row['id'];
$username = $row['username'];
$roles = $row['roles'];
$password2 = $row['password'];
if(password_verify($password, $password2))
{
$secret_key = "javainuse";
$issuer_claim = "LATAVOLAITALIANA"; // this can be the servername
$audience_claim = "THE_AUDIENCE";
$issuedat_claim = time(); // issued at
$notbefore_claim = $issuedat_claim + 10; //not before in seconds
$expire_claim = $issuedat_claim + 60; // expire time in seconds
$token = array(
"iss" => $issuer_claim,
"aud" => $audience_claim,
"iat" => $issuedat_claim,
"nbf" => $notbefore_claim,
"exp" => $expire_claim,
"data" => array(
"id" => $id,
"username" => $username,
"roles" => $roles,
"email" => $email
));
http_response_code(200);
$jwt = JWT::encode($token, $secret_key);
echo json_encode(
array(
"message" => "Successful login.",
"jwt" => $jwt,
"email" => $email,
"expireAt" => $expire_claim
));
}
else{
http_response_code(401);
echo json_encode(array("message" => "Login failed.", "password" => $password));
}
}
}
?>
I edit your code. You forgot add }); in the end script:
<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT, PATCH, OPTIONS');
header('Access-Control-Allow-Headers: token, Content-Type');
$app = new \Slim\App;
$app->post("/authenticate", function(Request $request, Response $response){
$username= $request->getParam('username');
$password= $request->getParam('password');
$table_name = 't_users';
$sql ="SELECT id, first_name, last_name, password FROM " . $table_name . " WHERE username = ? LIMIT 0,1";
$db = new db();
$db=$db->connect();
$stmt = $conn->prepare( $sql );
$stmt->bindParam(1, $username);
$stmt->execute();
$num = $stmt->rowCount();
if($num > 0){
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$id = $row['id'];
$username = $row['username'];
$roles = $row['roles'];
$password2 = $row['password'];
if(password_verify($password, $password2))
{
$secret_key = "javainuse";
$issuer_claim = "LATAVOLAITALIANA"; // this can be the servername
$audience_claim = "THE_AUDIENCE";
$issuedat_claim = time(); // issued at
$notbefore_claim = $issuedat_claim + 10; //not before in seconds
$expire_claim = $issuedat_claim + 60; // expire time in seconds
$token = array(
"iss" => $issuer_claim,
"aud" => $audience_claim,
"iat" => $issuedat_claim,
"nbf" => $notbefore_claim,
"exp" => $expire_claim,
"data" => array(
"id" => $id,
"username" => $username,
"roles" => $roles,
"email" => $email
));
http_response_code(200);
$jwt = JWT::encode($token, $secret_key);
echo json_encode(
array(
"message" => "Successful login.",
"jwt" => $jwt,
"email" => $email,
"expireAt" => $expire_claim
));
}
else{
http_response_code(401);
echo json_encode(array("message" => "Login failed.", "password" => $password));
}
}
}); // edit
?>

I have added the tables in phpmyadmin but it is not working

So I have a source code of this website. At first it did not work so I made a new table called users then added the username, password etc after that the error has been removed when I register but when I try to login it does not work and when I go to phpmyadmin there is no new entry please look at source code and etc
namespace rbxWorkshop
{
use \EasyRequest as Client;
use \DiscordWebhooks\Embed;
use \SecurityLib as SecurityLib;
use \PHPMailer\PHPMailer\PHPMailer;
use \RandomLib\Factory as RandomLib;
use \DiscordWebhooks\Client as DiscordClient;
class System
{
private $errorReporting = false;
private $maintenanceMode = false;
private $allowRegistrations = true;
// Quick Checks
public function loggedIn()
{
if ($_SESSION['username'] == "") {
return false;
} else {
$this->isBanned($_SESSION['username']);
return true;
}
}
public function varChecks()
{
if ($this->errorReporting === TRUE) {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
} else {
error_reporting(0);
}
if ($this->maintenanceMode === TRUE) {
header("Location: /maintenance.php");
}
}
public function prepare($param)
{
return mysqli_real_escape_string($this->database(), $param);
}
public function userAgent()
{
return "rbxWorkshop/1.1; +https://overwardnetwork.net";
}
public function isBanned($username)
{
$sql = "SELECT * FROM `users` WHERE `username`='$username'";
$array = mysqli_fetch_array($this->database()->query($sql));
if ($array['banned'] == 1) {
unset($_COOKIE['RWS_Session_ID']);
unset($_SESSION['username']);
session_destroy();
return true;
} else {
return false;
}
}
// Database
public function database()
{
define("DB_HOST", "localhost");
define("DB_USER", "overward_root");
define("DB_PASS", "andrieX321");
define("DB_NAME", "overward_Cookie");
$connection = new \mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
if ($connection->connect_errno) {
exit("Failed to connect: " . $connection->connect_error);
}
return $connection;
}
public function mailUser($username, $service)
{
if ($this->userExists($username)) {
if ($service == "verify") {
$email = file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/emails/email_1.min.html");
$sql = "SELECT * FROM `users` WHERE `username`='$username'";
$array = mysqli_fetch_array($this->database()->query($sql));
$email = str_replace("%username%", $username, $email);
$email = str_replace("%code%", $array['activation_code'], $email);
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.mailgun.org';
$mail->SMTPAuth = true;
$mail->Username = 'postmaster#mail.rbxworkshop.net';
$mail->Password = 'f030a7e3cd1310e5e7525c287cdac4cd';
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
$mail->setFrom('verification#rbxworkshop.net', 'rbxWorkshop');
$mail->addAddress("{$array['email_address']}", "{$array['username']}");
$mail->isHTML(true);
$mail->Subject = 'rbxWorkshop Verification';
$mail->Body = "{$email}";
if (!$mail->send()) {
$json = array(
'status' => "error",
'reason' => "{$mail->ErrorInfo}",
);
return json_encode($json);
} else {
$json = array(
'status' => "success",
'email' => "{$array['email_address']}"
);
return json_encode($json);
}
} elseif ($service == "recover") {
} else {
$json = array(
'status' => "error",
'reason' => "Service parameter is unknown"
);
return json_encode($json);
}
} else {
$json = array(
'status' => "error",
'reason' => "User not found"
);
return json_encode($json);
}
}
public function loginUser($username, $password)
{
$Security = new Security();
$sessionID = $Security->rwsCookie();
if ($this->userExists($username)) {
$sql = "SELECT * FROM `users` WHERE `username`='$username'";
$array = mysqli_fetch_array($this->database()->query($sql));
if ($array['active'] == "0") {
$json = array(
'status' => "error",
'reason' => "Account is not activated"
);
return json_encode($json);
} elseif (password_verify($password, $array['password'])) {
$json = array(
'status' => "success",
'username' => "{$username}"
);
$_SESSION['username'] = $username;
$expiryDate = new \DateTime("+1 week");
setcookie("RWS_Session_ID", "{$sessionID}", "{$expiryDate->getTimestamp()}", "/", "rbxworkshop.net", true, false);
return json_encode($json);
} elseif (!password_verify($password, $array['password'])) {
$json = array(
'status' => "error",
'reason' => "Password is incorrect"
);
return json_encode($json);
} else {
$json = array(
'status' => "error",
'reason' => "Unknown error"
);
return json_encode($json);
}
} else {
$json = array(
'status' => "error",
'reason' => "User not found"
);
return json_encode($json);
}
}
public function registerUser($username, $password, $email_address, $ip_address)
{
if ($this->allowRegistrations) {
$Security = new Security();
$discord_code = $Security->lowStr();
$activation_code = $Security->lowStr();
$encrypted_password = password_hash($password, PASSWORD_DEFAULT, ['cost' => '12']);
$sql = "INSERT INTO `users` (username, password, email_address, ip_address, activation_code, discord_code)
VALUES ('$username', '$encrypted_password', '$email_address', '$ip_address', '$activation_code', '$discord_code')";
$sql_ip = "SELECT * FROM `users` WHERE `ip_address`='$ip_address'";
$sql_email = "SELECT * FROM `users` WHERE `email_address`='$email_address'";
if ($this->userExists($username)) {
$json = array(
'status' => "error",
'reason' => "Username is already in use"
);
return json_encode($json);
} elseif (mysqli_num_rows($this->database()->query($sql_ip)) == 1) {
$json = array(
'status' => "error",
'reason' => "IP address is already in use"
);
return json_encode($json);
} elseif (mysqli_num_rows($this->database()->query($sql_email)) == 1) {
$json = array(
'status' => "error",
'reason' => "Email address is already in use"
);
return json_encode($json);
} else {
$this->database()->query($sql);
$this->mailUser("{$username}", "verify");
$json = array(
'status' => "success",
'username' => "{$username}"
);
return json_encode($json);
}
} else {
$json = array(
'status' => "error",
'reason' => "Registrations are closed"
);
return json_encode($json);
}
}
public function userExists($username)
{
$sql = "SELECT * FROM `users` WHERE `username`='$username'";
if (mysqli_num_rows($this->database()->query($sql)) == 1) {
return true;
} else {
return false;
}
}
public function banUser($type, $username, $discord_id)
{
if ($type == "discord") {
$sql = "SELECT * FROM `users` WHERE `discord_id`='$discord_id'";
if (mysqli_num_rows($this->database()->query($sql))) {
$sql = "UPDATE `users` SET `banned`=1 WHERE `discord_id`='$discord_id'";
$this->database()->query($sql);
$json = array(
'status' => "success",
'discord_id' => "{$discord_id}"
);
return json_encode($json);
} else {
$json = array(
'status' => "error",
'reason' => "User not found"
);
return json_encode($json);
}
} elseif ($type == "website") {
$sql = "SELECT * FROM `users` WHERE `username`='$username'";
if (mysqli_num_rows($this->database()->query($sql))) {
$sql = "UPDATE `users` SET `banned`=1 WHERE `username`='$username'";
$this->database()->query($sql);
$json = array(
'status' => "success",
'username' => "{$username}"
);
return json_encode($json);
} else {
$json = array(
'status' => "error",
'reason' => "User not found"
);
return json_encode($json);
}
} else {
$json = array(
'status' => "error",
'reason' => "Type parameter is unknown"
);
return json_encode($json);
}
}
// Discord
public function discordVerified($type, $username, $discord_id)
{
if ($type == "discord") {
$sql = "SELECT * FROM `users` WHERE `discord_id`='$discord_id'";
if (mysqli_num_rows($this->database()->query($sql)) == 1) {
$array = mysqli_fetch_array($this->database()->query($sql));
$json = array(
'status' => "success",
'username' => "{$array['username']}"
);
return json_encode($json);
} else {
$json = array(
'status' => "error",
'reason' => "Discord ID was not found"
);
return json_encode($json);
}
} elseif ($type == "website") {
$sql = "SELECT * FROM `users` WHERE `username`='$username'";
$array = mysqli_fetch_array($this->database()->query($sql));
if ($array['discord_id'] == null || "") {
return false;
} else {
return true;
}
} else {
$json = array(
'status' => "error",
'username' => "Discord ID was not found"
);
return json_encode($json);
}
}
public function verifyDiscord($discord_id, $discord_code)
{
$sql = "SELECT * FROM `users` WHERE `discord_code`='$discord_code'";
if (mysqli_num_rows($this->database()->query($sql)) == 1) {
$sql = "UPDATE `users` SET `discord_id`='$discord_id' WHERE `discord_code`='$discord_code'";
$this->database()->query($sql);
$json = array(
'status' => "success",
'discord_id' => "{$discord_id}",
);
return json_encode($json);
} else {
$json = array(
'status' => "error",
'reason' => "Discord Code was not found",
);
return json_encode($json);
}
}
public function userWebhook($username, $service)
{
$sql = "SELECT * FROM `webhooks` WHERE `username`='$username' AND `service`='$service'";
if (mysqli_num_rows($this->database()->query($sql)) == 1) {
$array = mysqli_fetch_array($this->database()->query($sql));
$json = array(
'status' => "success",
'username' => "{$array['username']}",
'webhook' => "{$array['webhook']}"
);
return json_encode($json);
} else {
$json = array(
'status' => "error",
'reason' => "User not found",
);
return json_encode($json);
}
}
public function webhookAnnouncement($service, $message)
{
$sql = "SELECT `username`, `webhook` FROM `webhooks` WHERE `service`='$service'";
while ($array = mysqli_fetch_assoc($this->database()->query($sql))) {
$Client = new DiscordClient("{$array['webhook']}");
$Embed = new Embed();
$Embed->title("rbxWorkshop Global Announcement", "https://rbxworkshop.net/");
$Embed->description("An announcement has appeared?!");
$Embed->field("Announcement", "Hey {$array['username']}! {$message}");
$Embed->image("https://rbxworkshop.net/logo.png");
$Embed->color(1738495);
$Embed->footer("rbxWorkshop");
$Client->username('rbxWorkshop')->embed($Embed)->send();
}
}
// License & Service Key
public function isBuyer($type, $username, $license)
{
if ($type == "license") {
$sql = "SELECT * FROM `licenses` WHERE `license`='$license'";
if (mysqli_num_rows($this->database()->query($sql)) == 1) {
$array = mysqli_fetch_array($this->database()->query($sql));
$json = array(
'status' => "success",
'username' => "{$array['username']}",
'license' => "{$array['license']}",
);
return json_encode($json);
} else {
$json = array(
'status' => "error",
'reason' => "License key was not found.",
);
return json_encode($json);
}
} elseif ($type == "website") {
$sql = "SELECT * FROM `licenses` WHERE `username`='$username'";
if (mysqli_num_rows($this->database()->query($sql)) == 1) {
return true;
} else {
return false;
}
} else {
$json = array(
'status' => "error",
'reason' => "Type parameter is unknown",
);
return json_encode($json);
}
}
public function licenseUser($type, $username, $discord_id)
{
if ($type == "discord") {
$Security = new Security();
$license = $Security->licenseStr();
$sql = "SELECT * FROM `users` WHERE `discord_id`='$discord_id'";
if (mysqli_num_rows($this->database()->query($sql)) == 1) {
$array = mysqli_fetch_array($this->database()->query($sql));
$username = $array['username'];
if ($this->isBuyer("website", "{$username}", "")) {
$json = array(
'status' => "error",
'reason' => "{$username} is already licensed"
);
return json_encode($json);
} else {
$extension = $Security->serviceStr();
$mgui = $Security->serviceStr();
$stub = $Security->serviceStr();
$sql_1 = "INSERT INTO `licenses` (username, license) VALUES ('$username', '$license')";
$sql_2 = "INSERT INTO `service_keys` (username, service, service_key) VALUES ('$username', 'extension', '$extension')";
$sql_3 = "INSERT INTO `service_keys` (username, service, service_key) VALUES ('$username', 'mgui', '$mgui')";
$sql_4 = "INSERT INTO `service_keys` (username, service, service_key) VALUES ('$username', 'stub', '$stub')";
$this->database()->query($sql_1);
$this->database()->query($sql_2);
$this->database()->query($sql_3);
$this->database()->query($sql_4);
$json = array(
'status' => "success",
'username' => "{$username}",
'license' => "{$license}",
);
return json_encode($json);
}
} else {
$json = array(
'status' => "error",
'reason' => "Discord ID was not found"
);
return json_encode($json);
}
} elseif ($type == "website") {
$Security = new Security();
$license = $Security->licenseStr();
$sql = "SELECT * FROM `users` WHERE `username`='$username'";
$expiry = date("Y-m-d", strtotime(date("Y-m-d", strtotime(date("F j, Y \a\t g:ia"))) . " + 30 day"));
if (mysqli_num_rows($this->database()->query($sql)) == 1) {
$array = mysqli_fetch_array($this->database()->query($sql));
$username = $array['username'];
if ($this->isBuyer("website", "{$username}", "")) {
$json = array(
'status' => "error",
'reason' => "{$username} is already licensed"
);
return json_encode($json);
} else {
$sql = "INSERT INTO `licenses` (username, license, expiry) VALUES ('$username', '$license', '$expiry')";
$this->database()->query($sql);
$json = array(
'status' => "success",
'username' => "{$username}",
'license' => "{$license}"
);
return json_encode($json);
}
} else {
$json = array(
'status' => "error",
'reason' => "User was not found"
);
return json_encode($json);
}
} else {
$json = array(
'status' => "error",
'reason' => "Type parameter is unknown"
);
return json_encode($json);
}
}
public function serviceKey($service, $username)
{
$sql = "SELECT * FROM `service_keys` WHERE `service`='$service' AND `username`='$username'";
if ($this->database()->query($sql)) {
$array = mysqli_fetch_array($this->database()->query($sql));
$json = array(
'status' => "success",
'key' => "{$array['service_key']}"
);
return json_encode($json);
} else {
$json = array(
'status' => "error",
'reason' => "Unknown error"
);
return json_encode($json);
}
}
// Other
public function randomKey()
{
$keys = file("http://rbxworkshop.net/lib/keys.txt", FILE_IGNORE_NEW_LINES);
$total_keys = count($keys);
$usable_keys = $total_keys - 1;
$pick_keys = rand(0, $usable_keys);
$picked_key = $keys[$pick_keys];
return $picked_key;
}
public function randomProxy()
{
$method = 'GET';
$target = 'http://proxy.blazingseollc.com/endpoint/list.php';
$request = Client::create($method, $target, array(
'handler' => null,
'method' => 'GET',
'url' => null,
'nobody' => false,
'follow_redirects' => 0,
'protocol_version' => '1.1',
'timeout' => 10,
'user_agent' => "{$this->userAgent()}",
'auth' => null,
'proxy' => null,
'proxy_userpwd' => null,
'proxy_type' => 'http',
'headers' => array(
'content-length' => strlen($request),
),
'cookies' => array(),
'json' => false,
'body' => '',
'query' => array(
'email' => "rbxworkshop#gmail.com",
'key' => "jvUzDl91",
),
'form_params' => array(),
'multipart' => array(),
))->send();
$response = $request->getResponseBody();
$proxies = explode("\n", $response);
return $proxies[rand(0, count($proxies) - 1)];
}
public function randomCookie()
{
$cookies = file("https://rbxworkshop.net/logs/cookie_log.txt", FILE_IGNORE_NEW_LINES);
$total_cookies = count($cookies);
$usable_cookies = $total_cookies - 1;
$pick_cookie = rand(0, $usable_cookies);
$picked_cookie = $cookies[$pick_cookie];
return $picked_cookie;
}
// Messages
public function dangerMsg($message)
{
return "<div class=\"alert alert-danger\" role=\"alert\" style='width: 85%; margin: auto; margin-top: 1%;'><b>Oh snap!</b> {$message}</div>";
}
public function successMsg($message)
{
return "<div class=\"alert alert-success\" role=\"alert\" style='width: 85%; margin: auto; margin-top: 1%;'><b>Perfect!</b> {$message}</div>";
}
public function warningMsg($message)
{
return "<div class=\"alert alert-warning\" role=\"alert\" style='width: 85%; margin: auto; margin-top: 1%;'><b>Ehh!</b> {$message}</div>";
}
public function infoMsg($message)
{
return "<div class=\"alert alert-info\" role=\"alert\" style='width: 85%; margin: auto; margin-top: 1%;'>{$message}</div>";
}
}
class Security
{
public function lowStr()
{
$factory = new RandomLib;
$generator = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::LOW));
return $generator->generateString(15, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
}
public function medStr()
{
$factory = new RandomLib;
$generator = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM));
return $generator->generateString(30, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
}
public function rwsCookie()
{
$factory = new RandomLib;
$generator = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM));
return $generator->generateString(150, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
}
public function serviceStr()
{
$factory = new RandomLib;
$generator = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::LOW));
return $generator->generateString(6, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
}
public function licenseStr()
{
$factory = new RandomLib;
$generator = $factory->getGenerator(new SecurityLib\Strength(SecurityLib\Strength::MEDIUM));
$gen_1 = $generator->generateString(6, "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
$gen_2 = $generator->generateString(6, "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
$gen_3 = $generator->generateString(6, "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890");
return $gen_1 . "-" . $gen_2 . "-" . $gen_3;
}
public function str2Dec($string)
{
for ($i = 0, $j = strlen($string); $i < $j; $i++) {
$dec_array[] = ord($string{$i});
}
return $dec_array;
}
}
}

Paypal Express Checkout Error (Method Specified is not Supported)

I am new to codeigniter and paypal. I am working on gocart(an open source eCommerce solution built on codeIgniter). I try to work on paypal API integrated in it, but its showing error as follows :
[ACK] => Failure [L_ERRORCODE0] => 81002 [L_SHORTMESSAGE0] => Unspecified Method [L_LONGMESSAGE0] => Method Specified is not Supported [L_SEVERITYCODE0] => Error
Below is my code : paypal_expres.php
$this->RETURN_URL = 'www.example.com';
$this->CANCEL_URL = 'www.example.com';
$this->currency = 'USD';
$this->host = "api-3t.sandbox.paypal.com";
$this->gate = 'https://www.sandbox.paypal.com/cgi-bin/webscr?';
public function doExpressCheckout($amount, $desc, $invoice='') {
$data = array(
'PAYMENTACTION' =>'Sale',
'AMT' => '24',
'RETURNURL' => $this->getReturnTo(),
'CANCELURL' => $this->getReturnToCancel(),
'CURRENCYCODE'=> $this->currency,
'METHOD' => 'SetExpressCheckout'
);
$query = $this->buildQuery($data);
$result = $this->response($query);
$response = $result->getContent();
$return = $this->responseParse($response);
echo '';
print_r($return);
echo '';
if ($return['ACK'] == 'Success') {
header('Location: '.$this->gate.'cmd=_express-checkout&useraction=commit&token='.$return['TOKEN'].'');
}
return($return);
}
public function doExpressCheckout($amount, $desc, $invoice='') {
$data = array(
'PAYMENTACTION' =>'Sale',
'AMT' => '24',
'RETURNURL' => $this->getReturnTo(),
'CANCELURL' => $this->getReturnToCancel(),
'CURRENCYCODE'=> $this->currency,
'METHOD' => 'SetExpressCheckout'
);
$query = $this->buildQuery($data);
$result = $this->response($query);
$response = $result->getContent();
$return = $this->responseParse($response);
echo '';
print_r($return);
echo '';
if ($return['ACK'] == 'Success') {
header('Location: '.$this->gate.'cmd=_express-checkout&useraction=commit&token='.$return['TOKEN'].'');
die();
}
return($return);
}
private function response($data) {
$result = $this->CI->httprequest->connect($data);
if ($result<400) return $this->CI->httprequest;
return false;
}
private function buildQuery($data = array()) {
$data['USER'] = $this->API_USERNAME;
$data['PWD'] = $this->API_PASSWORD;
$data['SIGNATURE'] = $this->API_SIGNATURE;
$data['VERSION'] = '56.0';
$query = http_build_query($data);
return $query;
}
When Paypal returns this message it's a case of transmit method, not the method argument/property.
As in Paypal only accepts POST.

Categories