Last active
May 17, 2020 18:59
-
-
Save gabbyprecious/940e1fc2d21a40aca33dc327035b253f to your computer and use it in GitHub Desktop.
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
import bcrypt | |
from fastapi import APIRouter | |
from fastapi_sqlalchemy import db | |
#the following line of code are to import the user in our model and schema | |
from model import User as ModelUser | |
from schema import UserCreate as SchemaUser | |
from schema import User as Users | |
router = APIRouter() | |
@router.post("/register", response_model=Users) | |
async def create_user(user: SchemaUser): | |
hashed_password = bcrypt.hashpw(user.password.encode('utf-8'), bcrypt.gensalt()) | |
User = ModelUser(first_name=user.first_name, last_name=user.last_name, username=user.username, email=user.email, password = hashed_password) | |
db.session.add(User) | |
db.session.commit() | |
db.session.refresh(User) | |
return User | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment