-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
8 changed files
with
108 additions
and
38 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
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 |
---|---|---|
@@ -1,11 +1,44 @@ | ||
import { isMail, isUserDuplication, isMailDuplication, generateSalt, hashPassword, sendMail} from "../../../util/takoFunction.ts"; | ||
|
||
export const handler = { | ||
async POST(req) { | ||
//const data = await req.json(); | ||
const data = { | ||
"status": "success" | ||
const data = await req.json(); | ||
const UserName = data.username; | ||
const email = data.email; | ||
const CsrfToken = data.csrftoken; | ||
const error = { | ||
"status": "error" | ||
} | ||
if(true) { | ||
// | ||
} | ||
if(!isMail(email)) { | ||
return new Response(JSON.stringify(error), { | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
} | ||
if(!isMailDuplication(email)) { | ||
return new Response(JSON.stringify(error), { | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
} | ||
if(!isUserDuplication) { | ||
return new Response(JSON.stringify(error), { | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
} | ||
try { | ||
//sha256生成 | ||
const hash = "ううえええええ" | ||
result = client("くえりいいいいいいいいい") | ||
sendMail(email,"本登録を完了してください",`https://takos.jp/register?key=${hash}`) | ||
return new Response(JSON.stringify(data), { | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
} catch (error) { | ||
return new Response(JSON.stringify({"status": "error"}), { | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
} | ||
return new Response(JSON.stringify(data), { | ||
headers: { "Content-Type": "application/json" }, | ||
}); | ||
} | ||
}; |
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,49 @@ | ||
import { envRoader} from "../../util/takoFunction.ts"; | ||
import { load } from "https://deno.land/std@0.204.0/dotenv/mod.ts"; | ||
import { Client } from "https://deno.land/x/mysql@v2.12.1/mod.ts"; | ||
const env = await load(); | ||
const hostname = env["hostname"]; | ||
const username = env["username"]; | ||
const db = env["db"]; | ||
const password = env["password"]; | ||
const client = await new Client().connect({ | ||
hostname, | ||
username, | ||
db, | ||
password, | ||
}); | ||
|
||
export const handler = { | ||
async GET(req) { | ||
const url = new URL(req.url); | ||
const origin = url.searchParams.get("origin") || ""; | ||
const allows = envRoader("origin") | ||
const allow = allows.split(',') | ||
if(allow.includes(origin)){ | ||
const csrftoken = generateRandomString(128) | ||
const result = await client.execute(`INSERT INTO csrftoken VALUES (default,default,"${csrftoken}");`) | ||
return new Response(JSON.stringify({"csrftoken": csrftoken}), { | ||
headers: { "Content-Type": "application/json", | ||
"Access-Control-Allow-Origin": origin | ||
}, | ||
} | ||
); | ||
}else { | ||
return new Response(JSON.stringify({"csrftoken": "This origin is not allowed"}), { | ||
headers: { "Content-Type": "application/json", | ||
"Access-Control-Allow-Origin": origin | ||
}, | ||
} | ||
); | ||
} | ||
} | ||
}; | ||
function generateRandomString(length) { | ||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
let result = ''; | ||
for (let i = 0; i < length; i++) { | ||
const randomIndex = Math.floor(Math.random() * characters.length); | ||
result += characters.charAt(randomIndex); | ||
} | ||
return result; | ||
} |
Empty file.
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