Skip to content

Commit

Permalink
Refactor user register (#1962)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

Refactor code, improve performance

### Type of change

- [x] Refactoring

Signed-off-by: Jin Hai <[email protected]>
  • Loading branch information
JinHai-CN authored Aug 15, 2024
1 parent 7bdd5a4 commit d92e927
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions api/apps/user_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,24 @@ def user_register(user_id, user):
@validate_request("nickname", "email", "password")
def user_add():
req = request.json
if UserService.query(email=req["email"]):
return get_json_result(
data=False, retmsg=f'Email: {req["email"]} has already registered!', retcode=RetCode.OPERATING_ERROR)
if not re.match(r"^[\w\._-]+@([\w_-]+\.)+[\w-]{2,4}$", req["email"]):
return get_json_result(data=False, retmsg=f'Invaliad e-mail: {req["email"]}!',
email_address = req["email"]

# Validate the email address
if not re.match(r"^[\w\._-]+@([\w_-]+\.)+[\w-]{2,4}$", email_address):
return get_json_result(data=False,
retmsg=f'Invalid Email address: {email_address}!',
retcode=RetCode.OPERATING_ERROR)

# Check if the email address is already used
if UserService.query(email=email_address):
return get_json_result(
data=False,
retmsg=f'Email: {email_address} has already registered!',
retcode=RetCode.OPERATING_ERROR)

user_dict = {
"access_token": get_uuid(),
"email": req["email"],
"email": email_address,
"nickname": req["nickname"],
"password": decrypt(req["password"]),
"login_channel": "password",
Expand Down

0 comments on commit d92e927

Please sign in to comment.