-
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.
- Loading branch information
1 parent
9837e72
commit c79b068
Showing
7 changed files
with
183 additions
and
3 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 |
---|---|---|
@@ -1 +1,56 @@ | ||
import sqlite3 | ||
from flask import Flask | ||
from flask_sqlalchemy import SQLAlchemy | ||
|
||
from typing import List | ||
from typing import Optional | ||
from sqlalchemy import create_engine | ||
from sqlalchemy import ForeignKey | ||
from sqlalchemy import String | ||
from sqlalchemy.orm import DeclarativeBase | ||
from sqlalchemy.orm import Mapped | ||
from sqlalchemy.orm import mapped_column | ||
from sqlalchemy.orm import relationship | ||
|
||
|
||
class Base(DeclarativeBase): | ||
pass | ||
|
||
|
||
app = Flask(__name__) | ||
app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql://localhost/cs419project" | ||
db = SQLAlchemy(app, model_class=Base) | ||
|
||
|
||
class User(db.Model): | ||
id: Mapped[int] = mapped_column(primary_key=True) | ||
username: Mapped[str] = mapped_column(unique=True) | ||
email: Mapped[str] | ||
fullname: Mapped[Optional[str]] | ||
addresses: Mapped[List["Address"]] = relationship( | ||
back_populates="user", cascade="all, delete-orphan" | ||
) | ||
|
||
def __repr__(self) -> str: | ||
return ( | ||
f"User(id={self.id!r}, name={self.username!r}, fullname={self.fullname!r})" | ||
) | ||
|
||
|
||
class Address(db.Model): | ||
id: Mapped[int] = mapped_column(primary_key=True) | ||
email_address: Mapped[str] | ||
user_id: Mapped[int] = mapped_column(ForeignKey("user.id")) | ||
user: Mapped["User"] = relationship(back_populates="addresses") | ||
|
||
def __repr__(self) -> str: | ||
return f"Address(id={self.id!r}, email_address={self.email_address!r})" | ||
|
||
|
||
with app.app_context(): | ||
db.create_all() | ||
user = User( | ||
username="user1", | ||
email="[email protected]", | ||
) | ||
db.session.add(user) | ||
db.session.commit() |
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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,21 @@ | ||
import axios from "axios"; | ||
|
||
// Create an axios instance | ||
const api = axios.create({ | ||
baseURL: "http://localhost:5000/api", | ||
withCredentials: true, | ||
}); | ||
|
||
// Register | ||
function register(username, email, password) { | ||
console.log("hi"); | ||
return api.post("/auth/register", { username, email, password }); | ||
} | ||
|
||
// Login | ||
function login(username, password) { | ||
return api.post("/auth/login", { username, password }); | ||
} | ||
|
||
// export the service | ||
export { register, login }; |