Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Issue24 registration api backend #26

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
15 changes: 15 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FLASK_ENVIRONMENT_CONFIG = <dev-or-test-or-prod>
SECRET_KEY = <your-secret-key>
SECURITY_PASSWORD_SALT = <your-security-password-salt>
MAIL_DEFAULT_SENDER = <mail-default-sender>
MAIL_SERVER = <mail-server>
APP_MAIL_USERNAME = <app-mail-username>
APP_MAIL_PASSWORD = <app-mail-password>
MOCK_EMAIL = <True-or-False>
FLASK_APP=run.py
DB_TYPE=postgresql
DB_USERNAME= <db-username>
DB_PASSWORD= <db-password>
DB_ENDPOINT= <db-endpoint>
DB_NAME=bit_schema
DB_TEST_NAME=bit_schema_test
115 changes: 115 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# 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

# 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/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# 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

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# PyCharm project settings
.idea/

# vscode
.vscode/

*.db

# aws-eb
.elasticbeanstalk/
3 changes: 3 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[MESSAGES CONTROL]
disable=missing-docstring, C0301, R0801, E203, E266, E501, W503, R0401, R0911, R0912, C0330, W0511, R0903, C0303, C0412, E0602, C0103, C0413, W0212, W0614, W0401, E1101, W0613, W0611, R0902, R0913, C0415
select = B,C,E,F,W,T4,B9,
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
language: python
sudo: required
python:
- '3.6'
cache: pip
services:
- postgresql
addons:
postgresql: '10'
apt:
packages:
- postgresql-10
- postgresql-client-10
env:
global:
- PGPORT=5432
before_script:
- psql -c 'create database bit_schema_test;' -U postgres
- psql -c 'create schema bitschema;' -U postgres
- psql -c 'create schema test_schema;' -U postgres
- psql -c 'create schema test_schema_2;' -U postgres
install:
- pip3 install -r requirements.txt
script:
- python -m unittest discover tests -v
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn run:application
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Bridge-In-Tech (backend)
Bridge-In-Tech is an application that allows industries/companies, mentors and students to actively collaborate to one another.

This is the backend client of Bridge-In-Tech.

## Contributing

**This project is under active development**



Please read our [Contributing Guidelines](.github/CONTRIBUTING.md), [Code of Conduct](.github/CODE_OF_CONDUCT.md) and [Reporting Guidelines](.github/REPORTING_GUIDELINES.md) thoroughly.


## Branches

This repository has the following branches:
- **master**: This branch contains the deployment of the backend.
- **develop**: This contains the latest code. All the contributing PRs must be sent to this branch.

## Contact

If you have any questions or want to discuss something about this repo, feel free to join our [Zulip Community](http://anitab-org.zulipchat.com/)! If you are a new contributor, head over to this project's stream [#bridge-in-tech](https://anitab-org.zulipchat.com/#narrow/stream/237630-bridge-in-tech) on Zulip to see ongoing discussions.

## License

The project is licensed under the GNU General Public License v3.0. Learn more about it in the [LICENSE](LICENSE) file.
Empty file added app/__init__.py
Empty file.
Empty file added app/api/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions app/api/bit_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from flask_restx import Api

api = Api(
title="Bridge In Tech API",
version="1.0",
description="API documentation for the backend of Bridge In Tech. \n \n"
+ "Bridge In Tech is an application inspired by the existing AnitaB.org Mentorship System, "
+ "It encourages organizations to collaborate with the mentors and mentees on mentoring programs. \n \n"
+ "The main repository of the Backend System can be found here: https://github.com/anitab-org/bridge-in-tech-backend \n \n"
+ "The Web client for the Mentorship System can be found here: https://github.com/anitab-org/bridge-in-tech-web \n \n"
+ "For more information about the project here's a link to our wiki guide: https://github.com/anitab-org/bridge-in-tech-backend/wiki"
# doc='/docs/'
)
api.namespaces.clear()

# Adding namespaces
from app.api.resources.users import users_ns as user_namespace

api.add_namespace(user_namespace, path="/")
Empty file added app/api/dao/__init__.py
Empty file.
37 changes: 37 additions & 0 deletions app/api/dao/user_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
from http import HTTPStatus
# from typing import Dict
# from sqlalchemy import func
from app.database.models.bit_schema.user_extension import UserExtensionModel
from app import messages


class UserExtensionDAO:

"""Data Access Object for Users_Extension functionalities"""

@staticmethod
def create_user_extension(data):
"""Creates a user_extension instance for a new registered user.

Arguments:
data: A list containing user's id, boolean value of whether or not
the user is representing an organization, as well as their timezone

Returns:
A dictionary containing "message" which indicates whether or not the user_exension was created successfully and "code" for the HTTP response code.
"""

user_id = data["user_id"]
is_organization_rep = data["is_organization_rep"]
timezone = data["timezone"]

user_extension = UserExtensionModel(user_id, is_organization_rep, timezone)

user_extension.save_to_db()

response = {
"message": f"{messages.USER_WAS_CREATED_SUCCESSFULLY}",
"code": f"{HTTPStatus.CREATED}",
}

return response
24 changes: 24 additions & 0 deletions app/api/jwt_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from http import HTTPStatus
from flask_jwt_extended import JWTManager
from app import messages
from app.api.bit_extension import api

jwt = JWTManager()

# This is needed for the error handlers to work with flask-restplus
jwt._set_error_handler_callbacks(api)


@jwt.expired_token_loader
def my_expired_token_callback():
return messages.TOKEN_HAS_EXPIRED, HTTPStatus.UNAUTHORIZED


@jwt.invalid_token_loader
def my_invalid_token_callback():
return messages.TOKEN_IS_INVALID, HTTPStatus.UNAUTHORIZED


@jwt.unauthorized_loader
def my_unauthorized_request_callback():
return messages.AUTHORISATION_TOKEN_IS_MISSING, HTTPStatus.UNAUTHORIZED
mtreacy002 marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 3 additions & 0 deletions app/api/mail_extension.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from flask_mail import Mail

mail = Mail()
Empty file added app/api/models/__init__.py
Empty file.
25 changes: 25 additions & 0 deletions app/api/models/user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from flask_restx import fields, Model


def add_models_to_namespace(api_namespace):
api_namespace.models[register_user_api_model.name] = register_user_api_model


register_user_api_model = Model(
"User registration model",
{
"name": fields.String(required=True, description="User name"),
"username": fields.String(required=True, description="User username"),
"password": fields.String(required=True, description="User password"),
"email": fields.String(required=True, description="User email"),
"terms_and_conditions_checked": fields.Boolean(
required=True, description="User check Terms and Conditions value"
),
"need_mentoring": fields.Boolean(
required=False, description="User need mentoring indication"
),
"available_to_mentor": fields.Boolean(
required=False, description="User availability to mentor indication"
),
},
)
39 changes: 39 additions & 0 deletions app/api/ms_api_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import logging
import requests
from http import HTTPStatus
from app import messages

# from requests.exceptions import HTTPError
from flask import json
# from urllib3.exceptions import HTTPError
# from werkzeug.exceptions import HTTPException

# set base url

# for ms-api local server
BASE_MS_API_URL = "http://127.0.0.1:4000"

# for MS-API on Heroku server
# WARNING!!! When you push a PR, for travis to pass test cases related to MS API
# Heroku MS API needs to be set as preference over the localhost. Otherwise, make sure
# you run the MS API local server when you push the PR.
# BASE_MS_API_URL = "https://bridge-in-tech-ms-test.herokuapp.com"


# create instance
def post_request(request_url, data):
try:

response = requests.post(
request_url, json=data, headers={"Accept": "application/json"}
)
response.raise_for_status()
except requests.ConnectionError as e:
return f"{e.response.json()}", HTTPStatus.INTERNAL_SERVER_ERROR
except requests.HTTPError as e:
return f"{e.response.json()}", e.response.status_code
except Exception as e:
return f"{e.response.json()}", e.response.status_code
else:
logging.warning(f"{response}")
return f"{response.json()}", response.status_code
Empty file added app/api/resources/__init__.py
Empty file.
Loading