Changing the user login command to use the player's email address instead of username. Also Require quotes around the username with the character creation command regardless of whether it's two words or one.

This commit is contained in:
Greg Taylor 2007-04-03 15:17:46 +00:00
parent 5a48c2e30b
commit 50b17b3626
4 changed files with 34 additions and 15 deletions

View file

@ -10,25 +10,32 @@ def cmd_connect(cdat):
This is the connect command at the connection screen. Fairly simple, This is the connect command at the connection screen. Fairly simple,
uses the Django database API and User model to make it extremely simple. uses the Django database API and User model to make it extremely simple.
""" """
session = cdat['session'] session = cdat['session']
uname = cdat['uinput']['splitted'][1]
if len(cdat['uinput']['splitted']) != 3:
session.msg("Missing arguments!")
return
uemail = cdat['uinput']['splitted'][1]
password = cdat['uinput']['splitted'][2] password = cdat['uinput']['splitted'][2]
# Match an email address to an account.
email_matches = functions_db.get_dbref_from_email(uemail)
account = User.objects.filter(username__iexact=uname) autherror = "Specified email does not match any accounts!"
autherror = "Invalid username or password!"
# No username match # No username match
if account.count() == 0: if email_matches.count() == 0:
session.msg(autherror) session.msg(autherror)
return return
# We have at least one result, so we can check hte password. # We have at least one result, so we can check the password.
user = account[0] user = email_matches[0]
if not user.check_password(password): if not user.check_password(password):
session.msg(autherror) session.msg(autherror)
else: else:
user = account[0] user = email_matches[0]
uname = user.username uname = user.username
session.login(user) session.login(user)
@ -38,15 +45,21 @@ def cmd_create(cdat):
""" """
session = cdat['session'] session = cdat['session']
server = session.server server = session.server
uname = cdat['uinput']['splitted'][1] quote_split = ' '.join(cdat['uinput']['splitted']).split("\"")
email = cdat['uinput']['splitted'][2] uname = quote_split[1]
password = cdat['uinput']['splitted'][3] lastarg_split = quote_split[2].split()
email = lastarg_split[0]
password = lastarg_split[1]
# Search for a user object with the specified username. # Search for a user object with the specified username.
account = User.objects.filter(username=uname) account = User.objects.filter(username=uname)
# Match an email address to an account.
email_matches = functions_db.get_dbref_from_email(email)
if not account.count() == 0: if not account.count() == 0:
session.msg("There is already a player with that name!") session.msg("There is already a player with that name!")
elif not email_matches.count() == 0:
session.msg("There is already a player with that email address!")
elif len(password) < 3: elif len(password) < 3:
session.msg("Your password must be 3 characters or longer.") session.msg("Your password must be 3 characters or longer.")
else: else:

Binary file not shown.

View file

@ -122,6 +122,12 @@ def is_dbref(dbstring):
else: else:
return True return True
def get_dbref_from_email(uemail):
"""
Returns a player's dbref when given an email address.
"""
return User.objects.filter(email__iexact=uemail)
def get_object_from_dbref(dbref): def get_object_from_dbref(dbref):
""" """
Returns an object when given a dbref. Returns an object when given a dbref.

View file

@ -78,14 +78,14 @@ class PlayerSession(async_chat):
def game_connect_screen(self, session): def game_connect_screen(self, session):
""" """
Show our banner screen. Show the banner screen.
""" """
buffer = '-'*50 buffer = '-'*50
buffer += ' \n\rWelcome to Evennia!\n\r' buffer += ' \n\rWelcome to Evennia!\n\r'
buffer += '-'*50 + '\n\r' buffer += '-'*50 + '\n\r'
buffer += """Please type one of the following to begin:\n\r buffer += """Please type one of the following to begin:\n\r
connect <username> <password>\n\r connect <email> <password>\n\r
create <username> <email> <password>\n\r""" create \"<username>\" <email> <password>\n\r"""
buffer += '-'*50 buffer += '-'*50
session.msg(buffer) session.msg(buffer)