Beispiel #1
0
 def get_current_user(self):
     if self.session:
         user_name = self.session.get('user')
         if user_name:
             user = User.get_user_by_name(user_name)
             if not user:
                 self.session.set(user=None)
             return user
Beispiel #2
0
    def post(self):
        username = self.get_argument('u', None)
        password = self.get_argument('p', '')
        user = User.login(username, password)
        if user:
            session = self.create_user_session(user)
            session.set(user=username)
            return self.redirect('/')

        # login error
        self.render('login.html', error_message=u"用户名或密码错误", username=username, password=password)