mirror of
https://github.com/stackblitz/bolt.new
synced 2025-06-26 18:17:50 +00:00
feat: 移除手机号验证功能
This commit is contained in:
parent
2da57de786
commit
a7a7bf7a0f
@ -1,19 +1,13 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useNavigate } from '@remix-run/react';
|
||||
import { validatePhoneNumber } from '~/utils/validation';
|
||||
|
||||
export function Login() {
|
||||
const [phone, setPhone] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [phoneError, setPhoneError] = useState('');
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!validatePhoneNumber(phone)) {
|
||||
setPhoneError('请输入有效的手机号码');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const response = await fetch('/api/auth/login', {
|
||||
method: 'POST',
|
||||
@ -42,14 +36,10 @@ export function Login() {
|
||||
type="tel"
|
||||
id="phone"
|
||||
value={phone}
|
||||
onChange={(e) => {
|
||||
setPhone(e.target.value);
|
||||
setPhoneError('');
|
||||
}}
|
||||
onChange={(e) => setPhone(e.target.value)}
|
||||
required
|
||||
className="mt-1 block w-full px-3 py-2 bg-bolt-elements-background-depth-1 border border-bolt-elements-borderColor rounded-md shadow-sm focus:outline-none focus:ring-bolt-elements-button-primary-background focus:border-bolt-elements-button-primary-background"
|
||||
/>
|
||||
{phoneError && <p className="mt-2 text-sm text-red-600">{phoneError}</p>}
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="password" className="block text-sm font-medium text-bolt-elements-textPrimary">
|
||||
|
||||
@ -1,20 +1,14 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useNavigate } from '@remix-run/react';
|
||||
import { validatePhoneNumber } from '~/utils/validation';
|
||||
|
||||
export function Register() {
|
||||
const [phone, setPhone] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [confirmPassword, setConfirmPassword] = useState('');
|
||||
const [phoneError, setPhoneError] = useState('');
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleSubmit = async (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (!validatePhoneNumber(phone)) {
|
||||
setPhoneError('请输入有效的手机号码');
|
||||
return;
|
||||
}
|
||||
if (password !== confirmPassword) {
|
||||
alert('两次输入的密码不一致');
|
||||
return;
|
||||
@ -45,14 +39,10 @@ export function Register() {
|
||||
type="tel"
|
||||
id="phone"
|
||||
value={phone}
|
||||
onChange={(e) => {
|
||||
setPhone(e.target.value);
|
||||
setPhoneError('');
|
||||
}}
|
||||
onChange={(e) => setPhone(e.target.value)}
|
||||
required
|
||||
className="mt-1 block w-full px-3 py-2 bg-bolt-elements-background-depth-1 border border-bolt-elements-borderColor rounded-md shadow-sm focus:outline-none focus:ring-bolt-elements-button-primary-background focus:border-bolt-elements-button-primary-background"
|
||||
/>
|
||||
{phoneError && <p className="mt-2 text-sm text-red-600">{phoneError}</p>}
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="password" className="block text-sm font-medium text-bolt-elements-textPrimary">
|
||||
|
||||
1
app/routes/api/auth/login.ts
Normal file
1
app/routes/api/auth/login.ts
Normal file
@ -0,0 +1 @@
|
||||
|
||||
1
app/routes/api/auth/register.ts
Normal file
1
app/routes/api/auth/register.ts
Normal file
@ -0,0 +1 @@
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import knex from 'knex';
|
||||
import type { Knex } from 'knex';
|
||||
import { env } from 'node:process';
|
||||
|
||||
let db: Knex;
|
||||
|
||||
@ -21,11 +22,11 @@ function getDb() {
|
||||
return knex({
|
||||
client: 'mysql2',
|
||||
connection: {
|
||||
host: process.env.DB_HOST,
|
||||
user: process.env.DB_USER,
|
||||
password: process.env.DB_PASSWORD,
|
||||
database: process.env.DB_NAME,
|
||||
port: Number(process.env.DB_PORT) || 3306,
|
||||
host: env.DB_HOST,
|
||||
user: env.DB_USER,
|
||||
password: env.DB_PASSWORD,
|
||||
database: env.DB_NAME,
|
||||
port: Number(env.DB_PORT) || 3306,
|
||||
},
|
||||
pool: {
|
||||
min: 2,
|
||||
|
||||
21
db/migrations/20241022114400_modify_users_table.js
Normal file
21
db/migrations/20241022114400_modify_users_table.js
Normal file
@ -0,0 +1,21 @@
|
||||
export function up(knex) {
|
||||
return knex.schema.alterTable('users', function(table) {
|
||||
// 修改手机号为必填
|
||||
table.string('phone', 20).notNullable().alter();
|
||||
|
||||
// 修改用户名为选填
|
||||
table.string('username', 255).nullable().alter();
|
||||
|
||||
// 修改电子邮箱为选填
|
||||
table.string('email', 255).nullable().alter();
|
||||
});
|
||||
}
|
||||
|
||||
export function down(knex) {
|
||||
return knex.schema.alterTable('users', function(table) {
|
||||
// 恢复原来的设置
|
||||
table.string('phone', 20).nullable().alter();
|
||||
table.string('username', 255).notNullable().alter();
|
||||
table.string('email', 255).notNullable().alter();
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user