本文整理汇总了Python中models.account.Account.get方法的典型用法代码示例。如果您正苦于以下问题:Python Account.get方法的具体用法?Python Account.get怎么用?Python Account.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.account.Account
的用法示例。
在下文中一共展示了Account.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: request_password
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import get [as 别名]
def request_password(self, clear_static=True, dynamic=True, repeat=False):
account = Account.get(lambda account: account.id == self.account_id)
if isinstance(account, Account):
self.static_salt = account.salt
else:
if clear_static or not self.static_salt:
self.static_salt = hashlib.sha256(os.urandom(256)).hexdigest()
if dynamic:
self.dynamic_salt = hashlib.sha256(os.urandom(256)).hexdigest()
else:
self.dynamic_salt = None
message = "Please repeat your password" if repeat else "Please type your password"
self.send_messages(OfftopicMessage(message),
PasswordRequest(self.static_salt, self.dynamic_salt))
示例2: handle
# 需要导入模块: from models.account import Account [as 别名]
# 或者: from models.account.Account import get [as 别名]
def handle(self, message={}):
"""
Handle a received message in login state
:param message:
:return:
"""
try:
BaseController.handle(self, message)
except KeyError:
key = message.get("k")
value = message.get("v")
if key != "msg" or len(value) == 0:
return
# State - Login username
if self.state == State.login_username:
account = Account.get(lambda account: account.name.lower() == value.lower())
if account:
self.account_id = account.id
self.request_password()
self.state = State.login_password
else:
self.send_offtopic("Create new account with this name y/n?")
self.account_name = value
self.state = State.create_account
# State - Login password
elif self.state == State.login_password:
account = Account[self.account_id]
if self.hash_password_with_salt(account.password, self.dynamic_salt) == value:
self.send_offtopic("Login OK")
# Set controller to menu controller
self.connection.controller = MenuController(self.connection, self.runtime, self.account_id)
return
else:
logging.info("Expected password: {}".format(
self.hash_password_with_salt(account.password, self.dynamic_salt)))
logging.info("Received password: {}".format( value))
self.send_offtopic("Login fail")
self.state = State.login_username
self.greeting()
# State - Create account
elif self.state == State.create_account:
if value.lower()[0] == "y":
self.request_password(True, False)
self.state = State.create_password
else:
self.greeting()
self.state = State.login_username
# State - Create account - password
elif self.state == State.create_password:
self.password = value
logging.info("Received password 1: {}".format(value))
self.request_password(False)
self.state = State.create_password_repeat
# State - Create account - password repeat
elif self.state == State.create_password_repeat:
dynamic_password = self.hash_password_with_salt(self.password, self.dynamic_salt)
logging.info("Received password 2: {}".format(value))
if dynamic_password == value:
self.state = State.login_username
self.send_offtopic("New account has been created, you may now login.")
self.greeting()
account = Account(name=self.account_name,
password=self.password,
salt=self.static_salt)
db.commit()
else:
self.send_offtopic("Password mismatch. Account not created.")
self.greeting()
self.state = State.login_username