@tornado.gen.coroutine
    def post(self, key):
        res = yield motor.Op(self.application.mongodb.pwrecover.find_one,
                             { 'key':key })
        if not res:
            raise tornado.web.HTTPError(404)
        uid = res['_id']

        # Apply canonicalizations to the passwords.
        password = self.get_argument('password', '')
        password = unicodedata.normalize('NFKC', password)
        password = password.encode()  # to UTF8 bytes
        password2 = self.get_argument('password2', '')
        password2 = unicodedata.normalize('NFKC', password2)
        password2 = password2.encode()  # to UTF8 bytes
        
        formerror = None
        formfocus = 'name'
        
        if self.twsessionstatus == 'auth':
            formerror = 'You are already signed in!'
        elif (not password):
            formerror = 'You must enter your new password.'
            formfocus = 'password'
        elif (not password2):
            formerror = 'You must enter your new password twice.'
            formfocus = 'password2'
        elif (len(password) < 6):
            formerror = 'Please use at least six characters in your password.'
            formfocus = 'password'
        elif (len(password) > 128):
            formerror = 'Please use no more than 128 characters in your password.'
            formfocus = 'password'
        elif (password != password2):
            formerror = 'The passwords you entered were not the same.'
            password2 = ''
            formfocus = 'password2'

        if formerror:
            self.render('recover2.html', key=key, formerror=formerror)
            return

        try:
            yield self.application.twsessionmgr.change_password(uid, password)
            # Success.
            yield motor.Op(self.application.mongodb.pwrecover.remove,
                           { 'key':key })
            formerror = None
        except MessageException as ex:
            formerror = str(ex)

        if formerror:
            self.render('recover2.html', key=key, formerror=formerror)
            return

        self.render('recover2.html', key=key, pwchanged=True)
dataset/ETHPy150Open erkyrath/tworld/lib/tweblib/handlers.py/Recover2Handler.post/original