Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source venv/bin/activate
export PYTHONPATH=.:$PYTHONPATH
179 changes: 23 additions & 156 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,167 +1,34 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.py[co]
*.DS_*
# Packages
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.tox

# Translations
#Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# dotenv
.env

# virtualenv
.venv
venv/
ENV/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

#Mr Developer
venv
*.pyc
build

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov


# Coverage directory used by tools like istanbul
coverage


# nyc test coverage
.nyc_output


# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next
.idea
.cache
.pytest_cache
.vscode
15 changes: 15 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
language: python

python:
- "3.6"

install:
- pip install -r requirements.txt

script:
- nosetests --exe -v
- nosetests --exe --with-coverage --cover-package=WeConnect_RestAPI
- coveralls

after_success:
- "coveralls"
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# WeConnect
[![Coverage Status](https://coveralls.io/repos/github/dcDalin/WeConnect/badge.svg?branch=master)](https://coveralls.io/github/dcDalin/WeConnect?branch=master) [![Build Status](https://travis-ci.org/dcDalin/WeConnect.svg?branch=master)](https://travis-ci.org/dcDalin/WeConnect) [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org) ![Open Source Love](https://badges.frapsoft.com/os/mit/mit.svg?v=102)
[![Coverage Status](https://coveralls.io/repos/github/dcDalin/WeConnect/badge.svg?branch=ft-login-route-2153372)](https://coveralls.io/github/dcDalin/WeConnect?branch=ft-login-route-2153372)[![Build Status](https://travis-ci.org/dcDalin/WeConnect.svg?branch=master)](https://travis-ci.org/dcDalin/WeConnect) [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-yellow.svg)](https://conventionalcommits.org) ![Open Source Love](https://badges.frapsoft.com/os/mit/mit.svg?v=102)

View a [live demo](https://dcdalin.github.io/WeConnect/).

Expand Down
3 changes: 3 additions & 0 deletions WeConnect_RestAPI/.pytest_cache/v/cache/lastfailed
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"tests/test_auth_route.py": true
}
38 changes: 33 additions & 5 deletions WeConnect_RestAPI/api/we_connect/business.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,27 @@ def __init__(self):
'''Constructor method, will have dictionaries in a list'''
self.users_counter = 0
self.users = []
self.token = []

def check_email_exists(self, search_email):
'''Check if email'''
for find_email in self.users:
if find_email['email'] == search_email:
return True
break;
return False

def check_email_for_login(self, search_email):
'''Check if email'''
for find_email in self.users:
if find_email['email'] == search_email:
return find_email
return False

def check_password_exists(self, search_email):
'''Check if email'''
for find_email in self.users:
if find_email['email'] == search_email:
return True
return False


Expand All @@ -40,8 +54,22 @@ def create_user(self, data):
user['last_name'] = user['last_name'].title()
self.users.append(user)
return {'message': 'successful'}




def show_all_users(self):
return self.users
return self.users

def login_user(self, data):
'''Logic behind logging in '''
user = data
if (is_empty(user['email'])) or (is_empty(user['password'])):
return {'message': 'Empty field(s)'}
elif is_email(user['email']):
return {'message': 'Wrong email'}
elif not self.check_email_exists(user['email']):
return {'message': 'Email does not exist'}
else:
a_variable = self.check_email_for_login(user['email'])
if check_password_hash(a_variable['password'], user['password']):
'''compare password input to saved password'''
return {'message': 'logged in'}
return {'message': 'wrong creds'}
41 changes: 32 additions & 9 deletions WeConnect_RestAPI/api/we_connect/endpoints/auth.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,37 @@
import logging

from flask import request
from flask import request, Blueprint
from flask_restplus import Resource
from functools import wraps
from WeConnect_RestAPI.api.we_connect.business import WeConnectUsers
from WeConnect_RestAPI.api.we_connect.serializers import (NEW_USER_STRUCTURE,
login_structure, logout_structure, reset_pass_structure)
from WeConnect_RestAPI.api.restplus import api
LOGIN_STRUCTURE, logout_structure, reset_pass_structure)
from WeConnect_RestAPI.api.restplus import api

log = logging.getLogger(__name__)

ns = api.namespace('auth', description='Operations related to Authentication')

def token_required(f):
@wraps(f)
def decorated(*args, **kwargs):

token = None

if 'X-API-KEY' in request.headers:
token = request.headers['X-API-KEY']

if not token:
return {'message' : 'Token is missing.'}, 401

if token != 'mytoken':
return {'message' : 'Wrong token'}, 401

print('TOKEN: {}'.format(token))
return f(*args, **kwargs)

return decorated

init_we_connect_users = WeConnectUsers()

@ns.route('/register')
Expand All @@ -27,25 +48,25 @@ def post(self):
@ns.route('/login')
class LoginUser(Resource):

@api.expect(login_structure)
@api.expect(LOGIN_STRUCTURE)
def post(self):
"""
Logs in a User.
"""
pass
return init_we_connect_users.login_user(api.payload)

@ns.route('/logout')
class LoginUser(Resource):
class LogOut(Resource):

@api.expect(logout_structure)
@api.doc(security='apikey')
def post(self):
"""
Logs out a User.
"""
pass

@ns.route('/reset-password')
class LoginUser(Resource):
class ResetPassword(Resource):

@api.expect(reset_pass_structure)
def post(self):
Expand All @@ -57,7 +78,9 @@ def post(self):
@ns.route('/all-users')
class ShowAllUsers(Resource, WeConnectUsers):

@ns.marshal_with(NEW_USER_STRUCTURE, envelope='data')

@api.doc(security='apikey')
@token_required
def get(self):
"""
Returns all users.
Expand Down
3 changes: 1 addition & 2 deletions WeConnect_RestAPI/api/we_connect/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
'password': fields.String(required=False, description='The password of a User'),
})

login_structure = api.model('Login User', {
LOGIN_STRUCTURE = api.model('Login User', {
'email': fields.String(required=True, description='Email address of a User'),
'password': fields.String(required=True, description='The password of a User'),
'last_login': fields.DateTime,
})

logout_structure = api.model('Logout User', {
Expand Down
2 changes: 2 additions & 0 deletions WeConnect_RestAPI/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@


def configure_app(flask_app):
flask_app.config['SECRET_KEY'] = settings.SECRET_KEY
flask_app.config['SERVER_NAME'] = settings.FLASK_SERVER_NAME
flask_app.config['SWAGGER_UI_JSONEDITOR'] = settings.SWAGGER_UI_JSONEDITOR
flask_app.config['SWAGGER_UI_DOC_EXPANSION'] = settings.RESTPLUS_SWAGGER_UI_DOC_EXPANSION
flask_app.config['RESTPLUS_VALIDATE'] = settings.RESTPLUS_VALIDATE
flask_app.config['RESTPLUS_MASK_SWAGGER'] = settings.RESTPLUS_MASK_SWAGGER
flask_app.config['ERROR_404_HELP'] = settings.RESTPLUS_ERROR_404_HELP



def initialize_app(flask_app):
Expand Down
Loading