@tornado.gen.coroutine
    def post(self):

        # If this flag is set, logins are restricted to administrators.
        locked = yield self.get_config_key('nologin')
        
        # If the "register" form was submitted, jump to the player-
        # registration page.
        if (self.get_argument('register', None)):
            self.redirect('/register')
            return

        # If the "guest login" form was submitted, create a guest session
        # and play.
        if (self.get_argument('guest', None)):
            try:
                if locked:
                    raise MessageException('Sign-ins are not allowed at this time.')
                (res, email) = yield self.application.twsessionmgr.create_session_guest(self)
            except MessageException as ex:
                formerror = str(ex)
                self.render('main.html', formerror=formerror)
                return
            self.application.twlog.info('Player signed in as guest: %s (session %s)', email, res)
            self.redirect('/play')
            return

        # Apply canonicalizations to the name and password.
        name = self.get_argument('name', '')
        name = unicodedata.normalize('NFKC', name)
        name = tornado.escape.squeeze(name.strip())
        password = self.get_argument('password', '')
        password = unicodedata.normalize('NFKC', password)
        password = password.encode()  # to UTF8 bytes
        
        formerror = None
        if (not name):
            formerror = 'You must enter your player name or email address.'
        elif (not password):
            formerror = 'You must enter your password.'
        if formerror:
            self.render('main.html', formerror=formerror, init_name=name)
            return

        try:
            res = yield self.application.twsessionmgr.find_player(self, name, password)
        except MessageException as ex:
            formerror = str(ex)
            self.render('main.html', formerror=formerror, init_name=name)
            return
        
        if not res:
            formerror = 'The name and password do not match.'
            self.render('main.html', formerror=formerror, init_name=name)
            return
        
        fieldname = name
        uid = res['_id']
        email = res['email']
        name = res['name']

        if locked and not res.get('admin', None):
            formerror = 'Sign-ins are not allowed at this time.'
            self.render('main.html', formerror=formerror, init_name=name)
            return            

        # Set a name cookie, for future form fill-in. This is whatever the
        # player entered in the form (name or email)
        self.set_cookie('tworld_name', tornado.escape.url_escape(fieldname),
                        expires_days=30)

        res = yield self.application.twsessionmgr.create_session(self, uid, email, name)
        self.application.twlog.info('Player signed in: %s (session %s)', email, res)
        self.redirect('/play')
dataset/ETHPy150Open erkyrath/tworld/lib/tweblib/handlers.py/MainHandler.post/original