def register(): data = json.loads(request.data) email = data['email'] username = data['name'] password = data['password'] try: app.logger.debug("Registration attempt ('%s', '%s')" % (username, email)) if (db.email_exists(email)): app.logger.debug("Registration for '%s' failed - email already taken" % email) return jsonify({"success":False, "error_message":"email already registered"}), 409 if (db.username_exists(username)): app.logger.debug("Registration for '%s' failed - username already taken" % username) return jsonify({"success":False, "error_message":"username already taken"}), 409 if (len(password) < 8): app.logger.debug("Registration for '%s' failed - password too short" % username) return jsonify({"success":False, "error_message":"password too short"}), 422 if (len(password) > 64): app.logger.debug("Registration for '%s' failed - password too long" % username) return jsonify({"success":False, "error_message":"password too long"}), 422 db.add_new_user(email, username, password) app.logger.info("Registered new user ('%s', '%s')" % (username, email)) return jsonify({"success":True}), 201 except Exception as e: app.logger.error("Error while processing registration ('%s', '%s')\n%s" % (username, email, e)) return jsonify({"success":False, "error_message":"internal server error"}), 500
def register_user(user_name, password, e_mail, country, city, avatar_image): if db.email_exists(e_mail): return jsonify({"response": ["E-Mail Already Registered"]}) elif db.user_name_exists(user_name): return jsonify({"response": ["User Name Taken"]}) else: db.add_new_user(user_name, password, e_mail, country, city, avatar_image) return jsonify({"response": ["Success"]})
def update_user_data(original_user_name, original_e_mail, new_user_name, new_e_mail, new_password, new_country, new_city, new_location, new_image): response = "Success" if original_user_name != new_user_name and db.user_name_exists(new_user_name): response = "User Name Exists" elif original_e_mail != new_e_mail and db.email_exists(new_e_mail): response = "E-Mail Exists" else: db.update_user_data(original_user_name, new_user_name, new_e_mail, new_password, new_country, new_city, new_location, new_image) return jsonify({"response": [response]})
def update_user_data(original_user_name, original_e_mail, new_user_name, new_e_mail, new_password, new_country, new_city, new_location, new_image): response = "Success" if original_user_name != new_user_name and db.user_name_exists(new_user_name): response = "User Name Exists" elif original_e_mail != new_e_mail and db.email_exists(new_e_mail): response = "E-Mail Exists" else: db.update_user_data(original_user_name, new_user_name, new_e_mail, new_password, new_country, new_city, new_location, new_image) return {"response": response}
def register(): firstName = input('\nWhat is your first name? \t') lastName = input('What is your last name? \t') email = input('\nEnter your email address: \t') if db.email_exists(email): print("This email already exists in our records, try logging in") return False else: # newPassword = input('\nCreate a new password:\t') newPassword = getpass('Create a new password: \t') newAccount = accountGen() newBalance = 0.00 newUser = [firstName, lastName, email, newPassword, str(newBalance)] db.create(newAccount, newUser) print( f'\nWelcome to Divus Bank, your new Account Number is {newAccount} \n' ) return True
def user_exists(): data = json.loads(request.data) email = data['email'] app.logger.debug("Check if email '%s' exists" % email) return jsonify({"success":True, "response":db.email_exists(email)}), 200