Skip to content

Commit

Permalink
middleware update
Browse files Browse the repository at this point in the history
  • Loading branch information
pbastia committed Jun 9, 2023
1 parent a7c4790 commit 62ba124
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
13 changes: 6 additions & 7 deletions api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ async def root():
return {"message": "Hello World"}

@app.get("/verify_page", response_class=HTMLResponse)
async def verify_page(request: Request, email_address: str = "missing",route_prefix: str = "", auth_provider_uuid: str = "", redirect_url="test redirect"):
async def verify_page(request: Request, email_address: str = "missing",route_prefix: str = "", auth_provider_uuid: str = "", redirect_url="test redirect", validation_failed = ""):
failed_valid = True if validation_failed.lower() == 'true' else False
return templates.TemplateResponse("verify.html",
{"request": request,
"email_address": email_address,
"redirect_url": redirect_url,
"auth_provider_uuid": auth_provider_uuid,
"route_prefix": route_prefix,
"validation_failed": False})
"validation_failed": failed_valid})


@app.get("/is_verified")
Expand Down Expand Up @@ -136,7 +137,7 @@ async def verify(email_address: Annotated[str, Form()],

# TODO: will want to check whether email has already been verified instead of verifying again

if password_results is not None:
if password_results is not None and len(password_results) > 0:
verified_email_record = session.query(VerifiedEmail)\
.where(VerifiedEmail.id == email_id).first()
print('verified_email_record: {}'.format(verified_email_record))
Expand All @@ -146,13 +147,11 @@ async def verify(email_address: Annotated[str, Form()],
session.commit()

# validation succeeded
return RedirectResponse(urllib.parse.unquote(redirect_url))
return Response(status_code=200)

else:
# validation failed
return templates.TemplateResponse("verify.html", {"request": {},
"email_address": email_address,
"validation_failed": True})
return Response(status_code=401)


@app.post("/create_otp/")
Expand Down
49 changes: 40 additions & 9 deletions middleware/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,40 @@ function getMiddleware(configuration) {
const internalRouter = express.Router();

// Handle submit form endpoint with OTP
internalRouter.post("/verify", (req, res, next) => {
console.log("Verify!");
});
internalRouter.post("/verify", async (req, res, next) => {
console.log(req.body);

const verifyUrl = new URL(`${config.everifyHost}/verify`);

const data = new URLSearchParams();
data.append("one_time_password", "3625");
data.append("email_address", "[email protected]");
data.append(
"auth_provider_uuid",
"fd2e5c94f4da4c1393a6e03093e25a85@bceidboth"
);
data.append("redirect_url", host);

const response = await fetch(verifyUrl, {
method: "POST",
body: data,
});

console.log(response.status);

if (response.ok) return res.redirect(host);

// Show the user the OTP page
const verifyPageUrl = new URL(`${config.everifyHost}/verify_page`);
verifyPageUrl.searchParams.append("route_prefix", config.routePrefix);
verifyPageUrl.searchParams.append("email_address", req.claims.email);
verifyPageUrl.searchParams.append("auth_provider_uuid", req.claims.sub);
verifyPageUrl.searchParams.append("validation_failed", "true");

internalRouter.get("/verify_page", (req, res, next) => {
return "a";
//const verifyPageResponse = await fetch(verifyPageUrl);
request({
uri: verifyPageUrl,
}).pipe(res);
});

// Handle static assets for verify page
Expand Down Expand Up @@ -71,10 +99,13 @@ function getMiddleware(configuration) {
verifyPageUrl.searchParams.append("email_address", req.claims.email);
verifyPageUrl.searchParams.append("auth_provider_uuid", req.claims.sub);

//const verifyPageResponse = await fetch(verifyPageUrl);
request({
uri: verifyPageUrl,
}).pipe(res);
const verifyPageResponse = await fetch(verifyPageUrl);
// request({
// uri: verifyPageUrl,
// }).pipe(res);
const html = await verifyPageResponse.text();
res.send(html);
res.status(201);
});

return router;
Expand Down

0 comments on commit 62ba124

Please sign in to comment.