Skip to content

Commit

Permalink
update lib
Browse files Browse the repository at this point in the history
  • Loading branch information
kien9977 committed May 18, 2022
1 parent a06ab3d commit c21b1a3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/sql_manipulate.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,11 @@ function insert_user_token($conn, $app_id, $user_id) {
return "";
}


function write_user_data($conn, $app_id, $user_id, $secret) {
$stmt = mysqli_prepare($conn, "INSERT INTO user(app_id, user_id, secret, created_at) VALUES (?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, "ssss", $app_id, $user_id, $secret, time());
$res = mysqli_stmt_execute($stmt);

return $res;
}
?>
3 changes: 3 additions & 0 deletions lib/status_code_description.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ function status_code_description($code) {
else if($code == 433) {
return "[opcode] not valid, please read the documents carefully and then try again";
}
else if($code == 434) {
return "[user_id] existed";
}
else if($code == 512) {
return "SQL server(s) caused an error";
}
Expand Down
13 changes: 13 additions & 0 deletions lib/validate.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,17 @@ function check_app_exist($conn, $app_id) {
return false;
}
}

function check_user_exists($conn, $app_id, $user_id) {
$stmt = mysqli_prepare($conn, "SELECT count(*) as count FROM user WHERE app_id = ? AND user_id = ?");
mysqli_stmt_bind_param($stmt, "ss", $app_id, $user_id);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt, $count);
mysqli_stmt_fetch($stmt);

if($count == 0) {
return false;
}
return true;
}
?>

0 comments on commit c21b1a3

Please sign in to comment.