move the character password check into a separate method
just a bit of reuse Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
parent
2ad79285b3
commit
fa56e51ce3
|
@ -144,6 +144,19 @@ class Character(models.Model):
|
|||
# character is past their old time and in the process of leveling up, calculate next based on that
|
||||
return Game.level_formula(self.level, self.next_level)
|
||||
|
||||
def check_password(self, password: str):
|
||||
"""Check that the provided password is correct for this character.
|
||||
|
||||
Used to authenicate without logging in (yet).
|
||||
|
||||
Args:
|
||||
password: the password to check
|
||||
Raises:
|
||||
ValueError: if the password is incorrect
|
||||
"""
|
||||
if not check_password(password, self.password):
|
||||
raise ValueError(f"incorrect password for character '{self.name}'!")
|
||||
|
||||
def level_up(self):
|
||||
"""Set this character's level and next time if they meet the necessary criteria.
|
||||
|
||||
|
@ -171,8 +184,7 @@ class Character(models.Model):
|
|||
"""
|
||||
if self.status != self.CHARACTER_STATUS_OFFLINE:
|
||||
raise ValueError(f"character '{self.name}' can't be logged in, isn't offline!")
|
||||
if not check_password(password, self.password):
|
||||
raise ValueError(f"incorrect password for character '{self.name}'!")
|
||||
self.check_password(password)
|
||||
|
||||
logger.debug("logging %s in...", str(self))
|
||||
# we need to apply the time lost to the next level time
|
||||
|
|
Loading…
Reference in New Issue