Skip to content

Commit

Permalink
Fix user registration validation to ensure valid data before creating…
Browse files Browse the repository at this point in the history
… user
  • Loading branch information
workaryangupta committed Mar 26, 2024
1 parent e50e258 commit 316c26b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mslib/mscolab/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def check_login(emailid, password):


def register_user(email, password, username):
user = User(email, username, password)
if len(str(email.strip())) == 0 or len(str(username.strip())) == 0:
return {"success": False, "message": "Your username or email cannot be empty"}
is_valid_username = True if username.find("@") == -1 else False
is_valid_email = validate_email(email)
if not is_valid_email:
Expand All @@ -167,6 +168,7 @@ def register_user(email, password, username):
user_exists = User.query.filter_by(username=str(username)).first()
if user_exists:
return {"success": False, "message": "This username is already registered"}
user = User(email, username, password)
result = fm.modify_user(user, action="create")
return {"success": result}

Expand Down

0 comments on commit 316c26b

Please sign in to comment.