diff --git a/app/library/App/Controllers/UserController.php b/app/library/App/Controllers/UserController.php index 164eb31..47794a6 100755 --- a/app/library/App/Controllers/UserController.php +++ b/app/library/App/Controllers/UserController.php @@ -17,12 +17,12 @@ class UserController extends CrudResourceController ]; } - public function me() + public function meAction() { return $this->createResourceResponse($this->userService->getDetails()); } - public function authenticate() + public function authenticateAction() { $username = $this->request->getUsername(); $password = $this->request->getPassword(); @@ -44,7 +44,7 @@ class UserController extends CrudResourceController return $this->createArrayResponse($response, 'data'); } - public function register() { + public function registerAction() { $this->beforeHandle(); $this->beforeHandleWrite(); diff --git a/app/library/App/Resources/UserResource.php b/app/library/App/Resources/UserResource.php index 50aea41..58376e5 100755 --- a/app/library/App/Resources/UserResource.php +++ b/app/library/App/Resources/UserResource.php @@ -2,6 +2,7 @@ namespace App\Resources; +use PhalconApi\Constants\HttpMethods; use PhalconRest\Api\ApiResource; use PhalconRest\Api\ApiEndpoint; use App\Model\User; @@ -18,44 +19,74 @@ class UserResource extends ApiResource { ->model(User::class) ->expectsJsonData() ->transformer(UserTransformer::class) - ->handler(UserController::class) ->itemKey('user') ->collectionKey('users') ->deny(AclRoles::UNAUTHORIZED, AclRoles::USER) + ->handler(UserController::class); + $this ->endpoint(ApiEndpoint::all() ->allow(AclRoles::USER) - ->description('Returns all registered users') - ) - ->endpoint(ApiEndpoint::get('/me', 'me') + ->name('all') + ->description('Возвращает всех зарегистрированных пользователей') + ); + $this + ->endpoint(ApiEndpoint::factory('/me', HttpMethods::GET, 'meAction') + ->name('me') + ->description('Возвращает текущего залогиненного пользователя') ->allow(AclRoles::USER) - ->description('Returns the currently logged in user') - ) - ->endpoint(ApiEndpoint::post('/authenticate', 'authenticate') + ); + + $this + ->endpoint(ApiEndpoint::factory('/authenticate', HttpMethods::POST, 'authenticateAction') + ->name('authenticate') + ->description('Авторизация пользователя через BasicAuth и возвращает токен доступа') ->allow(AclRoles::UNAUTHORIZED) ->deny(AclRoles::AUTHORIZED) - ->description('Authenticates user credentials provided in the authorization header and returns an access token') ->exampleResponse([ - 'token' => 'co126bbm40wqp41i3bo7pj1gfsvt9lp6', - 'expires' => 1451139067 + 'data' => [ + 'token' => 'co126bbm40wqp41i3bo7pj1gfsvt9lp6', + 'expires' => 1451139067, + "user" => + [ + "id" => 1, + "username" => "demo", + "email" => "test@example.com", + "role" => "User", + "createdAt" => "2015-12-28 16:20:58", + "updatedAt" => null + ] + ] + ]) - ) - ->endpoint(ApiEndpoint::post('/', 'register') + ); + $this + ->endpoint(ApiEndpoint::factory('/', HttpMethods::POST, 'registerAction') + ->name('register') + ->description('Регистрация нового пользователя') ->allow(AclRoles::UNAUTHORIZED) ->deny(AclRoles::AUTHORIZED) - ->description('Register new user') - ->expectsJsonData() ->exampleResponse([ - "result" => "OK", - "user" => [ - "id" => "95", - "username" => "MyLogin", - "email" => "myGmail@gmail.com", - "role" => "User", - "createdAt" => "2017-02-16 17:57:52", - "updatedAt" => "2017-02-16 17:57:52" - ] + "result" => "OK", + "user" => [ + "id" => "95", + "username" => "MyLogin", + "email" => "myGmail@gmail.com", + "role" => "User", + "createdAt" => "2017-02-16 17:57:52", + "updatedAt" => "2017-02-16 17:57:52" + ] ]) ); + $this + ->endpoint(ApiEndpoint::remove() + ->name('remove') + ->description('Удаление пользователя') + ->allow(AclRoles::USER) + ->exampleResponse([ + "result" => "OK" + ]) + ) + ; } } \ No newline at end of file diff --git a/public/js/angular-sanitize.min.js b/public/js/angular-sanitize.min.js new file mode 100644 index 0000000..cd8bfc1 --- /dev/null +++ b/public/js/angular-sanitize.min.js @@ -0,0 +1,3 @@ +/** + * Created by User on 14.03.2017. + */ diff --git a/public/js/angular.min.js b/public/js/angular.min.js new file mode 100644 index 0000000..cd8bfc1 --- /dev/null +++ b/public/js/angular.min.js @@ -0,0 +1,3 @@ +/** + * Created by User on 14.03.2017. + */ diff --git a/public/js/bootstrap.min.js b/public/js/bootstrap.min.js new file mode 100644 index 0000000..cd8bfc1 --- /dev/null +++ b/public/js/bootstrap.min.js @@ -0,0 +1,3 @@ +/** + * Created by User on 14.03.2017. + */ diff --git a/public/js/jquery.min.js b/public/js/jquery.min.js new file mode 100644 index 0000000..cd8bfc1 --- /dev/null +++ b/public/js/jquery.min.js @@ -0,0 +1,3 @@ +/** + * Created by User on 14.03.2017. + */ -- libgit2 0.21.4