Exemplo n.º 1
0
    def add(self, email, password, ip):
        if self.get(email=email, fields='1') is not None:
            raise self.DeplicateUser('duplicate username')

        now = time.time()
        if isinstance(ip, str):
            ipVersion = utils.isIP(ip)
            ip = utils.ip2varbinary(ip, ipVersion)
        userkey = umsgpack.unpackb(crypto.password_hash(password))[0]

        hash = MD5.new()
        hash.update(password.encode('utf-8'))
        password_md5 = hash.hexdigest()

        insert = dict(
            email=email,
            email_verified=0,
            password=crypto.aes_encrypt(crypto.password_hash(password),
                                        userkey),
            userkey=crypto.aes_encrypt(userkey),
            nickname=None,
            role=None,
            ctime=now,
            mtime=now,
            atime=now,
            cip=ip,
            mip=ip,
            aip=ip,
            password_md5=password_md5,
        )
        return self._insert(**insert)
Exemplo n.º 2
0
Arquivo: base.py Projeto: zdqd/qiandao
 def ip2varbinary(self):
     return utils.ip2varbinary(self.request.remote_ip,
                               utils.isIP(self.request.remote_ip))