Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Googleログイン追加準備】user_nameの利用箇所の削除 #26

Merged
merged 6 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/components/icons/GoogleLogoIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default function GoogleLogoIcon() {
return (
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 48 48">
<path fill="#EA4335" d="M24 9.5c3.54 0 6.71 1.22 9.21 3.6l6.85-6.85C35.9 2.38 30.47 0 24 0 14.62 0 6.51 5.38 2.56 13.22l7.98 6.19C12.43 13.72 17.74 9.5 24 9.5z"></path>
<path fill="#4285F4" d="M46.98 24.55c0-1.57-.15-3.09-.38-4.55H24v9.02h12.94c-.58 2.96-2.26 5.48-4.78 7.18l7.73 6c4.51-4.18 7.09-10.36 7.09-17.65z"></path>
<path fill="#FBBC05" d="M10.53 28.59c-.48-1.45-.76-2.99-.76-4.59s.27-3.14.76-4.59l-7.98-6.19C.92 16.46 0 20.12 0 24c0 3.88.92 7.54 2.56 10.78l7.97-6.19z"></path>
<path fill="#34A853" d="M24 48c6.48 0 11.93-2.13 15.89-5.81l-7.73-6c-2.15 1.45-4.92 2.3-8.16 2.3-6.26 0-11.57-4.22-13.47-9.91l-7.98 6.19C6.51 42.62 14.62 48 24 48z"></path>
<path fill="none" d="M0 0h48v48H0z"></path>
</svg>
)
}
23 changes: 13 additions & 10 deletions app/routes/_layout.archives.edit.$postId.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ClientOnly } from "remix-utils/client-only";
import MarkdownEditor from "~/components/MarkdownEditor.client";
import { useState } from "react";
import { marked } from 'marked';
import { requireUserId } from "~/modules/session.server";
import { getSession, requireUserId } from "~/modules/session.server";
import * as diff from 'diff';
import { createEmbedding } from "~/modules/embedding.server";

Expand All @@ -20,7 +20,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
where : { postId: Number(postId) },
select : {
postId: true,
userName: true,
userId: true,
lastHeartBeatAtUTC: true
},
});
Expand All @@ -39,10 +39,10 @@ export async function loader({ params, request }: LoaderFunctionArgs) {

if (nowEditingInfo){
const userName = await prisma.userProfiles.findUniqueOrThrow({
select: { userName: true },
select: { userId: true },
where: { userId },
});
if (nowEditingInfo.userName === userName.userName){
if (nowEditingInfo.userId === userName.userId){
isEditing = false;
}
}
Expand All @@ -55,7 +55,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
postMarkdown: null,
tagNames: null,
allTagsForSearch: null,
editingUserName: nowEditingInfo.userName,
editingUserName: nowEditingInfo.userId,
postId,
isEditing: true,
userName: null,
Expand All @@ -71,14 +71,14 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
});
}
const userName = await prisma.userProfiles.findUniqueOrThrow({
select: { userName: true },
select: { userId: true },
where: { userId },
});

await prisma.nowEditingPages.create({
data: {
postId: Number(postId),
userName: userName.userName,
userId: userName.userId,
},
});

Expand Down Expand Up @@ -132,7 +132,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
select: {
postRevisionNumber: true,
postEditDateJst: true,
editorUserName: true,
editorUserId: true,
postTitleBeforeEdit: true,
postTitleAfterEdit: true,
postContentBeforeEdit: true,
Expand All @@ -147,7 +147,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
tagNames,
postMarkdown,
allTagsForSearch,
userName: userName.userName,
userName: userName.userId,
editingUserName:null,
isEditing:false,
postId,
Expand Down Expand Up @@ -314,7 +314,7 @@ export default function EditPost() {
<tr key={edit.postRevisionNumber}>
<td className="border px-2 py-2">{edit.postRevisionNumber}</td>
<td className="border px-2 py-2">{edit.postEditDateJst.toLocaleString()}</td>
<td className="border px-2 py-2">{edit.editorUserName}</td>
<td className="border px-2 py-2">{edit.editorUserId.slice(0,8)}</td>
<td className="border px-2 py-2">
{diff.diffChars(edit.postTitleBeforeEdit, edit.postTitleAfterEdit).map((part, index) => {
if (part.added || part.removed) {
Expand Down Expand Up @@ -363,6 +363,8 @@ export async function action({ request, params }: ActionFunctionArgs) {
const postContent = formData.get("postContent")?.toString() || "";
const tags = formData.getAll("tags") as string[];
const userName = formData.get("userName")?.toString() || "";
const session = await getSession(request.headers.get('Cookie'));
const userId = session.get('userId');

const postId = Number(params.postId);

Expand Down Expand Up @@ -429,6 +431,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
postId,
postRevisionNumber: newRevisionNumber,
editorUserName: userName,
editorUserId: userId,
postTitleBeforeEdit: latestPost.postTitle,
postTitleAfterEdit: postTitle,
postContentBeforeEdit: latestPost.postContent,
Expand Down
41 changes: 2 additions & 39 deletions app/routes/_layout.signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,11 @@ export async function action({ request }: ActionFunctionArgs) {
const form = await request.formData();
const email = form.get("email")?.toString();
const password = form.get("password")?.toString();
const username = form.get("username")?.toString();

if (!email || !password || !username) {
if (!email || !password ) {
return json({ status: 500, message: "Email, password and username are required" });
}

const isUserNameExist = await prisma.userProfiles.findFirst({
where: {
userName: username,
},
});

if (isUserNameExist) {
return json({ status: 500, message: "ユーザー名が既に登録されています" });
}

const url = new URL(request.url);
const origin = url.origin;
const emailRedirectTo = `${origin}/login`;
Expand All @@ -47,16 +36,13 @@ export async function action({ request }: ActionFunctionArgs) {
}

try {
console.log(userId, username, email)
await prisma.userProfiles.create({
data: {
userId: userId,
userName: username,
userEmail: email,
},
});
} catch (error) {
console.log(error)
return json({ status: 500, message: "ユーザー登録に失敗しました" });
}

Expand All @@ -66,12 +52,11 @@ export async function action({ request }: ActionFunctionArgs) {
export default function Component() {
const actionData = useActionData<typeof action>();
const [isRegistering, setIsRegistering] = useState(false);
const [userName, setUserName] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [passwordError, setPasswordError] = useState("");

const isDisabled = !email || !password || !userName || passwordError !== "";
const isDisabled = !email || !password || passwordError !== "";

const handlePasswordChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const newPassword = e.target.value;
Expand All @@ -94,28 +79,6 @@ export default function Component() {
onSubmit={() => setIsRegistering(true)}
>
<H1>ユーザー新規登録</H1>
<div className="mb-4">
<label
htmlFor="username"
className="block mb-2 font-bold text-base-content"
>
ユーザー名:
</label>
<input
type="text"
id="username"
name="username"
className={`w-full px-3 py-2 text-base-content border rounded-md focus:outline-none ${
userName ? "focus:border-blue-500" : "border-red-500"
}`}
value={userName}
onChange={(e) => setUserName(e.target.value)}
required
/>
{!userName && (
<p className="text-red-500 text-sm mt-1">ユーザー名を入力してください。</p>
)}
</div>
<div className="mb-4">
<label htmlFor="email" className="block mb-2 font-bold text-base-content">
メールアドレス:
Expand Down
7 changes: 3 additions & 4 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ model FctCommentVoteHisotry {

model userProfiles {
userId String @id @map("user_id") @db.Uuid
userName String @unique @map("user_name")
userCreatedAt DateTime @default(now()) @map("user_created_at") @db.Timestamptz(6)
userEmail String @unique @map("user_email")
now_editing_pages nowEditingPages[]
Expand All @@ -90,10 +89,10 @@ model userProfiles {

model nowEditingPages {
postId Int @id @unique @default(autoincrement()) @map("post_id")
userName String @map("user_name")
userId String @map("user_id")
lastHeartBeatAtUTC DateTime @default(dbgenerated("(now() AT TIME ZONE 'utc'::text)")) @map("last_heart_beat_at_utc") @db.Timestamptz(6)
dim_posts DimPosts @relation(fields: [postId], references: [postId], onDelete: Cascade, onUpdate: Cascade, map: "public_now_editing_pages_post_id_fkey")
user_profiles userProfiles @relation(fields: [userName], references: [userName], onDelete: Cascade, map: "public_now_editing_pages_user_name_fkey")
user_profiles userProfiles @relation(fields: [userId], references: [userId], onDelete: Cascade, map: "public_now_editing_pages_user_id_fkey")

@@map("now_editing_pages")
}
Expand Down Expand Up @@ -127,7 +126,7 @@ model FctPostEditHistory {
postRevisionNumber Int @map("post_revision_number")
postEditDateJst DateTime @default(dbgenerated("(now() AT TIME ZONE 'jst'::text)")) @map("post_edit_date_jst") @db.Timestamptz(6)
postEditDateGmt DateTime @default(dbgenerated("(now() AT TIME ZONE 'utc'::text)")) @map("post_edit_date_gmt") @db.Timestamptz(6)
editorUserName String @map("editor_user_name") @db.VarChar(255)
editorUserId String @map("editor_user_id")
postTitleBeforeEdit String @map("post_title_before_edit") @db.VarChar(255)
postTitleAfterEdit String @map("post_title_after_edit") @db.VarChar(255)
postContentBeforeEdit String @map("post_content_before_edit")
Expand Down
Loading