---
description: User accounts API
---

# Accounts

## Register new user

<mark style="color:green;">`POST`</mark> `https://muni-portal-backend.openup.org.za/api/accounts/register/`

Register new user

#### Request Body

| Name              | Type   | Description                          |
| ----------------- | ------ | ------------------------------------ |
| password\_confirm | string | Password confirm                     |
| password          | string | User password                        |
| username          | string | User name (can be the same as email) |
| email             | string | User email                           |

{% tabs %}
{% tab title="201 New user created" %}
```
{}
```
{% endtab %}

{% tab title="400 Validation errors" %}
```
{"field_name": "Error description"}
```
{% endtab %}
{% endtabs %}

## Verify registration

<mark style="color:green;">`POST`</mark> `https://muni-portal-backend.openup.org.za/api/accounts/verify-registration/`

Verify user email from the verification link

#### Request Body

| Name      | Type    | Description                 |
| --------- | ------- | --------------------------- |
| user\_id  | string  | Django model user ID        |
| signature | string  | HMAC verification signature |
| timestamp | integer | User registration timestamp |

{% tabs %}
{% tab title="200 User account verified" %}
```
{}
```
{% endtab %}
{% endtabs %}

## Retrieve reset password link

<mark style="color:green;">`POST`</mark> `https://muni-portal-backend.openup.org.za/api/accounts/send-reset-password-link/`

Send reset password link to the user by email

#### Request Body

| Name  | Type   | Description |
| ----- | ------ | ----------- |
| email | string | User email  |

{% tabs %}
{% tab title="200 Reset password link was sent" %}
```
{}
```
{% endtab %}

{% tab title="404 User not found" %}
```
{}
```
{% endtab %}
{% endtabs %}

## Set new user password

<mark style="color:green;">`POST`</mark> `https://muni-portal-backend.openup.org.za/api/accounts/reset-password/`

Set new user password from the reset link

#### Request Body

| Name      | Type    | Description                      |
| --------- | ------- | -------------------------------- |
| password  | string  | New user password                |
| signature | string  | HMAC verification signature      |
| timestamp | integer | Reset password request timestamp |
| user\_id  | string  | Django model user ID             |

{% tabs %}
{% tab title="200 " %}
```
{}
```
{% endtab %}

{% tab title="400 " %}
```
{"field_name": "Error description"}
```
{% endtab %}
{% endtabs %}

## Login user

<mark style="color:green;">`POST`</mark> `https://muni-portal-backend.openup.org.za/api/account/login/`

Login user with username and password

#### Request Body

| Name     | Type   | Description   |
| -------- | ------ | ------------- |
| password | string | User password |
| login    | string | User name     |

{% tabs %}
{% tab title="200 " %}
```
{"token": "JWT.TOKEN"}
```
{% endtab %}

{% tab title="400 Username or password are invalid" %}
```
```
{% endtab %}
{% endtabs %}

## Logout user

<mark style="color:green;">`POST`</mark> `https://muni-portal-backend.openup.org.za/api/accounts/logout/`

Logout user from the system

#### Path Parameters

| Name          | Type    | Description          |
| ------------- | ------- | -------------------- |
| revoke\_token | boolean | Revoke current token |

#### Headers

| Name                | Type   | Description      |
| ------------------- | ------ | ---------------- |
| HTTP\_AUTHORIZATION | string | Bearer JWT.TOKEN |

{% tabs %}
{% tab title="200 " %}
```
{}
```
{% endtab %}
{% endtabs %}

## Get user profile info

<mark style="color:blue;">`GET`</mark> `https://muni-portal-backend.openup.org.za/api/accounts/profile/`

#### Headers

| Name                | Type   | Description      |
| ------------------- | ------ | ---------------- |
| HTTP\_AUTHORIZATION | string | Bearer JWT.TOKEN |

{% tabs %}
{% tab title="200 Return user information" %}
```
{
    "id": 1,
    "username": "test", 
    "first_name": "",
    "last_name": "", 
    "email": "test@test.com"
}
```
{% endtab %}

{% tab title="401 JWT token is invalid" %}
```
```
{% endtab %}
{% endtabs %}

## Update user profile info

<mark style="color:green;">`POST`</mark> `https://muni-portal-backend.openup.org.za/api/accounts/profile/`

#### Headers

| Name                | Type   | Description      |
| ------------------- | ------ | ---------------- |
| HTTP\_AUTHORIZATION | string | Bearer JWT.TOKEN |

#### Request Body

| Name        | Type   | Description         |
| ----------- | ------ | ------------------- |
| email       | string | Email to change     |
| Last name   | string | Lastname to change  |
| first\_name | string | Firstname to change |
| username    | string | Username to change  |

{% tabs %}
{% tab title="200 Return updated information" %}
```
{
    "id": 1,
    "username": "test", 
    "first_name": "",
    "last_name": "", 
    "email": "test@test.com"
}
```
{% endtab %}

{% tab title="401 JWT token is invalid" %}
```
```
{% endtab %}
{% endtabs %}

## Change user password

<mark style="color:green;">`POST`</mark> `https://muni-portal-backend.openup.org.za/api/accounts/change-password/`

#### Headers

| Name                | Type   | Description      |
| ------------------- | ------ | ---------------- |
| HTTP\_AUTHORIZATION | string | Bearer JWT.TOKEN |

#### Request Body

| Name              | Type   | Description                       |
| ----------------- | ------ | --------------------------------- |
| password\_confirm | string | New password confirmation         |
| password          | string | New password                      |
| old\_password     | string | Old password for security reasons |

{% tabs %}
{% tab title="200 " %}
```
{}
```
{% endtab %}
{% endtabs %}

## Update user email

<mark style="color:green;">`POST`</mark> `https://muni-portal-backend.openup.org.za/api/accounts/register-email/`

Send a verification link to a user new email

#### Headers

| Name                | Type   | Description      |
| ------------------- | ------ | ---------------- |
| HTTP\_AUTHORIZATION | string | Bearer JWT.TOKEN |

#### Request Body

| Name  | Type   | Description    |
| ----- | ------ | -------------- |
| email | string | New user email |

{% tabs %}
{% tab title="200 " %}
```
{}
```
{% endtab %}
{% endtabs %}

## Verify new user email

<mark style="color:green;">`POST`</mark> `https://muni-portal-backend.openup.org.za/api/account/verify-email/`

Verify new user email from verification link

#### Headers

| Name                | Type   | Description      |
| ------------------- | ------ | ---------------- |
| HTTP\_AUTHORIZATION | string | Bearer JWT.TOKEN |

#### Request Body

| Name      | Type   | Description                                |
| --------- | ------ | ------------------------------------------ |
| signature | string | HMAC request signature                     |
| timestam  | string | Timestamp when user requested email change |
| email     | string | New user email                             |
| user\_id  | string | Django model user ID                       |

{% tabs %}
{% tab title="200 New user email was set" %}
```
{}
```
{% endtab %}
{% endtabs %}

### User registration and verification

![](https://3781560293-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MJMOjRvhmSwc5da9Djd%2F-MMnfHOq-7YfuBz8fZxp%2F-MMoZ-4aVQPVC3IQMYNe%2FJWT%20auth.jpeg?alt=media\&token=59098735-42ce-45cd-8ef6-dd1092c80278)

### User login

![](https://3781560293-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MJMOjRvhmSwc5da9Djd%2F-MMpUU08qk2-DaxoK0u9%2F-MMpUd329yhKqLWhpcwt%2FJWT%20login.png?alt=media\&token=e0047258-cc7f-4c42-ad2e-3a1a0b0147f9)
