Giter VIP home page Giter VIP logo

visakh47 / maverick Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 18.06 MB

An analytics application built for the hack-o-uplift program wherein we provide users with different tableau visualization, so users can make an informed choice as to which education platform they should invest their time in.

Home Page: https://maverick-1.herokuapp.com/

Python 4.47% Shell 0.16% CSS 16.61% HTML 76.93% JavaScript 1.83%

maverick's Introduction

##How to Integrate SAWO SDK to Flask App

Requirements – Python, pip.

Steps:

  1. Install the sawo package

    pip install sawo
    
  2. From Sawo import createTemplate, getContext and verifyToken methods The getContext method is used to create sawo dictionary object from data gain from DB in Django

    from sawo import createTemplate, getContext, verifyToken
    
  3. Login to sawo dev console sawo-dev-console

  4. Create new project Set project name Set project host For dev: point to localhost For prod: point to your domain Copy the API key

  5. Setup Getting started Creating template for sawo password less and OTP-less Authentication for your website.

    Flask

    #example
    createTemplate("./templates/partials",flask=True)
    

    #Sending data required by _sawo.html

    The variable name used in _sawo.html template are sawo.auth_key, sawo.identifier and sawo.to so to send that data we create a json.

    Note *The "to" route should be a post route which can receive posted data. *If you don’t know how data is passed to templates in Django or Flask, We will suggest looking into it first

    Flask

    METHOD 1. SENDING STATIC DATA

    context = {
      "sawo":{
      "auth_key": "<api_key>",
      "identifier": "email | phone_number_sms"
      "to": <route> #the route where you will recieve
      the payload sent by sdk
      }
    }
    
    #example
    context = {
      "sawo":{
      "auth_key": "785ha-hdjsdsd-799-ss345",
      "identifier": "email | phone_number_sms"
      "to": login
      }
    }
    

    METHOD 2. USING ADMIN AND DATABASE TO SAVE CONFIG FOR SAWO

    Step 1. Creating fields for sawo api_key and identifier to set it from admin dashboard. copy this code in models of your app

    class Config(models.Models):
    api_key = models.CharField(max_length=200)
    identifier = models.CharField(max_length=200)
    choices = [("email","Email"),("phone_number_sms","Phone")]
    

    Step 2. Setting up view.py of app. Note: Route should be the receiving end where you can handle post request

    from models import Config
    from sawo import getContext
    
    def <your_function>(request):
    config = Config.objects.order_by('-api_key')[:1]
    context = {
    "sawo" = getContext(config,<route>) #the route where you will recieve
    the payload sent by sdk
    }
    
    #example
    
    def index(request):
    config = Config.objects.order_by('-api_key')[:1]
    context = {
        "sawo" = getContext(config,"login")
    }
    

    Verifying Token

    When the login is done on the webpage it sends the data to backend as payload to verify user, you can use verifyToken function, it returns a boolean.

    BACKEND CODE IS SAME FOR DJANGO AND FLASK

    from sawo import verifyToken
    
    #use the method provided by flask and django to receive the
    #data from post request the use this function it will return
    #True or False depending on user status
    verifyToken(payload)
    
    //example
    payload = <data from POST request>
    if(verifyToken(payload)):
    #do something
    else:
    #do something else
    

    You are all set to use SAWO in your Flask Application

maverick's People

Contributors

visakh47 avatar

Watchers

 avatar

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.