From 556992d1b727c6d3aaadc29ca89338ad18bf8eb4 Mon Sep 17 00:00:00 2001 From: Debajyoti Saha <91759192+Debajyoti14@users.noreply.github.com> Date: Tue, 14 May 2024 20:51:54 +0530 Subject: [PATCH] Debajyotisaha14/refactoring (#37) * Password validation Changed * Add Special Character support for password * Added Docs for Local Setup with folder structure * Updated Docs --- .env.example | 6 + README.md | 13 +- docs/api/openapi.yaml | 461 ++++++++++++++++++++++++++++++++ docs/api/readme.md | 7 + docs/folder-structure/readme.md | 16 ++ docs/local-setup/readme.md | 53 ++++ src/handlers/user_handler.rs | 1 - 7 files changed, 551 insertions(+), 6 deletions(-) create mode 100644 .env.example create mode 100644 docs/api/openapi.yaml create mode 100644 docs/api/readme.md create mode 100644 docs/folder-structure/readme.md create mode 100644 docs/local-setup/readme.md diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..d744df7 --- /dev/null +++ b/.env.example @@ -0,0 +1,6 @@ +SERVER_KEK=my_server_kek +EMAIL_PASSWORD=my_email_password +EMAIL=my_email +MAIL_NAME=my_name +SMTP_DOMAIN=smtp.gmail.com +SMTP_PORT=587 \ No newline at end of file diff --git a/README.md b/README.md index 18e5d2a..ddda0d6 100644 --- a/README.md +++ b/README.md @@ -25,13 +25,16 @@ Need some features you think might be helpful for others? Raise a PR and we will surely try to bring it live. ## Local Setup: -Here is a documentation for if you want to setup this repo locally - [Local Setup Doc]() +Here is a documentation for if you want to setup this repo locally - [Local Setup Doc](https://github.com/Rajdip019/flexauth/tree/main/docs/local-setup/readme.md) + +## API Documentation: +Here is the API documentation - [API Doc](https://github.com/Rajdip019/flexauth/tree/main/docs/api/readme.md) ## Backend Documentation: Link to backend docs - [Backend Doc](https://github.com/Rajdip019/flexauth/tree/main/docs/backend) ## Folder Structure and others: -Link to general docs for this repository - [General Docs]() +Link to general docs for this repository - [General Docs](https://github.com/Rajdip019/flexauth/tree/main/docs/folder-structure/readme.md) **Code of Conduct:** @@ -39,12 +42,12 @@ Please note that we have a code of conduct in place to ensure a welcoming and in **Get Started:** -Ready to start contributing to Freeflow? Head over to our GitHub repository and fork the project today! +Ready to start contributing to FlexAuth? Head over to our GitHub repository and fork the project today! -[GitHub Repository Link](https://github.com/Rajdip019/freeflow) +[GitHub Repository Link](https://github.com/Rajdip019/flexAuth) -We look forward to your contributions and thank you for helping us make Freeflow the best platform for designers and teams! +We look forward to your contributions and thank you for helping us make FlexAuth the best platform for designers and teams!

Project maintainers

diff --git a/docs/api/openapi.yaml b/docs/api/openapi.yaml new file mode 100644 index 0000000..da3670e --- /dev/null +++ b/docs/api/openapi.yaml @@ -0,0 +1,461 @@ +openapi: 3.1.0 +info: + title: FlexAuth + description: >- + # ๐Ÿš€ Get started here + + + This template guides you through CRUD operations (GET, POST, PUT, DELETE), + variables, and tests. + + + ## ๐Ÿ”– **How to use this template** + + + #### **Step 1: Send requests** + + + RESTful APIs allow you to perform CRUD operations using the POST, GET, PUT, + and DELETE HTTP methods. + + + This collection contains each of these + [request](https://learning.postman.com/docs/sending-requests/requests/) + types. Open each request and click "Send" to see what happens. + + + #### **Step 2: View responses** + + + Observe the response tab for status code (200 OK), response time, and size. + + + #### **Step 3: Send new Body data** + + + Update or add new data in "Body" in the POST request. Typically, Body data + is also used in PUT request. + + + ``` + + { + "name": "Add your name in the body" + } + + ``` + + #### **Step 4: Update the variable** + + + Variables enable you to store and reuse values in Postman. We have created a + [variable](https://learning.postman.com/docs/sending-requests/variables/) + called `base_url` with the sample request + [https://postman-api-learner.glitch.me](https://postman-api-learner.glitch.me). + Replace it with your API endpoint to customize this collection. + + + #### **Step 5: Add tests in the "Tests" tab** + + + Tests help you confirm that your API is working as expected. You can write + test scripts in JavaScript and view the output in the "Test Results" tab. + + + + + + ## ๐Ÿ’ช Pro tips + + + - Use folders to group related requests and organize the collection. + + - Add more + [scripts](https://learning.postman.com/docs/writing-scripts/intro-to-scripts/) + in "Tests" to verify if the API works as expected and execute workflows. + + + ## ๐Ÿ’กRelated templates + + + [API testing + basics](https://go.postman.co/redirect/workspace?type=personal&collectionTemplateId=e9a37a28-055b-49cd-8c7e-97494a21eb54&sourceTemplateId=ddb19591-3097-41cf-82af-c84273e56719) + + [API + documentation](https://go.postman.co/redirect/workspace?type=personal&collectionTemplateId=e9c28f47-1253-44af-a2f3-20dce4da1f18&sourceTemplateId=ddb19591-3097-41cf-82af-c84273e56719) + + [Authorization + methods](https://go.postman.co/redirect/workspace?type=personal&collectionTemplateId=31a9a6ed-4cdf-4ced-984c-d12c9aec1c27&sourceTemplateId=ddb19591-3097-41cf-82af-c84273e56719) + version: 1.0.0 +servers: + - url: http://{{base_url}} +tags: + - name: user + - name: auth + - name: health-check + - name: session + - name: password +paths: + /user/get-all: + get: + tags: + - user + summary: get-all + responses: + "200": + description: Successful response + content: + application/json: {} + /user/get-from-email: + post: + tags: + - user + summary: get-from-email + requestBody: + content: + application/json: + schema: + type: object + example: + email: debajyotisaha14@gmail.com + responses: + "200": + description: Successful response + content: + application/json: {} + /user/get-from-id: + post: + tags: + - user + summary: get-from-id + requestBody: + content: + application/json: + schema: + type: object + example: + uid: 4554efa4-71da-4a1d-85bb-1c5691db87be + responses: + "200": + description: Successful response + content: + application/json: {} + /user/update: + post: + tags: + - user + summary: update + requestBody: + content: + application/json: + schema: + type: object + example: + name: Debajyoti Saha + email: debajyotisaha14@gmail.com + responses: + "200": + description: Successful response + content: + application/json: {} + /user/toggle-account-active-status: + post: + tags: + - user + summary: toggle-account-active-status + requestBody: + content: + application/json: + schema: + type: object + example: + is_active: true + email: debajyotisaha14@gmail.com + responses: + "200": + description: Successful response + content: + application/json: {} + /user/update-role: + post: + tags: + - user + summary: update-role + requestBody: + content: + application/json: + schema: + type: object + example: + role: admin + email: debajyotisaha14@gmail.com + responses: + "200": + description: Successful response + content: + application/json: {} + /user/delete: + post: + tags: + - user + summary: delete + requestBody: + content: + application/json: + schema: + type: object + example: + email: debajyotisaha14@gmail.com + responses: + "200": + description: Successful response + content: + application/json: {} + /auth/signup: + post: + tags: + - auth + summary: signup + requestBody: + content: + application/json: + schema: + type: object + example: + email: debajyotisaha14@gmail.com + name: Debajyoti Saha + password: Debu@1234 + role: admin + responses: + "200": + description: Successful response + content: + application/json: {} + /auth/signin: + post: + tags: + - auth + summary: signin + requestBody: + content: + application/json: + schema: + type: object + example: + email: debajyotisaha14@gmail.com + password: Debu4321 + responses: + "200": + description: Successful response + content: + application/json: {} + /auth/signout: + post: + tags: + - auth + summary: signout + requestBody: + content: + application/json: + schema: + type: object + example: + session_id: >- + 1e6129b169517494cffff74ac735a03a52967604c31cca8b9c8c43c24d780cf6cc2804550f845c1221fd8a787ce88884a57fb7c8 + responses: + "200": + description: Successful response + content: + application/json: {} + /health: + get: + tags: + - health-check + summary: health + responses: + "200": + description: Successful response + content: + application/json: {} + /session/verify: + post: + tags: + - session + summary: verify + requestBody: + content: + application/json: + schema: + type: object + example: + token: >- + eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1aWQiOiIyNjk3NzY3Ni1jYjM3LTRmM2ItYTgyMS03ZTU5YzU0NTlmZDIiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJpYXQiOjE3MTU2MjU5MjMsImV4cCI6MTcxNTYyOTUyMywidG9rZW5fdHlwZSI6ImlkIiwiZGF0YSI6eyJpc19lbWFpbF92ZXJpZmllZCI6ImZhbHNlIiwiaXNfYWN0aXZlIjoidHJ1ZSIsImRpc3BsYXlfbmFtZSI6IkRlYmFqeW90aSBTYWhhIiwicm9sZSI6ImFkbWluIn19.qmE4MijE52rNldxc6PRw3rvpXbpBnNi-l7UhiuYqi1GT2bD1_KnqGrdQFJdVRTQ0fQjOFJwUu-77HbaQUCODHlE0NHn9aHECjCI4in1X--5atiyVIt_73wqgQgwMjkxmzDMtwIwClFQcQwKQizGOgrqKftsy_IhrerMgy7aE3wrZv0on5fdxOfxVZ8OW1ueATuEVR1QWn8vjM3ojpylrXJCVWhoJje0z7diudHHorNaon8e-7JUQr-TYzrlA-OH5QoaLDboobRg1-VU8RzaPWNbysUGZgUvLIPwJojoVa_fRk0I8qzmKBSFzcPKZQHMNXtB0ySaCv5flI-0EZ2yHnA + responses: + "200": + description: Successful response + content: + application/json: {} + /session/get_all_from_uid: + post: + tags: + - session + summary: get_all_from_uid + requestBody: + content: + application/json: + schema: + type: object + example: + uid: 26977676-cb37-4f3b-a821-7e59c5459fd2 + responses: + "200": + description: Successful response + content: + application/json: {} + /session/refresh-session: + post: + tags: + - session + summary: refresh-session + requestBody: + content: + application/json: + schema: + type: object + example: + session_id: >- + 41607eb13b522fc3cfaafe1b9035a03c51c47604c019c38bcc891ac2132f0ef4ca26010772c0dcef478394e996c8e22bf8c08360 + id_token: >- + eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1aWQiOiIyNjk3NzY3Ni1jYjM3LTRmM2ItYTgyMS03ZTU5YzU0NTlmZDIiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJpYXQiOjE3MTU2MjYxMjQsImV4cCI6MTcxNTYyOTcyNCwidG9rZW5fdHlwZSI6ImlkIiwiZGF0YSI6eyJyb2xlIjoiYWRtaW4iLCJkaXNwbGF5X25hbWUiOiJEZWJhanlvdGkgU2FoYSIsImlzX2FjdGl2ZSI6InRydWUiLCJpc19lbWFpbF92ZXJpZmllZCI6ImZhbHNlIn19.Otar_P0p5Fq7iQpss2Uf0awXiaF_GItIAGIGmxMJYitXJbR1KBj2xb9zsNBuW62OKjKJq_Sir1kNb9MAsd8ccnOmIpT9Kv5j7f-3nusRNiBjlWfrdqbunhPKEAH8Qdxjf6bm15dA78QIXRfUYyn9j24Rm_HCaMWwCZ39cNDIjL7QE9Kxbtru6bpmHoHVF_ac0VbhoUZ26XkoyQ__K86ypcr27y4lrEq8hj-kW6t7epwFlOS_ktlYHrCIREVAOh3s2KCb2PoNG_ObHLhS60-J0WDEv4iJ-Lv5aUka1zcLgShc64xlkj0qDD9wPrtqOgHjV4qjMvUk7sPpEc6AbKCu5g + refresh_token: >- + eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJ1aWQiOiIyNjk3NzY3Ni1jYjM3LTRmM2ItYTgyMS03ZTU5YzU0NTlmZDIiLCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjgwODAiLCJpYXQiOjE3MTU2MjYxMjQsImV4cCI6MTcxOTUxNDEyNCwic2NvcGUiOiJnZXRfbmV3X2lkX3Rva2VuIiwiZGF0YSI6bnVsbH0.OGCc90lt5baMPIb2LP-IeZmOpBezXfkvwwNSeinuRuLLT9mwdfFw6QPv5n7P9n_9FZAeVRl8azHIZgr1zAHk_9Agr5EsVmalDQBqw5x59M5oTRy0tGGhvUVMESJ3TvFn4p6M1aU9i740mNgjkDCsZ695gaxZqv5RlLZgilk5qBElQXd_vba9BBbVpfvW0rweXwJ-T-aF_8Xd2Gpr3FXOd18x68u4CefDNQtWBJZgAL-a_FpVFhcRo-MJIelhzQNgBhnp2h98PQfaa7e8sVoyUTLXE-5zb0KRE4YqalvFUPR8U7vpyJXUMuKz6orjfn9eHYA4L8YUrtsIU6SIx2Rj4A + responses: + "200": + description: Successful response + content: + application/json: {} + /session/revoke: + post: + tags: + - session + summary: revoke + requestBody: + content: + application/json: + schema: + type: object + example: + session_id: >- + 41607eb13b522fc3cfaafe1b9035a03c51c47604c019c38bcc891ac2132f0ef4ca26010772c0dcef478394e996c8e22bf8c08360 + responses: + "200": + description: Successful response + content: + application/json: {} + /session/revoke-all: + post: + tags: + - session + summary: revoke-all + requestBody: + content: + application/json: + schema: + type: object + example: + uid: 26977676-cb37-4f3b-a821-7e59c5459fd2 + responses: + "200": + description: Successful response + content: + application/json: {} + /session/delete: + post: + tags: + - session + summary: delete + requestBody: + content: + application/json: + schema: + type: object + example: + session_id: >- + 41607eb13b522fc3cfaafe1b9035a03c51c47604c019c38bcc891ac2132f0ef4ca26010772c0dcef478394e996c8e22bf8c08360 + responses: + "200": + description: Successful response + content: + application/json: {} + /session/delete-all: + post: + tags: + - session + summary: delete-all + requestBody: + content: + application/json: + schema: + type: object + example: + uid: 26977676-cb37-4f3b-a821-7e59c5459fd2 + responses: + "200": + description: Successful response + content: + application/json: {} + /password/reset: + post: + tags: + - password + summary: reset + requestBody: + content: + application/json: + schema: + type: object + example: + email: debajyotisaha14@gmail.com + old_password: Debu@1234 + new_password: Debu4321 + responses: + "200": + description: Successful response + content: + application/json: {} + /password/forget-request: + post: + tags: + - password + summary: forget-request + requestBody: + content: + application/json: + schema: + type: object + example: + email: debajyotisaha14@gmail.com + responses: + "200": + description: Successful response + content: + application/json: {} + /password/forget-reset/414a5486-5254-4016-908b-72cde4acf063: + post: + tags: + - password + summary: forget-reset + requestBody: + content: + application/json: + schema: + type: object + example: + email: debajyotisaha14@gmail.com + password: Debu4321 + responses: + "200": + description: Successful response + content: + application/json: {} diff --git a/docs/api/readme.md b/docs/api/readme.md new file mode 100644 index 0000000..5f17ce5 --- /dev/null +++ b/docs/api/readme.md @@ -0,0 +1,7 @@ +## API Documentation + +The API documentation can be accessed [here](lhttps://app.swaggerhub.com/apis/SAHADEBAJYOTI7/flex-auth/1.0.0). If you encounter any issues accessing the documentation, you can also view it in the [Swagger Editor](https://editor-next.swagger.io/) by pasting the content of the OpenAPI YAML file. + +## OpenAPI YAML File + +You can find the `openapi.yaml` file inside `/docs/api-docs`. This file contains the specifications for the API endpoints, schemas, and more. \ No newline at end of file diff --git a/docs/folder-structure/readme.md b/docs/folder-structure/readme.md new file mode 100644 index 0000000..45e6b88 --- /dev/null +++ b/docs/folder-structure/readme.md @@ -0,0 +1,16 @@ + +## Folder Structure Explanation + +- **src/**: This directory contains the source code of the project. + - **cli/**: All the logic for the CLI executable functions resides here. + - **config/**: Configuration files such as db connection configurations. + - **routes/**: Route definitions for the API endpoints. + - **utils/**: Utility functions or helper modules. + - **core/**: Has all the logics for the core modules such as `Auth`,`Session`. + - **handlers/**: Contains all the API Handlers. + - **middlewares/**: Contains all the middleware functions + - **models/**: Contains all the Data Models + +- **docs/**: Documentation files are stored here. + +Feel free to adjust this structure according to your project's needs and conventions. diff --git a/docs/local-setup/readme.md b/docs/local-setup/readme.md new file mode 100644 index 0000000..e89f67a --- /dev/null +++ b/docs/local-setup/readme.md @@ -0,0 +1,53 @@ + +## Local Setup + +### Step 1 : Pre Requisities +- [Rust Basics](https://doc.rust-lang.org/book/) +- [Cargo (Rust package manager)](https://doc.rust-lang.org/cargo/getting-started/installation.html) +- [Docker (For containerization)](https://docs.docker.com/get-docker/) +- [MongoDB Compass (For Visualising DB with GUI)](https://www.mongodb.com/try/download/compass) + + +### Step 2: Environment Variables + +To run this project, you will need to add the following environment variables to your .env file. Have a look at the `.env.example` file to see all the keys needed. + + +You can generate `SERVER_KEK` by running the command below from the root of your project. ( Make sure you have cargo installed +``` +cargo run --bin create_kek + +``` + + +SMTP servers require authentication to ensure that only authorized users can send emails. For generating `EMAIL_PASSWORD`, Visit this [link](https://support.google.com/mail/thread/205453566/how-to-generate-an-app-password?hl=en). +`SMTP_DOMAIN = smtp.gmail.com` as we are using GMAIL as a Mail Provider. + + +Also we need a Private Key for verifying Sessions (Make sure you have openssl in your system) and place it at the root of the project. +``` +openssl genpkey -algorithm RSA -out private_key.pem -aes256 -pass pass:your_passphrase -pkeyopt rsa_keygen_bits:2048 + +``` + +### Step 3: Spinning up Docker Containers + +Not it's time to run the docker container by running this following command (Make sure you have Docker installed) +``` +docker compose up + +``` + +Note:- If there's any changes outside of the `/src` directory like- `cargo.toml` file, Make sure to stop the container and run the docker container with `--build` flag +``` +docker compose up --build + +``` + +Congrats, Your Local Setup is done successfully. + + + + + + diff --git a/src/handlers/user_handler.rs b/src/handlers/user_handler.rs index 24a1d28..d2f4079 100644 --- a/src/handlers/user_handler.rs +++ b/src/handlers/user_handler.rs @@ -50,7 +50,6 @@ pub async fn update_user_handler( Ok(dek) => dek, Err(e) => return Err(e), }; - // find the user in the users collection using the uid match collection .update_one(