예제 #1
0
    def test_gets(self):

        accounts = Account.gets([])
        assert len(accounts) == 0

        email1 = '*****@*****.**'
        password1 = 'test'
        salt1 = randbytes(4)
        passwd_hash1 = pwd_hash(salt1, password1)
        name1 = 'test'
        account1 = Account.add(email1,
                               passwd_hash1,
                               salt1,
                               name1,
                               reg_type=ACCOUNT_REG_TYPE.EMAIL)

        email2 = '*****@*****.**'
        password2 = 'test'
        salt2 = randbytes(4)
        passwd_hash2 = pwd_hash(salt2, password2)
        name2 = 'test'
        account2 = Account.add(email2,
                               passwd_hash2,
                               salt2,
                               name2,
                               reg_type=ACCOUNT_REG_TYPE.EMAIL)

        email3 = '*****@*****.**'
        password3 = 'test'
        salt3 = randbytes(4)
        passwd_hash3 = pwd_hash(salt3, password3)
        name3 = 'test'
        account3 = Account.add(email3,
                               passwd_hash3,
                               salt3,
                               name3,
                               reg_type=ACCOUNT_REG_TYPE.EMAIL)

        email4 = '*****@*****.**'
        password4 = 'test'
        salt4 = randbytes(4)
        passwd_hash4 = pwd_hash(salt4, password4)
        name4 = 'test'
        account4 = Account.add(email4,
                               passwd_hash4,
                               salt4,
                               name4,
                               reg_type=ACCOUNT_REG_TYPE.EMAIL)

        ids = [account1.id, account2.id, account3.id, account4.id]
        accounts = Account.gets(ids)

        assert len(accounts) == 4

        assert account1 in accounts
        assert account2 in accounts
        assert account3 in accounts
        assert account4 in accounts
예제 #2
0
    def add_account(self,
                    email=None,
                    mobile=None,
                    password=None,
                    name=None,
                    status=0):
        from core.models.user.consts import ACCOUNT_REG_TYPE
        from core.models.user.account import Account
        from core.models.utils import pwd_hash
        from core.models.utils import randbytes

        if not email and not mobile:
            email = '*****@*****.**'

        alias_type = ACCOUNT_REG_TYPE.MOBILE \
            if mobile else ACCOUNT_REG_TYPE.EMAIL

        alias = mobile or email
        password = password or 'test'
        salt = randbytes(4)
        passwd_hash = pwd_hash(salt, password)
        name = name or 'test'
        return Account.add(alias,
                           passwd_hash,
                           salt,
                           name,
                           reg_type=alias_type,
                           status=status)
예제 #3
0
def lily_device_binding(sqlstore, redis):
    lily = Account.add('*****@*****.**',
                       passwd_hash='lilypwd',
                       salt='test',
                       name='lily')
    device_id = 'device_of_lily'
    device_platform = Platform.android
    return DeviceBinding.create(lily, device_id, device_platform,
                                SetuptoolsVersion('1.0.1'))
예제 #4
0
 def test_add_account(self):
     email = '*****@*****.**'
     password = '******'
     salt = randbytes(4)
     passwd_hash = pwd_hash(salt, password)
     name = 'test'
     account = Account.add(email,
                           passwd_hash,
                           salt,
                           name,
                           reg_type=ACCOUNT_REG_TYPE.EMAIL)
     self.assertTrue(account)
     self.assertEqual(account.name, name)
     self.assertTrue(account.has_email())
     self.assertEqual(account.email, email)
     self.assertTrue(ACCOUNT_REG_TYPE.EMAIL in account.reg_type)
예제 #5
0
def _register_user(alias, password, reg_type, status):
    user = Account.get_by_alias(alias)
    salt = randbytes(4)
    passwd_hash = pwd_hash(salt, password)

    if user and user.need_verify():
        user.change_passwd_hash(salt, passwd_hash)
        return Account.get_by_alias(alias)
    elif user:
        return

    return Account.add(alias,
                       passwd_hash,
                       salt,
                       generate_nickname(alias, reg_type),
                       reg_type,
                       status=status)
예제 #6
0
def user(sqlstore, redis):
    return Account.add('*****@*****.**',
                       passwd_hash='foobar',
                       salt='barfoo',
                       name='user',
                       reg_type=ACCOUNT_REG_TYPE.EMAIL)