mirror of
https://github.com/pierre42100/ComunicAPI
synced 2024-11-23 13:59:29 +00:00
Created account controller
This commit is contained in:
parent
ea5257c478
commit
43ba96ac5e
61
RestControllers/accountController.php
Normal file
61
RestControllers/accountController.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
/**
|
||||
* API Rest controller
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
class accountController {
|
||||
|
||||
/**
|
||||
* Try to connect user and return login tokens
|
||||
*
|
||||
* @url POST /user/connectUSER
|
||||
* @url POST /account/login
|
||||
*/
|
||||
public function connectUSER(){
|
||||
//Check variables sent in request
|
||||
if(!isset($_POST['userMail']) OR !isset($_POST['userPassword']))
|
||||
throw new RestException(400, "Missing data !");
|
||||
|
||||
//Retrieve database connection
|
||||
$db = CS::get()->db;;
|
||||
|
||||
//Extract data
|
||||
$userMail = $_POST["userMail"];
|
||||
$userPassword = $_POST['userPassword'];
|
||||
|
||||
//Try to perform login
|
||||
$loginTokens = CS::get()->components->account->generateUserLoginTokens($userMail, $userPassword, APIServiceID, $db);
|
||||
|
||||
if(count($loginTokens) == 0)
|
||||
throw new RestException(401, "Invalid e-mail address / password !");
|
||||
|
||||
//Return result with tokens
|
||||
return array(
|
||||
"success" => "User logged in !",
|
||||
"tokens" => array(
|
||||
"token1" => $loginTokens[0],
|
||||
"token2" => $loginTokens[1],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request token delete (= disconnectUSER)
|
||||
*
|
||||
* @url POST /user/disconnectUSER
|
||||
* @url POST /account/logout
|
||||
*/
|
||||
public function disconnectUSER(){
|
||||
|
||||
user_login_required();
|
||||
|
||||
//Try to delete token
|
||||
if(!CS::get()->components->account->deleteUserLoginToken(userID, APIServiceID))
|
||||
throw new RestException(500, "Something went wrong while trying to logout user !");
|
||||
|
||||
//Everything is ok
|
||||
return array("success" => "The user has been disconnected !");
|
||||
}
|
||||
}
|
@ -10,55 +10,6 @@ use \Jacwright\RestServer\RestException;
|
||||
|
||||
class userController
|
||||
{
|
||||
/**
|
||||
* Try to connect user and return login tokens
|
||||
*
|
||||
* @url POST /user/connectUSER
|
||||
*/
|
||||
public function connectUSER(){
|
||||
//Check variables sent in request
|
||||
if(!isset($_POST['userMail']) OR !isset($_POST['userPassword']))
|
||||
throw new RestException(400, "Missing data !");
|
||||
|
||||
//Retrieve database connection
|
||||
$db = CS::get()->db;;
|
||||
|
||||
//Extract data
|
||||
$userMail = $_POST["userMail"];
|
||||
$userPassword = $_POST['userPassword'];
|
||||
|
||||
//Try to perform login
|
||||
$loginTokens = CS::get()->components->account->generateUserLoginTokens($userMail, $userPassword, APIServiceID, $db);
|
||||
|
||||
if(count($loginTokens) == 0)
|
||||
throw new RestException(401, "Invalid e-mail address / password !");
|
||||
|
||||
//Return result with tokens
|
||||
return array(
|
||||
"success" => "User logged in !",
|
||||
"tokens" => array(
|
||||
"token1" => $loginTokens[0],
|
||||
"token2" => $loginTokens[1],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Request token delete (= disconnectUSER)
|
||||
*
|
||||
* @url POST /user/disconnectUSER
|
||||
*/
|
||||
public function disconnectUSER(){
|
||||
|
||||
user_login_required();
|
||||
|
||||
//Try to delete token
|
||||
if(!CS::get()->components->account->deleteUserLoginToken(userID, APIServiceID))
|
||||
throw new RestException(500, "Something went wrong while trying to logout user !");
|
||||
|
||||
//Everything is ok
|
||||
return array("success" => "The user has been disconnected !");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get informations about a user
|
||||
|
@ -19,7 +19,6 @@ class User{
|
||||
const USER_PAGE_PUBLIC = 1;
|
||||
const USER_PAGE_OPEN = 2;
|
||||
|
||||
|
||||
/**
|
||||
* Public constructor
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user