Пример #1
0
def login():
    """
    login handler
    """
    if not utils.check_json(request.json, 'username') \
            or \
            not utils.check_json(request.json, 'password'):
        return jsonify(status='error',
                       code=-1,
                       message='username/password error')

    username = request.json['username']
    password = request.json['password']

    # verify username and pwd
    account_db = account.Account()
    is_exist, real_pwd = account_db.get_password(username)
    if not is_exist or (int)(password) != (int)(real_pwd):
        return jsonify(status='error',
                       code=-1,
                       message='username/password error')

    expired = 7 * 24 * 60 * 60

    content = {}
    content['token'] = token.create(request.json['username'], expired)
    content['expired'] = expired

    return jsonify(status='success', code=200, data=content)
Пример #2
0
    def test_withdraw(self):
        mike = account.Account(account_number="123456", balance=100.0)

        mike.withdraw(50.0)
        self.assertAlmostEqual(mike.balance, 50.0, "balance removes money")

        with self.assertRaises(account.InsufficientFundsError, msg="Overdraft should raise insufficient funds error"):  # note you don't need an 'as'
            mike.withdraw(10.0)
Пример #3
0
def verify(token):
    """
    check whether the token is valid
    """
    try:
        data = Serializer(secret_key='secret_key').loads(token)
    except (BadSignature, SignatureExpired):
        return False

    if not utils.check_json(data, 'user'):
        return False
    exist, _ = account.Account().get_password(data['user'])

    if not exist:
        return False

    print("token success")

    return True
Пример #4
0
    def test_save(self):
        mike = account.Account(first_name="Mike", last_name="Bloom", account_number="123456")
        mike.save()

        testmike = account.Account.from_account_number("123456")
        self.assertEqual(testmike.first_name, "Mike", "Saved account is loaded from file")
Пример #5
0
    def test_creation(self):

        nobody = account.Account()
        self.assertIsNone(nobody.first_name, "default for first_name should be None")

        mike = account.Account(first_name="Mike", last_name="Bloom")