Skip to content
Merged

Dev #133

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
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@
# Ignore python cache file
.vscode/
__pycache__/
*.py[cod]
*.py[cod]

# Ignore logs
/logs/
*.log
40 changes: 33 additions & 7 deletions src/__init__.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# src/__init__.py

from flask import Flask, request, Response
from flask import Flask
from flask_caching import Cache
from flask_cors import CORS
from flask_mail import Mail
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from datetime import timedelta
from flask_caching import Cache
from redis import Redis
from flask_sqlalchemy import SQLAlchemy
from flasgger import Swagger
from .config import Config
import os
from flask_cors import CORS
from flasgger import Swagger

BASEDIR = os.path.abspath(os.path.dirname(__file__))
API_PREFIX = '/api/v1'
Expand All @@ -31,6 +29,8 @@ def create_app(config_class=Config):

register_blueprints(app, API_PREFIX)

register_log(app)

with app.app_context():
db.create_all()

Expand All @@ -54,3 +54,29 @@ def register_blueprints(app, prefix):
app.register_blueprint(auth, url_prefix=f'{prefix}/auth/')
app.register_blueprint(news, url_prefix=f'{prefix}/news/')
app.register_blueprint(users, url_prefix=f'{prefix}/users/')

def register_log(app: Flask):
import logging
from logging.handlers import RotatingFileHandler
from logging import Formatter

log_formatter = Formatter(
'%(asctime)s %(levelname)s: %(message)s '
'[in %(pathname)s:%(lineno)d]'
)

if not os.path.exists('logs'):
os.mkdir('logs')
print('Logs directory created')

log_handler = RotatingFileHandler(
'logs/app.log', 'w', maxBytes=1024*1024, backupCount=10
)

log_handler.setLevel(logging.INFO)
log_handler.setFormatter(log_formatter)

app.logger.addHandler(log_handler)

app.logger.setLevel(logging.INFO)
app.logger.info('App startup')
17 changes: 0 additions & 17 deletions src/admin/__init__.py

This file was deleted.

11 changes: 0 additions & 11 deletions src/admin/templates/admin/create_user.html

This file was deleted.

31 changes: 0 additions & 31 deletions src/admin/views.py

This file was deleted.

66 changes: 66 additions & 0 deletions src/apidocs/auth/forgotPassword/getOtp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
This is yml file for verifyOTP API document.
In this example the specification is taken from external YAML file
---
tags:
- Auth
produces: application/json,
parameters:
- name: body
in: body
description: "Get OTP requirements"
schema:
type: object
properties:
userId:
type: string
required: true
description: The user id
example: 1
responses:
200:
description: return OTP code from server
schema:
type: string
properties:
otp:
type: string
example: "1234"
message:
type: string
example: "OTP get successfully"
status:
type: string
example: "success"
400:
description: User id is required
schema:
type: object
properties:
status:
type: string
example: "error"
message:
type: string
example: UserId is required
404:
description: User does not exist
schema:
type: object
properties:
status:
type: string
example: "error"
message:
type: string
example: OTP not found in cache or has expired
500:
description: Database error occurred
schema:
type: object
properties:
status:
type: string
example: "error"
message:
type: string
example: Failed to get OTP
69 changes: 69 additions & 0 deletions src/apidocs/auth/forgotPassword/resetPassword.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Reset Password
Requirements:
email, newPassword
---
tags:
- Auth
produces: application/json,
parameters:
- name: body
in: body
description: "Password reset requirements"
schema:
type: object
properties:
email:
type: string
required: true
description: The user email
example: "411031111@mail.nknu.edu.tw"
newPassword:
type: string
required: true
description: The user new password
example: "411031111"
responses:
200:
description: The user new password reset successfully.
schema:
type: object
properties:
status:
type: string
example: "success"
message:
type: string
example: "Password reset successfully"
400:
description: Email and newPassword is required
schema:
type: object
properties:
status:
type: string
example: "error"
message:
type: string
example: Email and newPassword is required
404:
description: User does not exist
schema:
type: object
properties:
status:
type: string
example: "error"
message:
type: string
example: User does not exist
500:
description: Database error occurred
schema:
type: object
properties:
status:
type: string
example: "error"
message:
type: string
example: Database error occurred
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
This is yml file for forgetPassword API document.
In this example the specification is taken from external YAML file
Send OTP mail to user email
Post user email and send OTP mail to user email
---
tags:
- User API
- Auth
produces: application/json,
parameters:
- name: body
in: body
description: Forget password requirements
description: Send OTP to user email requirements
schema:
type: object
properties:
Expand All @@ -18,26 +18,26 @@ parameters:
example: "411031111@mail.nknu.edu.tw"
responses:
200:
description: OTP-mail send success
description: OTP email send success
schema:
type: object
properties:
Message:
message:
type: string
example: OTP-mail send success
example: OTP email send success
400:
description: OTP-mail send failed
description: OTP email send failed
schema:
type: object
properties:
Message:
message:
type: string
example: OTP-mail send failed
404:
description: The user email is incorrect, no user found in database
example: Email is required
503:
description: Failed to send OTP email
schema:
type: object
properties:
Message:
message:
type: string
example: No user found
example: Failed to send OTP email
44 changes: 0 additions & 44 deletions src/apidocs/auth/passwordReset.yml

This file was deleted.

Loading
Loading