Skip to content

Commit

Permalink
update user module
Browse files Browse the repository at this point in the history
  • Loading branch information
CAOLINAN committed May 22, 2018
1 parent e925ab1 commit 9208eb1
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 22 deletions.
2 changes: 1 addition & 1 deletion ulordapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def edit(self, data):
ulord_publish_data = {
"author": "justin",
"title": "第一篇技术博客",
"tag": ["blockchain", "IPFS"],
"tags": ["blockchain", "IPFS"],
"udfs_hash": "QmVcVaHhMeWNNetSLTZArmqaHMpu5ycqntx7mFZaci63VF",
"price": 0.1,
"content_type": ".txt",
Expand Down
8 changes: 4 additions & 4 deletions ulordapi/up.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def transaction(self, payer, claim_id, pay_password, isads=False):
"""

data = {
'username': payer,
'customer': payer,
'claim_id': claim_id
}
if isads:
Expand Down Expand Up @@ -271,7 +271,7 @@ def checkisbought(self, payer, claim_ids):
:return: errcode.You can query from the errcode dict.
"""
data = {
'username': payer,
'customer': payer,
'claim_ids': claim_ids
}
return self.post(self.ulord_checkbought, data)
Expand All @@ -286,7 +286,7 @@ def queryuserpublished(self, wallet_username, page=1, num=10, category=2):
:type page: int
:param num: how many pieces of data of result do you want to view?Default is 10.
:type num: int
:param category:
:param category: 0-resource,1-ads,2-all
:type category: todo need to be thinking
:return: errcode.You can query from the errcode dict.
"""
Expand All @@ -310,7 +310,7 @@ def queryuserbought(self, wallet_username, page=1, num=10, category=2):
:type page: int
:param num: how many pieces of data of result do you want to view?Default is 10.
:type num: int
:param category:
:param category: 0-resource,1-ads,2-all
:type category: todo need to be thinking
:return: errcode.You can query from the errcode dict.
"""
Expand Down
102 changes: 85 additions & 17 deletions ulordapi/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,25 @@
from ulordapi.errcode import _errcodes, return_result


class Developer():
class Developer(up.UlordHelper):
"""
basic develoer class to execute some functions
"""
def __init__(self):
def __init__(self, appkey, secret):
"""
init the developer. create a udfs helper, a ulord-helper, add a logger
:param appkey: application key
:type appkey: str
:param secret: application secret
:type secret: str
"""
up.UlordHelper.__init__(self, appkey, secret)
ulordconfig.update({
'ulord_appkey': appkey,
'ulord_secret': secret
})
config.save()
self.udfs = udfs.UdfsHelper()
self.ulord = up.UlordHelper()
self.log = logging.getLogger("Developer:")
Expand Down Expand Up @@ -176,14 +187,7 @@ class Senior (Developer):
Senior programmer to develop his application.
"""
def __init__(self, appkey, secret):
Developer.__init__(self)
ulordconfig.update({
'ulord_appkey': appkey,
'ulord_secret': secret
})
config.save()
# UlordHelper.__init__(self)
# UdfsHelper.__init__(self)
Developer.__init__(self, appkey, secret)
self.log = logging.getLogger("Developer1:")
self.log.info("Developer1 init")

Expand All @@ -198,12 +202,7 @@ def __init__(self, appkey, secret):
:param appkey:
:param secret:
"""
Developer.__init__(self)
ulordconfig.update({
'ulord_appkey':appkey,
'ulord_secret':secret
})
config.save()
Developer.__init__(self, appkey, secret)
self.log = logging.getLogger("Developer2:")
self.log.info("Developer2 init")
self.pripath = os.path.join(os.getcwd(), 'private.pem')
Expand Down Expand Up @@ -420,7 +419,7 @@ def user_publish(self, title, udfshash, amount, tags, description, usercondition
data = self.ulord.ulord_publish_data
data['author'] = current_user.wallet
data['title'] = title
data['tag'] = tags
data['tags'] = tags
data['ipfs_hash'] = udfshash
data['price'] = amount
data['pay_password'] = current_user.pay_password
Expand Down Expand Up @@ -514,6 +513,75 @@ def user_pay_ads(self, wallet, claim_id, pay_password):
"""
return self.ulord.transaction(wallet, claim_id, pay_password, True)

def user_published_num(self, wallet):
"""
the num of user has published
:param wallet: wallet name
:type wallet: str
:return: num(int)
"""
return self.ulord.querypublishnum(wallet)

def user_info_query(self, username=None, token=None):
"""
user information
:param username: username.Default is none.
:type username: str
:param token: user token.Default is none.
:type token: str
:return: dict.User info
"""
login_user = None
if token:
login_user = User.query.filter_by(token=token).first()
if int(login_user.timestamp) < time.time():
return return_result(60104)
elif username:
login_user = User.query.filter_by(username=username).first()
if login_user:
result = {
'username': login_user.username,
"cellphone": login_user.cellphone,
"Email": login_user.email
}
return return_result(reason={
'result': result
})
else:
return return_result(60002)

def user_infor_modify(self, username=None, token=None, data={}):
"""
user information
:param username: username.Default is none.
:type username: str
:param token: user token.Default is none.
:type token: str
:param data: update data
:type data: dict
:return: dict.User info
"""
login_user = None
if token:
login_user = User.query.filter_by(token=token).first()
if int(login_user.timestamp) < time.time():
return return_result(60104)
elif username:
login_user = User.query.filter_by(username=username).first()
if login_user:
result = {
'username': login_user.username,
"cellphone": login_user.cellphone,
"Email": login_user.email
}
return return_result(reason={
'result': result
})
else:
return return_result(60002)
def create_database(self, path=None):
"""
create database
Expand Down

0 comments on commit 9208eb1

Please sign in to comment.