Authentication

POST /api/auth/register

register a user

Example request:

POST /auth/register HTTP/1.1
Content-Type: application/json

Example responses:

  • successful registration

HTTP/1.1 201 CREATED
Content-Type: application/json

{
  "auth_token": "JSON Web Token",
  "message": "Successfully registered.",
  "status": "success"
}
  • error on registration

HTTP/1.1 400 BAD REQUEST
Content-Type: application/json

{
  "message": "Errors: Valid email must be provided.\n",
  "status": "error"
}
Request JSON Object
  • username (string) – user name (3 to 12 characters required)

  • email (string) – user email

  • password (string) – password (8 characters required)

  • password_conf (string) – password confirmation

Status Codes
  • 201 Created – Successfully registered.

  • 400 Bad Request

    • Invalid payload.

    • Sorry. That user already exists.

    • Errors:
      • Username: 3 to 12 characters required.

      • Valid email must be provided.

      • Password and password confirmation don’t match.

      • Password: 8 characters required.

  • 500 Internal Server Error – Error. Please try again or contact the administrator.

POST /api/auth/login

user login

Example request:

POST /auth/login HTTP/1.1
Content-Type: application/json

Example responses:

  • successful login

HTTP/1.1 200 OK
Content-Type: application/json

{
  "auth_token": "JSON Web Token",
  "message": "Successfully logged in.",
  "status": "success"
}
  • error on login

HTTP/1.1 404 NOT FOUND
Content-Type: application/json

{
  "message": "Invalid credentials.",
  "status": "error"
}
Request JSON Object
  • email (string) – user email

  • password_conf (string) – password confirmation

Status Codes
GET /api/auth/logout

user logout

Example request:

GET /auth/logout HTTP/1.1
Content-Type: application/json

Example responses:

  • successful logout

HTTP/1.1 200 OK
Content-Type: application/json

{
  "message": "Successfully logged out.",
  "status": "success"
}
  • error on login

HTTP/1.1 401 UNAUTHORIZED
Content-Type: application/json

{
  "message": "Provide a valid auth token.",
  "status": "error"
}
Request Headers
Status Codes
GET /api/auth/profile

get authenticated user info

Example request:

GET /auth/profile HTTP/1.1
Content-Type: application/json

Example response:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "data": {
    "admin": false,
    "bio": null,
    "birth_date": null,
    "created_at": "Sun, 14 Jul 2019 14:09:58 GMT",
    "email": "admin@example.com",
    "first_name": null,
    "id": 2,
    "last_name": null,
    "location": null,
    "nb_activities": 6,
    "nb_sports": 3,
    "picture": false,
    "timezone": "Europe/Paris",
    "total_distance": 67.895,
    "total_duration": "6:50:27",
    "username": "sam"
  },
  "status": "success"
}
Request Headers
Status Codes
POST /api/auth/profile/edit

edit authenticated user

Example request:

POST /auth/profile/edit HTTP/1.1
Content-Type: application/json

Example response:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "data": {
    "admin": false,
    "bio": null,
    "birth_date": null,
    "created_at": "Sun, 14 Jul 2019 14:09:58 GMT",
    "email": "admin@example.com",
    "first_name": null,
    "id": 2,
    "last_name": null,
    "location": null,
    "nb_activities": 6,
    "nb_sports": 3,
    "picture": false,
    "timezone": "Europe/Paris",
    "total_distance": 67.895,
    "total_duration": "6:50:27",
    "username": "sam"
  },
  "status": "success"
}
Request JSON Object
  • first_name (string) – user first name

  • last_name (string) – user last name

  • location (string) – user location

  • bio (string) – user biography

  • birth_date (string) – user birth date (format: %Y-%m-%d)

  • password (string) – user password

  • password_conf (string) – user password confirmation

  • timezone (string) – user time zone

Request Headers
Status Codes
POST /api/auth/picture

update authenticated user picture

Example request:

POST /auth/picture HTTP/1.1
Content-Type: multipart/form-data

Example response:

HTTP/1.1 200 OK
Content-Type: application/json

{
  "data": {
    "admin": false,
    "bio": null,
    "birth_date": null,
    "created_at": "Sun, 14 Jul 2019 14:09:58 GMT",
    "email": "admin@example.com",
    "first_name": null,
    "id": 2,
    "last_name": null,
    "location": null,
    "nb_activities": 6,
    "nb_sports": 3,
    "picture": false,
    "timezone": "Europe/Paris",
    "total_distance": 67.895,
    "total_duration": "6:50:27",
    "username": "sam"
  },
  "status": "success"
}
Form Parameters
  • file – image file (allowed extensions: .jpg, .png, .gif)

Request Headers
Status Codes
DELETE /api/auth/picture

delete authenticated user picture

Example request:

DELETE /auth/picture HTTP/1.1
Content-Type: application/json

Example response:

HTTP/1.1 204 NO CONTENT
Content-Type: application/json
Request Headers
Status Codes