def validate_change_password():
    """This function changes the password of an account based on the
     confirmation code."""
    json_values = request.json
    values_required = {"email", "password", "code"}
    response = Response(json.dumps(json_error(ResponsesREST.INVALID_INPUT.value)),
                        status=ResponsesREST.INVALID_INPUT.value, mimetype="application/json")
    if all(key in json_values for key in values_required):
        if validator_login_password.is_valid(json_values):
            account_login = Account()
            account_login.email = json_values["email"]
            account_login.password = encode_password(json_values["password"])
            result = account_login.validate_change_password(json_values["code"])
            if result == ResponsesREST.SUCCESSFUL.value:
                response = Response(status=result)
            else:
                response = Response(json.dumps(json_error(result)),
                                    status=result, mimetype="application/json")
    return response
示例#2
0
def send_message_to_account():
    """This function updates the verification code and sends it to the email."""
    json_values = request.json
    values = {"email"}
    response = Response(json.dumps(
        json_error(ResponsesREST.INVALID_INPUT.value)),
                        status=ResponsesREST.INVALID_INPUT.value,
                        mimetype="application/json")
    if all(key in json_values for key in values):
        if validator_email.is_valid(json_values):
            account = Account()
            account.email = json_values["email"]
            result = account.change_code(create_code())
            if result == ResponsesREST.SUCCESSFUL.value:
                response = Response(json.dumps({"email": account.email}),
                                    status=result,
                                    mimetype="application/json")
            else:
                response = Response(json.dumps(json_error(result)),
                                    status=result,
                                    mimetype="application/json")
    return response