-
Notifications
You must be signed in to change notification settings - Fork 1
/
api.py
33 lines (26 loc) · 1012 Bytes
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from db import db
import hug
import tokenJWT
import account
database = db('user.db')
jwt = tokenJWT.tokenJWT(database)
acct = account.Account(database, jwt)
#Create Token Verification Function
def verifyToken(token):
return(jwt.verifyToken('PrivateKey.pem', token))
token_key_authentication = hug.authentication.token(verifyToken)
#API Main Authentication Endpoints
@hug.post('/register')
def register_user(username, email, password, firstName, lastName, dob, country, ipAddr):
return(acct.registerUser(username, email, password, firstName, lastName, dob, country, ipAddr))
@hug.post('/login')
def login(username, password):
return(acct.login(username, password))
#Account Management Endpoints
@hug.post('/changePassword')
def changePassword(token, pwFrom, pwTo):
return(acct.changePassword(token,pwFrom,pwTo))
#API Main Service Endpoints
@hug.get('/testauth', requires=token_key_authentication)
def basic_auth_api_call(user: hug.directives.user):
return ('Test Good'+user[1]['uuid'])