feat: implement user registration API and connect to UI
This commit is contained in:
@ -118,7 +118,15 @@ async function handleLogin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function handleRegister() {
|
async function handleRegister() {
|
||||||
// TODO: Implement register logic
|
try {
|
||||||
console.log('Registering with data:', registerForm);
|
const response = await $fetch('/api/register', {
|
||||||
|
method: 'POST',
|
||||||
|
body: registerForm
|
||||||
|
});
|
||||||
|
message.value = response.message;
|
||||||
|
showLogin();
|
||||||
|
} catch (error: any) {
|
||||||
|
message.value = error.data?.message || '注册失败';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
21
server/api/register.post.ts
Normal file
21
server/api/register.post.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { defineEventHandler, readBody, setResponseStatus } from 'h3';
|
||||||
|
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const body = await readBody(event);
|
||||||
|
|
||||||
|
const { name, gender, contact, idCard, password } = body;
|
||||||
|
|
||||||
|
if (!name || !gender || !contact || !idCard || !password) {
|
||||||
|
setResponseStatus(event, 400);
|
||||||
|
return {
|
||||||
|
message: '请填写完整信息',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Add database logic to save the user
|
||||||
|
console.log('Registering new user:', { name, gender, contact, idCard });
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: '注册成功!',
|
||||||
|
};
|
||||||
|
});
|
Reference in New Issue
Block a user