User registration REST endpoint - Yanko Rashkov
Create User registration REST endpoint using Python and Django framework.
MUST have:
- API URL /api/register, HTTP method POST
- In case of success HTTP response code MUST be 201
- langKey can take one of values: en, bg, fr, de
- Password hash using bcrypt or other encryption algorithm producing 60 characters.
- Password MUST has minimum 8 characters.
- Field "activated" MUST be set to false.
- Column created_by to be set to anonymous or currently logged user.
- Column created_date to be set to current time when record is created.
- Column activation_key to be set to random unique value.
- Email MUST be sent to the provided email address
- Email template subject: {application_name} account activation
- Email template body:
Dear {login}
Your {application_name} account has been created, please click on the URL below to activate it:
{server_url}/account/activate?key={activation_key}
Regards,
{application_name} Team.
- JSON Request message structure:
{
"login": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"imageUrl": "string",
"langKey": "en/bg",
"password": "string"
}
- JSON Response:
{
"id": long,
"login": "string",
"firstName": "string",
"lastName": "string",
"email": "string",
"imageUrl": "string",
"langKey": "string",
"activated": false,
"createdBy": "string",
"createdDate": "2023-11-02T06:42:50.339207Z",
"lastModifiedBy": "string",
"lastModifiedDate": "2023-11-02T06:43:38.517781Z",
"authorities": [
"ROLE_USER"
]
}
Example JSON Request:
{
"login": "trifont+113@gmail.com",
"firstName": "Trifon",
"lastName": "Trifonov",
"email": "trifont+113@gmail.com",
"imageUrl": "https://server/path/image.png",
"langKey": "en",
"password": "my-password"
}
HTTP response code: 201 and JSON message:
{
"id": 1253,
"login": "trifont+113@gmail.com",
"firstName": "Trifon",
"lastName": "Trifonov",
"email": "trifont+113@gmail.com",
"imageUrl": "https://server/path/image.png",
"langKey": "en",
"activated": false,
"createdBy": "anonymousUser",
"createdDate": "2023-11-02T06:42:50.339207Z",
"lastModifiedBy": "anonymousUser",
"lastModifiedDate": "2023-11-02T06:43:38.517781Z",
"authorities": [
"ROLE_USER"
]
}
Database table structure:
CREATE TABLE jhi_user (
id BIGINT PRIMARY KEY NOT NULL,
login VARCHAR(50) NOT NULL UNIQUE,
password_hash VARCHAR(60),
first_name VARCHAR(50),
last_name VARCHAR(50),
email VARCHAR(191) UNIQUE,
image_url VARCHAR(256),
activated BOOLEAN DEFAULT FALSE NOT NULL,
lang_key VARCHAR(10),
activation_key VARCHAR(20),
reset_key VARCHAR(20),
reset_date TIMESTAMP,
created_by VARCHAR(50) NOT NULL,
created_date TIMESTAMP,
last_modified_by VARCHAR(50),
last_modified_date TIMESTAMP
);
Edited by Trifon Trifonov