Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added tags feature #3

Open
wants to merge 23 commits into
base: release
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 0 additions & 75 deletions .github/workflows/google.yml

This file was deleted.

5 changes: 2 additions & 3 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ jobs:
- run: sudo apt-get install php-curl
- run: php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
- run: php -r "if (hash_file('sha384', 'composer-setup.php') === 'e0012edf3e80b6978849f5eff0d4b4e4c79ff1609dd1e613307e16318854d24ae64f26d17af3ef0bf7cfb710ca74755a') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
- run: php composer-setup.php
- run: php -r "unlink('composer-setup.php');"
- run: sudo apt-get install composer
- run: npm install
- run: npm run install
- run: npm run install_all
- run: cd backend && vendor/bin/phpunit
- run: sudo npm run build --if-present

32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Chef-s-Arena


<b>The link of website is https://codechef.tech/</b><br>(The website is live now)<br><br>


<b>If you have Redis,elastic stack, mysql, php 7.4, composer and node installed properly, then use the below commands</b><br><br><br>
<b>TO INSTALL EVERYTHING (REQUIRED ONLY ONCE)</b><br>
```sudo npm install```<br>
Expand All @@ -24,13 +27,34 @@


<b>Setting up database if importing doesn't work</b><br>
>>Open mysql as root<br>
>>Open mySQL as root<br>
>>type the following commands <br>
>>
>>>```CREATE DATABASE testreact;```<br>
>>>```USE testreact;```<br>
>>>```CREATE TABLE users(id varchar(50),password varchar(50),token varchar(100), refresh varchar(100));```<br>
>>then create a user named 'my_user'@'localhost' with password as 'password' and grant all permissions<br>
>>for more reference see /server/includes/connection.php<br>
>>>
>>>```
>>>CREATE TABLE tags(
>>> -> username VARCHAR(50),
>>> -> tag VARCHAR(50),
>>> -> tag_description VARCHAR(200),
>>> -> category VARCHAR(50),
>>> -> PRIMARY KEY (username, tag)
>>> -> );
>>>```
>>>
>>>```
>>>CREATE TABLE problems(
>>> -> username VARCHAR(50),
>>> -> tag VARCHAR(50),
>>> -> problem_code VARCHAR(50),
>>> -> PRIMARY KEY (username, tag)
>>> -> );
>>>```
>>>
>>>then create a user named 'my_user'@'localhost' with password as 'password' and grant all permissions<br>
>>>for more reference see /server/includes/connection.php<br>

<b>Setting up Redis</b><br>
https://redis.io/download<br>
Expand Down
98 changes: 97 additions & 1 deletion backend/curlFunctions.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,46 @@ function make_curl_request_for_auth_token($code){

}

function curl_client_authentication(){


$redis = new Redis();
$redis->connect('localhost', 6379);

if($redis->exists('client_authentication') == 1){
$result = $redis->get('client_authentication');
$redis->close();
return $result;
}

else{
$ch = curl_init();
$client_id = $_ENV["HTTP_CLIENT_ID"];
$client_secret_id = $_ENV["HTTP_CLIENT_SECRET_ID"];
$redirect_uri = $_ENV["HTTP_REDIRECT_URI"];

curl_setopt($ch, CURLOPT_URL, 'https://api.codechef.com/oauth/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "{\"grant_type\":\"client_credentials\" , \"scope\":\"public\", \"client_id\":\"$client_id\",\"client_secret\":\"$client_secret_id\",\"redirect_uri\":\"$redirect_uri\"}");

$headers = array();
$headers[] = 'Content-Type: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);

$redis->set('client_authentication',$result, 1800);
$redis->close();

return $result;
}
}

function curl_user_details($token){
$ch = curl_init();

Expand Down Expand Up @@ -191,6 +231,32 @@ function curl_contest_details($contest, $token){
return $result;
}


function curl_public_tag_problem_list($filter, $offset,$token){
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://api.codechef.com/tags/problems?filter='.$filter.'&limit=20&offset='.$offset.'');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');


$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Authorization: Bearer '.$token;
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);

return $result;
}




function curl_ranklist($contest, $token){
$ch = curl_init();

Expand Down Expand Up @@ -252,7 +318,6 @@ function curl_get_all_contests($token){
}



function curl_get_present_contests($token, $limit){
$ch = curl_init();

Expand All @@ -275,3 +340,34 @@ function curl_get_present_contests($token, $limit){
return $result;
}

function curl_get_public_tags(){


$redis = new Redis();
$redis->connect('localhost', 6379);

if($redis->exists('all_public_tags') == 1){
$result = $redis->get('all_public_tags');
$redis->close();
return $result;
}

else{
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://www.codechef.com/get/tags/problems/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$redis->set('all_public_tags',$result, 3000);
$redis->close();

}

return $result;
}

Loading