feat: implement user registration API and connect to UI

This commit is contained in:
2025-06-18 16:01:28 +08:00
parent ca74d9a400
commit 0d98d4f0c2
2 changed files with 31 additions and 2 deletions

View File

@ -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>

View 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: '注册成功!',
};
});