mirror of
https://gitea.gofwd.group/dstrawsb/ballistic-builder.git
synced 2025-12-06 02:36:44 -05:00
more users stuff
This commit is contained in:
35
src/actions/userActions.ts
Normal file
35
src/actions/userActions.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
"use server";
|
||||||
|
import { eq, not , asc} from "drizzle-orm";
|
||||||
|
import { revalidatePath } from "next/cache";
|
||||||
|
import { db } from "@db/index";
|
||||||
|
import { usersMerged } from "@schemas/schema";
|
||||||
|
|
||||||
|
export const getData = async () => {
|
||||||
|
const data = await db.select().from(usersMerged).orderBy(asc(usersMerged.email));
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const addUser = async ( first_name: string, last_name: string, username: string, email: string, password_hash : string) => {
|
||||||
|
await db.insert(usersMerged).values({
|
||||||
|
first_name : first_name, last_name: last_name, username: username, email: email, password_hash : password_hash
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteUser = async (id: string) => {
|
||||||
|
await db.delete(usersMerged).where(eq(usersMerged.id, id));
|
||||||
|
revalidatePath("/");
|
||||||
|
};
|
||||||
|
|
||||||
|
export const editUser = async (id: string, first_name: string, last_name: string, username: string, email : string, password_hash: string) => {
|
||||||
|
await db
|
||||||
|
.update(usersMerged)
|
||||||
|
.set({
|
||||||
|
first_name : first_name,
|
||||||
|
last_name: last_name,
|
||||||
|
username: username,
|
||||||
|
email: email,
|
||||||
|
password_hash: password_hash
|
||||||
|
})
|
||||||
|
.where(eq(usersMerged.id, id));
|
||||||
|
revalidatePath("/");
|
||||||
|
};
|
||||||
@@ -3,7 +3,6 @@ import constants from "@src/lib/constants";
|
|||||||
export default function About() {
|
export default function About() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
||||||
(
|
(
|
||||||
<section id="about" className="bg-gray-200 py-20">
|
<section id="about" className="bg-gray-200 py-20">
|
||||||
<div className="container mx-auto px-6 text-center">
|
<div className="container mx-auto px-6 text-center">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { db } from '../../../../db';
|
import { db } from '@db/index';
|
||||||
import { users } from '../../../../drizzle/schema';
|
import { usersMerged } from '@schemas/schema';
|
||||||
import bcrypt from 'bcryptjs';
|
import bcrypt from 'bcryptjs';
|
||||||
import { eq } from 'drizzle-orm';
|
import { eq } from 'drizzle-orm';
|
||||||
|
|
||||||
@@ -14,9 +14,9 @@ export async function POST(request: Request) {
|
|||||||
username,
|
username,
|
||||||
email,
|
email,
|
||||||
passwordHash: hashedPassword,
|
passwordHash: hashedPassword,
|
||||||
} satisfies typeof users.$inferInsert;
|
} satisfies typeof usersMerged.$inferInsert;
|
||||||
|
|
||||||
await db.insert(users).values(newUser);
|
await db.insert(usersMerged).values(newUser);
|
||||||
|
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
{ message: 'User created successfully', redirect: '/' },
|
{ message: 'User created successfully', redirect: '/' },
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export default function RegistrationForm() {
|
|||||||
try {
|
try {
|
||||||
// Add your registration API call here
|
// Add your registration API call here
|
||||||
console.log('Form submitted:', formData)
|
console.log('Form submitted:', formData)
|
||||||
router.push('/login') // Redirect to login after successful registration
|
router.push('/signin') // Redirect to login after successful registration
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError('Failed to register user')
|
setError('Failed to register user')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ export const userskeep = pgTable("users-keep", {
|
|||||||
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
|
id: bigserial({ mode: "bigint" }).primaryKey().notNull(),
|
||||||
username: varchar({ length: 50 }).notNull(),
|
username: varchar({ length: 50 }).notNull(),
|
||||||
email: varchar({ length: 255 }).notNull(),
|
email: varchar({ length: 255 }).notNull(),
|
||||||
|
|
||||||
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
|
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
|
||||||
firstName: varchar("first_name", { length: 50 }),
|
firstName: varchar("first_name", { length: 50 }),
|
||||||
lastName: varchar("last_name", { length: 50 }),
|
lastName: varchar("last_name", { length: 50 }),
|
||||||
@@ -59,9 +58,9 @@ export const usersMerged = pgTable("users-merged", {
|
|||||||
username: varchar({ length: 50 }).notNull(),
|
username: varchar({ length: 50 }).notNull(),
|
||||||
email: varchar({ length: 255 }).notNull(),
|
email: varchar({ length: 255 }).notNull(),
|
||||||
emailVerifiedOn: timestamp("emailVerified", { mode: "date" }),
|
emailVerifiedOn: timestamp("emailVerified", { mode: "date" }),
|
||||||
passwordHash: varchar("password_hash", { length: 255 }).notNull(),
|
password_hash: varchar("password_hash", { length: 255 }).notNull(),
|
||||||
firstName: varchar("first_name", { length: 50 }),
|
first_name: varchar("first_name", { length: 50 }),
|
||||||
lastName: varchar("last_name", { length: 50 }),
|
last_name: varchar("last_name", { length: 50 }),
|
||||||
profilePicture: varchar("profile_picture", { length: 255 }),
|
profilePicture: varchar("profile_picture", { length: 255 }),
|
||||||
dateOfBirth: date("date_of_birth"),
|
dateOfBirth: date("date_of_birth"),
|
||||||
phoneNumber: varchar("phone_number", { length: 20 }),
|
phoneNumber: varchar("phone_number", { length: 20 }),
|
||||||
|
|||||||
Reference in New Issue
Block a user