项目作者: ambersariya

项目描述 :
Event Sourcing Example using Prooph library
高级语言: PHP
项目地址: git://github.com/ambersariya/users-service-prooph.git
创建时间: 2018-06-01T15:56:46Z
项目社区:https://github.com/ambersariya/users-service-prooph

开源协议:

下载


Event Sourcing User Management App

A small application implementing Event Sourcing using Prooph components.

Start

  1. # Bash
  2. $ git clone git@github.com:ambersariya/users-service-prooph.git
  3. # Bash on Linux/Mac
  4. $ docker run --rm -it --volume $(pwd):/app prooph/composer:7.2 install
  5. # Fish shell
  6. $ docker run --rm -it --volume (pwd):/app prooph/composer:7.2 install
  7. # Git Bash on Windows
  8. $ docker run --rm -it -v "%cd%":/app prooph/composer:7.2 install
  9. $ docker-compose up -d
  10. $ docker-compose exec php sh
  11. $ docker-compose exec php bin/console event-store:event-stream:create
  12. $ docker-compose exec php bin/console doctrine:migrations:migrate --no-interaction

Enable JWT

  1. # The following will grab passphrase from our .env variable
  2. $ docker-compose exec php mkdir -p config/jwt
  3. $ docker-compose exec php openssl genrsa -passout env:JWT_PASSPHRASE -out config/jwt/private.pem -aes256 4096
  4. $ docker-compose exec php openssl rsa -pubout -in config/jwt/private.pem -out config/jwt/public.pem -passin env:JWT_PASSPHRASE

Create User (Cli)

  1. docker-compose exec php bin/console app:sign-up

Register

  1. $ curl -X POST \
  2. http://[HOST NAME HERE]/register \
  3. -H 'Content-Type: application/json' \
  4. -d '{
  5. "first_name": "John",
  6. "last_name": "Doe",
  7. "email": "johndoe@example.org",
  8. "password": "testpass",
  9. "id": "fd9999ff-0f13-4c52-a973-915217d591d1"
  10. }'
  11. -> 201 Created

Login

  1. curl -X POST \
  2. http://[HOST NAME HERE]/login_check \
  3. -H 'Cache-Control: no-cache' \
  4. -H 'Content-Type: application/json' \
  5. -d '{
  6. "username": "johndoe@example.org",
  7. "password": "testpass"
  8. }'
  9. -> Response: 200
  10. Body: {"token": "[JWT TOKEN]"}

Access protected route:

  1. $ curl -H "Authorization: Bearer [TOKEN]" http://[HOST NAME HERE]/api/me
  2. -> {
  3. "id": "fd9999ff-0f13-4c52-a973-915217d591d1",
  4. "first_name": "John",
  5. "last_name": "Doe",
  6. "email": "johndoe@example.org",
  7. "created_at": "2018-06-12T11:55:36+00:00",
  8. "updated_at": "2018-06-12T11:55:36+00:00",
  9. "_links": {
  10. "self": {
  11. "href": "/api/users/fd9999ff-0f13-4c52-a973-915217d591d1"
  12. }
  13. }
  14. }