mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-27 15:59:29 +00:00
getPrivateConversation fully operationnal
This commit is contained in:
parent
faa59b4fc7
commit
be91602277
@ -167,8 +167,47 @@ class conversationsController{
|
|||||||
user_login_required();
|
user_login_required();
|
||||||
|
|
||||||
//Check for parametres
|
//Check for parametres
|
||||||
if(!isset($_POST['user1']) OR !isset($_POST['user2']))
|
if(!isset($_POST['otherUser']))
|
||||||
Rest_fatal_error(400, "Please check your parametres")
|
Rest_fatal_error(400, "Please check your parametres !");
|
||||||
|
|
||||||
|
//Extract parametres
|
||||||
|
$otherUser = toInt($_POST['otherUser']);
|
||||||
|
if(isset($_POST["allowCreate"]))
|
||||||
|
$allowCreate = $_POST["allowCreate"] == "true" ? true : false;
|
||||||
|
else
|
||||||
|
$allowCreate = false;
|
||||||
|
|
||||||
|
//Check the user exists
|
||||||
|
if(!CS::get()->components->user->exists($otherUser))
|
||||||
|
Rest_fatal_error(400, "Specified user does not exist !");
|
||||||
|
|
||||||
|
//Search the database
|
||||||
|
$results = CS::get()->components->conversations->findPrivate(userID, $otherUser);
|
||||||
|
|
||||||
|
//Count results number
|
||||||
|
if(count($results) === 0) {
|
||||||
|
|
||||||
|
//We check if we are not allowed to create a conversation
|
||||||
|
if(!$allowCreate)
|
||||||
|
Rest_fatal_error(404, "Not any private conversation were found. The server wasn't allowed to create a new one...");
|
||||||
|
|
||||||
|
//Now we can try to create the conversation
|
||||||
|
$ID_owner = userID;
|
||||||
|
$follow = false; //Not following by default
|
||||||
|
$conversationMembers = array(userID, $otherUser);
|
||||||
|
|
||||||
|
//Try to create the conversation
|
||||||
|
$conversationID = CS::get()->components->conversations->create($ID_owner, $follow, $conversationMembers);
|
||||||
|
|
||||||
|
//Check for errors
|
||||||
|
if($conversationID == 0)
|
||||||
|
Rest_fatal_error(500, "Couldn't create the conversation !");
|
||||||
|
|
||||||
|
//Save result
|
||||||
|
$results = array($conversationID);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Success
|
||||||
|
return array("conversationsID" => $results);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -135,7 +135,7 @@ class conversations {
|
|||||||
* @param Mixed $name Optionnal, the name of the conversation
|
* @param Mixed $name Optionnal, the name of the conversation
|
||||||
* @return Integer 0 for a fail else the ID of the newly created conversation
|
* @return Integer 0 for a fail else the ID of the newly created conversation
|
||||||
*/
|
*/
|
||||||
public function create($userID, $follow, array $usersList, $name){
|
public function create($userID, $follow, array $usersList, $name = ""){
|
||||||
|
|
||||||
$mainInformations = array(
|
$mainInformations = array(
|
||||||
"ID_utilisateurs" => $userID*1,
|
"ID_utilisateurs" => $userID*1,
|
||||||
|
@ -32,7 +32,7 @@ class User{
|
|||||||
* @param String $serviceID The ID of the service
|
* @param String $serviceID The ID of the service
|
||||||
* @return String Token if success, false if fails
|
* @return String Token if success, false if fails
|
||||||
*/
|
*/
|
||||||
public function generateUserLoginTokens($email, $password, $serviceID){
|
public function generateUserLoginTokens($email, $password, $serviceID) : array{
|
||||||
//Try to find user ID in the database
|
//Try to find user ID in the database
|
||||||
$conditions = "WHERE mail = ? AND password = ?";
|
$conditions = "WHERE mail = ? AND password = ?";
|
||||||
$values = array(
|
$values = array(
|
||||||
@ -273,6 +273,30 @@ class User{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a user exists or not
|
||||||
|
*
|
||||||
|
* @param Integer $userID The ID of the user to check
|
||||||
|
* @return Boolean Depends of the existence of the user
|
||||||
|
*/
|
||||||
|
public function exists($userID){
|
||||||
|
//Perform a request on the database
|
||||||
|
$tableName = $this->userTable;
|
||||||
|
$condition = "WHERE ID = ?";
|
||||||
|
$condValues = array($userID);
|
||||||
|
$requiredFields = array("ID");
|
||||||
|
|
||||||
|
//Try to perform request
|
||||||
|
$result = CS::get()->db->select($tableName, $condition, $condValues, $requiredFields);
|
||||||
|
|
||||||
|
//Check for errors
|
||||||
|
if($result === false)
|
||||||
|
return false; //An error occured
|
||||||
|
|
||||||
|
//Check and return result
|
||||||
|
return count($result) !== 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crypt user password
|
* Crypt user password
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user