Giter VIP home page Giter VIP logo

magic-link's Introduction

Magic Link

This is the second edition of #umaStackQueNaoDomino. Python Edition. The project offer API to generate, send and validate a magic link.

What's a Magic Link

Magic Link is kind of an authenticated URL, which you send to the consumer in form of SMS/email that helps them to log in to the system with just one click of the link without any human interaction (no need for the user to enter username+password). Description Source

First things first

You need to have pip (of course).

  • python3 -m venv env
  • source env/bin/activate
  • which python
  • pip install -r requirements.txt

How to Run

Running FastAPI

  • uvicorn main:app --reload

Running Redis Server

  • redis-server

Consume Queue

  • rq worker send_magic_links

Firestore

On this project we store validated magic links into Firebase Firestore, please check the oficial quick start documentation in order to setup your project and export the serviceAccountKey.json

magic-link's People

Contributors

jbarbosaamancio avatar jpsilva15 avatar lucasgabrielb avatar lucasmontano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

magic-link's Issues

[Service] Vote Confirmation

As a user that sent its vote, I should be able to confirm my identification.

All votes received from #10 should be confirmed by a magic link. This service should consume the Queue as FIFO (First In First Out).

[API] Vote confirmation

As a user that has voted, I should be able to confirm my new vote.

The user will receive the magic link sent by the Confirmation Service #11 , the link is a GET request to this API.

A user can vote multiple times, but the last vote will override the previous ones. This API should write in the database the computed vote.

API Endpoint: /vote/confirmation/JWT

API Response
The API should return 200 status code if the vote is accepted and 400 if the request is invalid.

Note: we can create a separated issue to redirect the user to a cool webpage :)

[SETUP] Using Poetry to manage the dependencies

Poetry is a dependency manager.

Poetry allows the same development environment for all developers and organizing the project on a pyproject.toml file, following the "Python standards" PEP-517 and PEP-518.

After install Poetry you can run the following command to install all dependencies on a Python's virtual environment:

$ poetry install

To activate the virtual environment you can run:

$ poetry shell

To add a dependency you can run:

$ poetry add [PACKGE_NAME]

To add remove a dependency you can run:

$ poetry remove [PACKGE_NAME] 

Message Broker

Decide which message broker we should use for queuing the votes: RabbitMQ, Redis or others?

Define database and add to the ReadME

Define which database we're going to use for storing the confirmed votes(JWT), current poll options, current poll results.

Confirmed votes payload

{
  "options": ["PHP", "JAVA", "Python"],
  "identifier": "[email protected]"
}

Vote stored

_id: identifier hash
vote: payload

Note: Each vote is transformed into a JWT and stored in the database.

Current Poll options

{
  "options": ["PHP", "JAVA", "Python"]
}

Current Poll result

{
  "result": "Python"
}

Add requirements.txt

Requirements.txt is important to a contributor easily install dependencies running only pip install -r requirements.txt instead:

$ pip install ...
...
$ pip install ...

Choosing a proper framework

i though in 2 options:

  • flask : light and fast, looks like the express in JS
  • Django: heavier but more complete, looks like the GIN in golang(My stack)

[API] Voting

As a user, I want to be able to vote in an ongoing poll.

User
A user is anyone that has access to the API and it's identified by an e-mail.

Vote Options
In a ranked poll, the user has the right to vote in multiple options. The options should be sent sorted by preference.

Example: ["my best option", "second best option", "third best option"]

Validation
The API should check if all informed options are available in the current poll.

Example:

  • Valid options ["PHP", "JAVA", "JS"]
  • Informed options ["VB", "PHP"]
  • Error: VB is not a valid option

API Request

{
  "identifier": "[email protected]",
  "options": ["VB", JAVA"]
}

API Response
Code: The API should return 204 status code if the vote is accepted and 400 if the request is invalid.
Body: The API should return an error message or empty body (if succeed).

Error message

{
    "detail": {
        "message": "You are trying to vote in one or more invalid options, please check the available options.",
        "options": [
            "VB",
            "COBOL",
            "Delphi"
        ]
    }
}

Tech Implementation
The vote is added to the Redis queue and should be consumed by the Confirmation Service #11 .

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.