This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import unittest | |
| import datetime | |
| from app.main import db | |
| from app.main.model.user import User | |
| from app.test.base import BaseTestCase | |
| class TestUserModel(BaseTestCase): | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | @staticmethod | |
| def decode_auth_token(auth_token): | |
| """ | |
| Decodes the auth token | |
| :param auth_token: | |
| :return: integer|string | |
| """ | |
| try: | |
| payload = jwt.decode(auth_token, key) | |
| is_blacklisted_token = BlacklistToken.check_blacklist(auth_token) | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | def encode_auth_token(self, user_id): | |
| """ | |
| Generates the Auth Token | |
| :return: string | |
| """ | |
| try: | |
| payload = { | |
| 'exp': datetime.datetime.utcnow() + datetime.timedelta(days=1, seconds=5), | |
| 'iat': datetime.datetime.utcnow(), | |
| 'sub': user_id | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from .. import db | |
| import datetime | |
| class BlacklistToken(db.Model): | |
| """ | |
| Token Model for storing JWT tokens | |
| """ | |
| __tablename__ = 'blacklist_tokens' | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # app/__init__.py | |
| from flask_restplus import Api | |
| from flask import Blueprint | |
| from .main.controller.user_controller import api as user_ns | |
| blueprint = Blueprint('api', __name__) | |
| api = Api(blueprint, | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from flask import request | |
| from flask_restplus import Resource | |
| from ..util.dto import UserDto | |
| from ..service.user_service import save_new_user, get_all_users, get_a_user | |
| api = UserDto.api | |
| _user = UserDto.user | |
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from flask_restplus import Namespace, fields | |
| class UserDto: | |
| api = Namespace('user', description='user related operations') | |
| user = api.model('user', { | |
| 'email': fields.String(required=True, description='user email address'), | |
| 'username': fields.String(required=True, description='user username'), | |
| 'password': fields.String(required=True, description='user password'), | |
| 'public_id': fields.String(description='user Identifier') | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import uuid | |
| import datetime | |
| from app.main import db | |
| from app.main.model.user import User | |
| def save_new_user(data): | |
| user = User.query.filter_by(email=data['email']).first() | |
| if not user: | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import os | |
| import unittest | |
| from flask import current_app | |
| from flask_testing import TestCase | |
| from manage import app | |
| from app.main.config import basedir | |
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from flask_testing import TestCase | |
| from app.main import db | |
| from manage import app | |
| class BaseTestCase(TestCase): | |
| """ Base Tests """ | |
| def create_app(self): | |
| app.config.from_object('app.main.config.TestingConfig') |