修改/api/auth/register/phone中要求用户名密码的逻辑
This commit is contained in:
12
app.py
12
app.py
@@ -2123,10 +2123,8 @@ def register_with_phone():
|
|||||||
data = request.get_json()
|
data = request.get_json()
|
||||||
phone = data.get('phone')
|
phone = data.get('phone')
|
||||||
code = data.get('code')
|
code = data.get('code')
|
||||||
password = data.get('password')
|
|
||||||
username = data.get('username')
|
|
||||||
|
|
||||||
if not all([phone, code, password, username]):
|
if not all([phone, code]):
|
||||||
return jsonify({'success': False, 'error': '所有字段都是必填的'}), 400
|
return jsonify({'success': False, 'error': '所有字段都是必填的'}), 400
|
||||||
|
|
||||||
# 验证验证码
|
# 验证验证码
|
||||||
@@ -2137,14 +2135,12 @@ def register_with_phone():
|
|||||||
if stored_code['code'] != code:
|
if stored_code['code'] != code:
|
||||||
return jsonify({'success': False, 'error': '验证码错误'}), 400
|
return jsonify({'success': False, 'error': '验证码错误'}), 400
|
||||||
|
|
||||||
if User.query.filter_by(username=username).first():
|
if User.query.filter_by(phone=phone).first():
|
||||||
return jsonify({'success': False, 'error': '用户名已存在'}), 400
|
return jsonify({'success': False, 'error': '手机号已存在'}), 400
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 创建用户
|
# 创建用户
|
||||||
user = User(username=username, phone=phone)
|
user = User(username='用户', phone=phone)
|
||||||
user.email = f"{username}@valuefrontier.temp"
|
|
||||||
user.set_password(password)
|
|
||||||
user.phone_confirmed = True
|
user.phone_confirmed = True
|
||||||
|
|
||||||
db.session.add(user)
|
db.session.add(user)
|
||||||
|
|||||||
Reference in New Issue
Block a user