The Accounts Service is a microservice for managing user accounts, including registration, login, password reset, and role/plan assignment. It is built using the Moleculer framework and includes various features to handle user authentication and authorization.
- User Registration: Allows users to register with an email, password, and username.
- User Login: Authenticates users and provides a JWT token for session management.
- Email Verification: Sends verification emails to users and verifies their email addresses.
- Password Reset: Sends password reset emails and allows users to reset their passwords.
- Role Management: Assigns and revokes roles for users.
- Plan Management: Assigns plans to users.
- Account Status: Manages account statuses such as active, inactive, banned, deleted, and pending.
- Login Attempts: Tracks login attempts and implements a delay after multiple failed attempts.
The service provides the following actions:
This actions registers a new user with the provided email, password, and username.
Property | Type | Default | Description |
---|---|---|---|
username |
string |
null |
The username of the user. |
email |
string |
null |
The email of the user. |
password |
string |
null |
The password of the user. |
POST /{serviceName}/register
{
"username": "myusername",
"email": "[email protected]",
"password": "myPassword123"
}
{
"id": "akTRSKTKzGCg9EMz",
"username": "myusername",
"email": "[email protected]",
"password": "myPassword123",
"createdAt": "2023-07-05T13:45:32.123Z",
}
const user = await this.call("v1.accounts.register", {
username: "myusername",
email: "[email protected]",
password: "myPassword123"
});
This action logs in a user with the provided email and password.
Property | Type | Default | Description |
---|---|---|---|
email |
string |
null |
The email of the user. |
password |
string |
null |
The password of the user. |
POST /{serviceName}/login
{
"email": "[email protected]",
"password": "myPassword123"
}
{
"user": {
"id": "akTRSKTKzGCg9EMz",
"username": "myusername",
"email": "[email protected]",
// ...other user fields...
},
"token": "jwt-token"
}
This action verifies a user's email with the provided token.
Property | Type | Default | Description |
---|---|---|---|
token |
string |
null |
The verification token. |
POST /{serviceName}/verify-email
{
"token": "verification-token"
}
{
"id": "akTRSKTKzGCg9EMz",
"username": "myusername",
"email": "[email protected]",
"verified": true,
// ...other user fields...
}
This action sends a password reset email to the user.
Property | Type | Default | Description |
---|---|---|---|
email |
string |
null |
The email of the user. |
POST /{serviceName}/reset-password
{
"email": "[email protected]"
}
{
"id": "akTRSKTKzGCg9EMz",
"username": "myusername",
"email": "[email protected]",
// ...other user fields...
}
This action sends a reset password email to the user.
Property | Type | Default | Description |
---|---|---|---|
id |
string |
null |
The ID of the user. |
token |
string |
null |
The reset password token. |
{
"id": "akTRSKTKzGCg9EMz",
"username": "myusername",
"email": "[email protected]",
// ...other user fields...
}
This action sends a verification email to the user.
Property | Type | Default | Description |
---|---|---|---|
id |
string |
null |
The ID of the user. |
{
"id": "akTRSKTKzGCg9EMz",
"username": "myusername",
"email": "[email protected]",
// ...other user fields...
}
This action assigns a plan to the user.
Property | Type | Default | Description |
---|---|---|---|
id |
string |
null |
The ID of the user. |
plan |
string |
null |
The ID of the plan. |
POST /{serviceName}/:id/plans
{
"plan": "plan-id"
}
{
"id": "akTRSKTKzGCg9EMz",
"username": "myusername",
"email": "[email protected]",
"plan": "plan-id",
// ...other user fields...
}
This action assigns a role to the user.
Property | Type | Default | Description |
---|---|---|---|
id |
string |
null |
The ID of the user. |
role |
string |
null |
The name of the role. |
POST /{serviceName}/:id/roles
{
"role": "role-name"
}
{
"id": "akTRSKTKzGCg9EMz",
"username": "myusername",
"email": "[email protected]",
"roles": ["role-name"],
// ...other user fields...
}
This action revokes a role from the user.
Property | Type | Default | Description |
---|---|---|---|
id |
string |
null |
The ID of the user. |
role |
string |
null |
The name of the role. |
DELETE /{serviceName}/:id/roles/:role
{
"id": "akTRSKTKzGCg9EMz",
"username": "myusername",
"email": "[email protected]",
"roles": [],
// ...other user fields...
}