def sign_in(): # Getting the data and validating it before continue. data = request.get_json() keys = ["email", "password"] if not check_input_data(data, keys): return jsonify(success=False, message="Wrong input data.") # ------------------------------------------------------------------ # if database_helper.check_valid_user(data['email'], data['password']): token = token_generator() database_helper.add_token_user(data['email'], token) return jsonify(success=True, message="Logged in.", data=token) else: return jsonify(success=False, message="Wrong username or password!")
def change_password(): token = request.headers.get("Authorization") data = request.get_json() keys = ["old_password", "new_password"] if not check_input_data(data, keys): return jsonify(success=False, message="Wrong input data.") if not database_helper.check_token(token): return jsonify(success=False, message="You must be logged in to change password!") email = database_helper.get_email_by_token(token) if database_helper.check_valid_user(email, data['old_password']): database_helper.update_password(data['new_password'], email) return jsonify(success=True, message="Password changed!") else: return jsonify(success=False, message="Wrong old password!")