Example #1
0
    def test_register_existing_account(self):
        account = Account()
        account.username = "******"
        account.email_address = "*****@*****.**"
        self.persist([account])

        rv = self.app.post(
            "/register",
            data={
                "username": "******",
                "password": "******",
                "email_address": "*****@*****.**"
            }
        )

        assert rv.status_code == 403
Example #2
0
    def test_authenticate__invalid_user(self):
        account = Account()
        account.username = "******"
        account.email_address = "*****@*****.**"
        account.password = generate_password_hash("password")
        self.persist([account])

        rv = self.app.post(
            "/authenticate",
            data={
                "username": "******",
                "password": "******",
            }
        )

        assert rv.status_code == 403
Example #3
0
    def test_authenticate__get_pub__no_key(self):
        os.environ["COUCHDROP_SERVICE__SERVICE_TOKEN"] = "key"

        account = Account()
        account.username = "******"
        account.email_address = "*****@*****.**"
        self.persist([account])

        rv = self.app.post(
            "/authenticate/get/pub",
            data={
                "username": "******",
                "service_token": "key",
            }
        )

        assert rv.status_code == 403
Example #4
0
    def test_authenticate__valid(self):
        account = Account()
        account.username = "******"
        account.email_address = "*****@*****.**"
        account.password = generate_password_hash("password")
        self.persist([account])

        rv = self.app.post(
            "/authenticate",
            data={
                "username": "******",
                "password": "******",
            }
        )

        assert rv.status_code == 200
        assert json.loads(rv.data)["token"]
Example #5
0
    def test_authenticate__get_pub__key(self):
        os.environ["COUCHDROP_SERVICE__SERVICE_TOKEN"] = "key"

        account = Account()
        account.username = "******"
        account.email_address = "*****@*****.**"
        account.endpoint__valid_public_key = "publickey"
        self.persist([account])

        rv = self.app.post(
            "/authenticate/get/pub",
            data={
                "username": "******",
                "service_token": "key",
            }
        )

        assert rv.status_code == 200
        assert json.loads(rv.data) == {
            "public_key": "publickey"
        }
Example #6
0
def register():
    username = request.form.get("username")
    email_address = request.form.get("email_address")
    password = request.form.get("password")

    #Sanitise username
    account = flask.g.db_session.query(Account).filter(
        Account.email_address == email_address).scalar()
    if account:
        return flask.jsonify(err="Email already exists"), 403

    account = flask.g.db_session.query(Account).filter(
        Account.username == username).scalar()
    if account:
        return flask.jsonify(err="Username already exists"), 403

    new_account = Account()
    new_account.username = username
    new_account.email_address = email_address
    new_account.subscription_type = "freeby"
    new_account.password = generate_password_hash(password)
    new_account.email_confirmation_code = str(uuid.uuid4())
    new_account.email_confirmation_code_accepted = False

    stripe_customer = stripe_api.stripe__create_customer(email_address)
    if stripe_customer:
        new_account.stripe_customer_id = stripe_customer["id"]
        if request.form.get("subscription_type") != "freeby":
            stripe__subscribe_customer(new_account.stripe_customer_id,
                                       request.form.get("stripe_token"),
                                       request.form.get("subscription_type"))
        new_account.subscription_type = request.form.get("subscription_type")

    flask.g.db_session.add(new_account)
    mandrill__email_confirm__email(new_account.email_address,
                                   new_account.email_address,
                                   new_account.email_confirmation_code)

    return flask.jsonify({}), 200