Skip to content

Commit

Permalink
added new functions
Browse files Browse the repository at this point in the history
  • Loading branch information
xrowkristina committed Jun 30, 2015
1 parent 8bfa2bc commit 8ac1114
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 31 deletions.
4 changes: 4 additions & 0 deletions CRM/CRMPluginInterface.php
Expand Up @@ -12,5 +12,9 @@ public function getAccount($user);

public function getSubscriptions($user);

public function checkPassword($loginData);

public function updateUser($user, $newData);

public function getSubscription($user, $subscriptionId);
}
74 changes: 72 additions & 2 deletions Controller/ApiController.php
Expand Up @@ -2,6 +2,9 @@

namespace xrow\restBundle\Controller;

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -12,14 +15,21 @@
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
use Symfony\Component\DependencyInjection\ContainerInterface;

use FOS\OAuthServerBundle\Security\Authentication\Token\OAuthToken;
use FOS\OAuthServerBundle\Model\AccessTokenInterface;

use OAuth2\OAuth2;
use OAuth2\OAuth2AuthenticateException;

use xrow\restBundle\CRM\LoadCRMPlugin;
use xrow\restBundle\Entity\User as APIUser;

use eZ\Publish\Core\MVC\Symfony\Event\InteractiveLoginEvent;

/**
* @Route("/xrowapi/v1")
*/
class ApiController extends Controller
{
/**
Expand Down Expand Up @@ -63,7 +73,9 @@ public function __construct(LoadCRMPlugin $loadCRMPlugin, SecurityContextInterfa
}

/**
*
* @Route("/auth")
* @Method({"GET", "POST"})
*
* @param Request $request
* @throws AccessDeniedException
*/
Expand Down Expand Up @@ -148,6 +160,8 @@ function () use ( $currentEzUser )
}

/**
* @Route("/user")
* @Method({"GET", "PATCH"})
*
* @param Request $request
* @throws AccessDeniedException
Expand All @@ -163,7 +177,13 @@ public function getUserAction(Request $request)
'error_type' => 'NOUSER',
'error_description' => 'This user does not have access to this section.'), 403);
}
$CRMUser = $this->crmPluginClassObject->getUser($user);
$httpMethod = $request->getMethod();
if ($httpMethod == 'GET') {
$CRMUser = $this->crmPluginClassObject->getUser($user);
}
elseif ($httpMethod == 'PATCH') {
$CRMUser = $this->crmPluginClassObject->updateUser($user, $request);
}
if($CRMUser) {
return new JsonResponse(array(
'result' => $CRMUser,
Expand All @@ -184,6 +204,8 @@ public function getUserAction(Request $request)
}

/**
* @Route("/account")
* @Method({"GET"})
*
* @param Request $request
* @return \Symfony\Component\HttpFoundation\JsonResponse
Expand Down Expand Up @@ -219,6 +241,8 @@ public function getAccountAction(Request $request)
}

/**
* @Route("/subscriptions")
* @Method({"GET"})
*
* @param Request $request
* @throws AccessDeniedException
Expand Down Expand Up @@ -255,6 +279,52 @@ public function getSubscriptionsAction(Request $request)
}

/**
* @Route("/chekpassword")
* @Method({"GET"})
*
* @param Request $request
* @throws AccessDeniedException
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
public function checkPasswordAction(Request $request)
{
try {
$user = $this->checkAccessGranted($request);
if (!$user instanceof APIUser) {
return new JsonResponse(array(
'error' => 'invalid_grant',
'error_type' => 'NOUSER',
'error_description' => 'This user does not have access to this section.'), 403);
}
$username = $request->get('username', null);
$password = $request->get('password', null);
if ($username !== null && $password !== null) {
$loginData = array('username' => $username,
'password' => $password);
$return = $this->crmPluginClassObject->checkPassword($loginData);
if($this->crmPluginClassObject->checkPassword($loginData) === true) {
return new JsonResponse(array(
'result' => true,
'type' => 'CONTENT',
'message' => 'User data'));
}
}
return new JsonResponse(array(
'result' => null,
'type' => 'NOCONTENT',
'message' => 'User not found'), 204);
} catch (AuthenticationException $e) {
$exception = $this->errorHandling($e);
return new JsonResponse(array(
'error' => $exception['error'],
'error_type' => $exception['type'],
'error_description' => $exception['error_description']), $exception['httpCode']);
}
}

/**
* @Route("/logout")
* @Method({"GET"})
*
* @return \Symfony\Component\HttpFoundation\JsonResponse
*/
Expand Down
29 changes: 0 additions & 29 deletions Resources/config/routing.yml

This file was deleted.

0 comments on commit 8ac1114

Please sign in to comment.