Skip to content

FLYBYME/accounts-services

Repository files navigation

Moleculer

Accounts Service

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.

Features

  • 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.

Usage

Actions

The service provides the following actions:

register Register a new user

This actions registers a new user with the provided email, password, and username.

Parameters

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.

REST endpoint

POST /{serviceName}/register

Request Body

{
    "username": "myusername",
    "email": "[email protected]",
    "password": "myPassword123"
}

Results

{
    "id": "akTRSKTKzGCg9EMz",
    "username": "myusername",
    "email": "[email protected]",
    "password": "myPassword123",
    "createdAt": "2023-07-05T13:45:32.123Z",
}

Examples

Register a new user

const user = await this.call("v1.accounts.register", {
    username: "myusername",
    email: "[email protected]",
    password: "myPassword123"
});

login Login a user

This action logs in a user with the provided email and password.

Parameters

Property Type Default Description
email string null The email of the user.
password string null The password of the user.

REST endpoint

POST /{serviceName}/login

Request Body

{
    "email": "[email protected]",
    "password": "myPassword123"
}

Results

{
    "user": {
        "id": "akTRSKTKzGCg9EMz",
        "username": "myusername",
        "email": "[email protected]",
        // ...other user fields...
    },
    "token": "jwt-token"
}

verifyEmail Verify email

This action verifies a user's email with the provided token.

Parameters

Property Type Default Description
token string null The verification token.

REST endpoint

POST /{serviceName}/verify-email

Request Body

{
    "token": "verification-token"
}

Results

{
    "id": "akTRSKTKzGCg9EMz",
    "username": "myusername",
    "email": "[email protected]",
    "verified": true,
    // ...other user fields...
}

resetPassword Reset password

This action sends a password reset email to the user.

Parameters

Property Type Default Description
email string null The email of the user.

REST endpoint

POST /{serviceName}/reset-password

Request Body

{
    "email": "[email protected]"
}

Results

{
    "id": "akTRSKTKzGCg9EMz",
    "username": "myusername",
    "email": "[email protected]",
    // ...other user fields...
}

sendResetPasswordEmail Send reset password email

This action sends a reset password email to the user.

Parameters

Property Type Default Description
id string null The ID of the user.
token string null The reset password token.

Results

{
    "id": "akTRSKTKzGCg9EMz",
    "username": "myusername",
    "email": "[email protected]",
    // ...other user fields...
}

sendVerificationEmail Send verification email

This action sends a verification email to the user.

Parameters

Property Type Default Description
id string null The ID of the user.

Results

{
    "id": "akTRSKTKzGCg9EMz",
    "username": "myusername",
    "email": "[email protected]",
    // ...other user fields...
}

assignPlan Assign a plan to the user

This action assigns a plan to the user.

Parameters

Property Type Default Description
id string null The ID of the user.
plan string null The ID of the plan.

REST endpoint

POST /{serviceName}/:id/plans

Request Body

{
    "plan": "plan-id"
}

Results

{
    "id": "akTRSKTKzGCg9EMz",
    "username": "myusername",
    "email": "[email protected]",
    "plan": "plan-id",
    // ...other user fields...
}

assignRole Assign a role to the user

This action assigns a role to the user.

Parameters

Property Type Default Description
id string null The ID of the user.
role string null The name of the role.

REST endpoint

POST /{serviceName}/:id/roles

Request Body

{
    "role": "role-name"
}

Results

{
    "id": "akTRSKTKzGCg9EMz",
    "username": "myusername",
    "email": "[email protected]",
    "roles": ["role-name"],
    // ...other user fields...
}

revokeRole Revoke a role from the user

This action revokes a role from the user.

Parameters

Property Type Default Description
id string null The ID of the user.
role string null The name of the role.

REST endpoint

DELETE /{serviceName}/:id/roles/:role

Results

{
    "id": "akTRSKTKzGCg9EMz",
    "username": "myusername",
    "email": "[email protected]",
    "roles": [],
    // ...other user fields...
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages