示例#1
0
文件: admin.py 项目: RTNelo/dev_blog
    def get(self):
        # OAth2 for douban
        KEY = conf['douban_app_key']
        SECRET = conf['douban_app_secret']
        CALLBACK = conf['url'] + '/dback'
        SCOPE = 'douban_basic_common,community_basic_user,community_basic_note'
        client = DoubanClient(KEY, SECRET, CALLBACK, SCOPE)
        douban_login = client.authorize_url

        # OAth2 for sina_weibo
        APP_KEY =  conf['weibo_app_key']
        APP_SECRET = conf['weibo_app_secret']
        CALLBACK_URL = conf['url'] + '/wback'
        weibo_client = APIClient(app_key=APP_KEY, app_secret=APP_SECRET, redirect_uri=CALLBACK_URL)
        weibo_login = weibo_client.get_authorize_url()

        # statistics
        diary_count = Diary.get_diary_count()
        last_diary = Diary.get_last_diary()
        first_diary = Diary.get_first_diary()
        comment_count = Comment.get_comment_count()

        usr = tornado.escape.xhtml_escape(self.current_user)  
        site_start = Admin.find_by_username(usr).get('site_start')
        self.render('Admin/dashboard.html', douban_login=douban_login,
                    diary_count=diary_count, last_diary=last_diary,
                    first_diary=first_diary, site_start=site_start,
                    comment_count=comment_count, weibo_login=weibo_login
                  )
示例#2
0
文件: admin.py 项目: RTNelo/dev_blog
    def post(self, *args):

        try:
            usr = self.get_argument('username')
            pas = self.get_argument('password')
        except:
            self.redirect('/login')

        try:
            rem = self.get_argument('remember')
        except:
            rem = None

        profile = Admin.find_by_username(usr)

        if profile is not None and pas == profile.get('password'):

            # Set Cookie or Session
            if rem is not None: 
                self.set_secure_cookie("user", profile.get('user'))
            else:
                self.set_secure_cookie("user", profile.get('user'), expires_days=None)

            self.redirect('/admin')
        else:
            self.redirect('/login')