forked from anitab-org/bridge-in-tech-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: issue19-24 setup and User Registration API
* Add the README file * made changes to README * added suggested changes * docs: Move lines anitab-org#8 and anitab-org#10 * moved README outside .github * remove extra README file
- Loading branch information
1 parent
ba92967
commit 4967740
Showing
60 changed files
with
4,177 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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 |
This file contains 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
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/ |
This file contains 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
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, |
This file contains 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
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 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: gunicorn run:application |
This file contains 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
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.
Empty file.
This file contains 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
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.
This file contains 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
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 |
This file contains 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
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 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from flask_mail import Mail | ||
|
||
mail = Mail() |
Empty file.
This file contains 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
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" | ||
), | ||
}, | ||
) |
This file contains 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
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.
Oops, something went wrong.