def login(): json_data = get_json_data() username = json_data.get("username") password = json_data.get("password") dbw = DatabaseWrapper(GITOLITE_ADMIN_PATH, DATABASE_PORT) result = dbw.login(username, password) if not result: return jsonify({"error": "bad login credentials!", "exception": None}), 400 return jsonify({"token": result}), 200
def signup(): json_data = get_json_data() username = json_data.get("username") password = json_data.get("password") email = json_data.get("email") if '@' not in parseaddr(email)[1]: return jsonify({"error": "Invalid email address: "+str(email)}), 400 if len(password) < 8: return jsonify({"error": "Invalid password: must be 8 characters or more"}), 400 if len(username) < 1: return jsonify({"error": "Invalid username: cannot use an empty username"}), 400 first_name = json_data.get("firstname") last_name = json_data.get("lastname") dbw = DatabaseWrapper(GITOLITE_ADMIN_PATH, DATABASE_PORT) try: dbw.create_user(username, email, password, first_name, last_name) except UsernameAlreadyTakenError as e: return jsonify({"error": "Username is already taken!", "exception": str(e)}), 400 except EmailAlreadyTakenError as e: return jsonify({"error": "Email is already taken!", "exception": str(e)}), 400 result = dbw.login(username, password) return jsonify({"token": result}), 200