# Users & Registration

On this page you can find all relevant information on how to register new users in FibriCheck.

## Register a new user

Most properties are straightforward, the table below explains the specific requirements for some properties:

| Property          | Values                                                                                                                                                                                                                                                                                                                                          |
| ----------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `gender`          | <p><code>0</code> - Unknown<br><code>1</code> - Male<br><code>2</code> - Female<br><code>9</code> - Not applicable</p>                                                                                                                                                                                                                          |
| `time_zone`       | <p>Examples: <code>Europe/Brussels</code>, <code>GMT+2:00</code>, <code>UTC+3:00</code><br>This string should follow guidelines documented <a href="https://docs.oracle.com/javase/8/docs/api/java/time/ZoneId.html#of-java.lang.String-">here</a>. A full list of string timezone values can be found <a href="broken-reference">here</a>.</p> |
| `country`         | <p><a href="https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2#Officially_assigned_code_elements">ISO 3166 Country Code</a><br>e.g. <code>BE</code>, <code>NL</code>, <code>GB</code>, ...</p>                                                                                                                                                    |
| `birthday`        | <p><code>YYYY-MM-DD</code><br><br>N<em>ote: FibriCheck is only validated for users >= 18 years old. FibriCheck has not been validated for use on minors.</em></p>                                                                                                                                                                               |
| `activation_mode` | Add property and set it to `manual` so avoid activation mails being sent out after account creation.                                                                                                                                                                                                                                            |

{% hint style="warning" %}
In integrations, typically, you don't want to share your user's personal information during account creation. If you're creating an account with an email address that does not exist, make sure to add the `activation_mode` property and set it to `manual` to avoid activation emails being sent. This switch is currently only available for API calls, but will be implemented in the upcoming SDK releases.
{% endhint %}

{% hint style="info" %}
You do not need to be authenticated to register a new user
{% endhint %}

### SDK

The following snippet shows how you can register a new user.&#x20;

{% tabs %}
{% tab title="Flutter" %}

```dart
import 'package:flutter_fibricheck_sdk/flutter_fibricheck_sdk.dart';
import 'package:flutter_fibricheck_sdk/userdata.dart';

_sdk.register(UserRegisterData(
        firstName: "John",
        lastName: "Doe",
        email: "john.doe@example.com",
        password: "Strong!987",
        phoneNumber: "000000",
        birthday: "1990-07-06",
        gender: 0, // 0 = Not known; 1 = Male; 2 = Female; 9 = Not applicable
        country: "JO",
        language: "AR",
        // It has to be a time zone that is compatible w/
        // (https://docs.oracle.com/javase/8/docs/api/java/time/ZoneId.html#of-java.lang.String-)
        // This library will fetch the correct time zones:
        // https://pub.dev/packages/flutter_native_timezone
        // The time zone will be used to render the correct times in the measurement reports
        timeZone: "Europe/Brussels"
      ));
```

{% endtab %}

{% tab title="React Native" %}

```typescript
const user = await sdk.register({
  firstName: 'John',
  lastName: 'Doe',
  email: 'john.doe@example.com',
  password: 'Strong!987',
  phoneNumber: '000000',
  birthday: '1970-01-01',
  gender: 0, // 0 = Not known; 1 = Male; 2 = Female; 9 = Not applicable
  country: 'JO',
  language: 'AR',
  // It has to be a time zone that is compatible w/
  // (https://docs.oracle.com/javase/8/docs/api/java/time/ZoneId.html#of-java.lang.String-)
  // This library will fetch the correct time zones:
  // https://github.com/zoontek/react-native-localize#gettimezone
  // The time zone will be used to render the correct times in the measurement reports
  timeZone: "Europe/Brussels"
});
```

{% endtab %}
{% endtabs %}

### REST API

## Register a new user

<mark style="color:green;">`POST`</mark> `https://api.fibricheck.com/users/v1/register`

#### Request Body

| Name                                             | Type   | Description                                                                  |
| ------------------------------------------------ | ------ | ---------------------------------------------------------------------------- |
| `first_name`<mark style="color:red;">\*</mark>   | String |                                                                              |
| `last_name`<mark style="color:red;">\*</mark>    | String |                                                                              |
| `email`<mark style="color:red;">\*</mark>        | String |                                                                              |
| `password`<mark style="color:red;">\*</mark>     | String |                                                                              |
| `phone_number`<mark style="color:red;">\*</mark> | String |                                                                              |
| `language`<mark style="color:red;">\*</mark>     | String |                                                                              |
| `birthday`                                       | String |                                                                              |
| `gender`                                         | Number |                                                                              |
| `country`                                        | String |                                                                              |
| `region`                                         | String |                                                                              |
| `time_zone`                                      | String |                                                                              |
| `activation_mode`                                | String | Set to `manual` to avoid sending an activation mail (for anonymous accounts) |

{% tabs %}
{% tab title="200: OK User Created" %}

```javascript
{
    "id": "63f4c9d9775136300d3eca86",
    "first_name": "John",
    "last_name": "Doe",
    "language": "NL",
    "time_zone": "Europe/Brussels",
    "email": "john.doe2@example.com",
    "phone_number": "----",
    "activation": false,
    "creation_timestamp": 1676986841185,
    "update_timestamp": 1676986841185
}
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
In partner integrations, registered users will only be visible in the user listing endpoints after they have been added to a partner group through a prescription. See the [prescriptions documentation](https://docs.fibricheck.com/introduction/prescriptions) for more information.
{% endhint %}

{% hint style="info" %}
The password policy indicates that the chosen password is at least 8 characters and needs to have at least a number, a capital letter, and a small letter.
{% endhint %}

## Password Policy

As a password policy, we currently apply the following rules:

```json
{
  "minimum_length": 8,
  "maximum_length": 128,
  "upper_case_required": true,
  "lower_case_required": true,
  "symbol_required": false,
  "number_required": true
}
```

{% hint style="info" %}
**Difference between a registered and activated user**&#x20;

When retrieving the details of a newly registered user, you will notice the `activated` property. A user account is considered activated once they have verified their email by clicking the link sent to them after registration.

Although we encourage users to activate their accounts, the only difference between activated and non-activated accounts is that activated users can perform password resets.
{% endhint %}

## Delete User Data

### REST API

If you want to delete a user using the REST API, you need to know the **internal FibriCheck** `userId` of the user you want to delete. The `userId` is available in response of the `/tokens` endpoint after a successful authentication attempt. Note that you can only remove users that you are entitled to remove.

In the body of the API call you can provide the targeted user id in the `targetUserId` field.&#x20;

{% hint style="warning" %}
Please don't forget to include this field, else the authenticated user, often an admin user, will be deleted!
{% endhint %}

In addition, you can optionally  add a `reasonType` and `reasonDescription`. The description is a free text input, for the `reasonType` you can choose between:&#x20;

```
"too_expensive",
"too_complicated",
"technical_issues",
"switched_to_different_app",
"no_health_issues_found",
"treated_by_physician",
"physician_recommended_different_app",
"privacy_concerns",
"too_much_spam",
"other"
```

## Delete User Profile

<mark style="color:green;">`POST`</mark> `https://api.fibricheck.com/data/v1/user-deletion-requests/documents`

#### Request Body

| Name              | Type   | Description                      |
| ----------------- | ------ | -------------------------------- |
| targetUserId      | String | userId of the profile to remove  |
| reasonType        | String | reason for removal               |
| reasonDescription | String | extra context for removal reason |

{% tabs %}
{% tab title="200: OK " %}

{% endtab %}
{% endtabs %}
