Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Well that's what i've done, i was just reading some shit on some blog that was giving pros and cons to both
- # so my actual question is this, I have a route /register that you make a POST to.
- @user_blueprint.route('/register', methods=['POST'])
- def register():
- email = request.form['email']
- password = request.form['password']
- username = request.form['username']
- if isValidEmail(email) and isValidPassword(password) and \
- isValidUsername(username):
- user = User(
- email=email,
- password=password,
- username=username
- )
- db.session.add(user)
- db.session.commit()
- login_user(user)
- etc. etc.
- # In that I have the 3 funcs isValid...() eg:
- def isValidEmail(email):
- if len(email) > 7:
- # https://stackoverflow.com/questions/8022530/how-to-check-for-valid-email-address
- if re.match("^.+@(\[?)[a-zA-Z0-9-.]+.([a-zA-Z]{2,3}|[0-9]{1,3})(]?)$",
- email):
- if User.query.filter_by(email=email).first() is None:
- return True
- else:
- # return False "Error: user already exists"
- # return False "Error: not a valid email address"
- def isValidPassword(password):
- # https://stackoverflow.com/questions/41117733/validation-a-password-python
- pattern = re.compile('^(?=\S{6,20}$)(?=.*?\d)(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[^A-Za-z\s0-9])')
- if pattern.match(password):
- return True
- else:
- # return False "Password Requirments: 6 chars, 1 digit, 1 Uppercase, 1 special"
- # This is when i get a bit lost, I want the corresponding errors to appear below the respective inputs dynamically (as the rest of the form is dynamically built, instead of hiding/showing).
- # So i need to return false back to register and send the error message back to the client to be rendered clientside.
- # I thought about handling all the errors for the modal (username, email, password) in one function where you pass in the input element and then insert the new <p> after and then set the innerHTML to that of the error. But im not quite sure how i would do that or if that is the best way, if there is a better/nicer way that im missing, would appreciate the help.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement