コード例 #1
0
    def test_register_user(self):
        with self.app_context:
            user = User.register(email="*****@*****.**", password="******")

            user.save()

            user_test = User.get_by_id(user.id)
            self.assertIsNotNone(user_test.access_token)
            self.assertEqual(user.email, "*****@*****.**")
            self.assertTrue(check_password_hash(user.password, "paco"))

            User.remove(user.id)
コード例 #2
0
def register_user():
    email = request.json.get('email')
    password = request.json.get('password')

    if not email_is_valid(email):
        response_data = create_response_error(
            'InvalidEmail',
            'This email is invalid',
            409
        )

        return jsonify(response_data)

    if not password:
        response_data = create_response_error(
            'InvalidPassword',
            'This password is invalid',
            409
        )

        return jsonify(response_data)

    try:
        user = User.register(email, password)
    except User.EmailAlreadyInUse:
        response_data = create_response_error(
            'UsedEmail',
            'This email is already in use',
            409
        )
        return jsonify(response_data)

    user.save()
    g.user = user

    # Create a Friends default group for the user
    # This group has the same id as the user id
    friends_group = Group.create(group_id=user.id,
                                 name="Friends",
                                 creator=user.id)

    friends_group.save()

    response_data = create_response_data(
        user.to_dict(),
        200
    )
    return jsonify(response_data), response_data['status_code']