Ejemplo n.º 1
0
 def login(cls, username, password):
     user = cls.by_name(username)
     if not user:
         print 'user not found'
     else:
         print 'user found: %s ' % user.username
     if user and Secure.valid_password(username, password, user.password_hash):
         return user
Ejemplo n.º 2
0
 def get(self):
     touch_db = self.request.get('touch_db')
     if touch_db != '':
         if not self.valid_cookie_login() or self.get_login_name() != Secure.get_god_name():
             self.goto_login()
         else:
             Activity().flush(touch_db == 'reset')
             self.redirect('/')
         return 
     self.render('exercise.html', activity=Activity().content())
Ejemplo n.º 3
0
 def update(cls, subject, content, id):
     diary = None
     if id:
         diary = Diary.get_by_id(id)
     if diary:
         diary.subject = subject
         diary.content = content
     else:
         diary = Diary(subject=subject, content=content, 
             created = Secure.get_system_time())
     
     diary.put()
Ejemplo n.º 4
0
    def post(self):
        username = self.request.get('username')
        password = self.request.get('password')

        user = User.by_name(username)
        error = ''
        if not user:
            error = 'Invalid Username'
        elif not Secure.valid_password(username, password, user.password_hash):
            error = 'Invalid Password'

        if error == '':
            self.login(user)
        else:
            self.render('login.html', username = username, error = error)
Ejemplo n.º 5
0
    def get(self):
        if not self.valid_cookie_login() or self.get_login_name() != Secure.get_god_name():
            self.goto_login()
            return

        diary_id = self.request.get('id')
        if diary_id:
            diary = Diary.get_by_id(long(diary_id))
            if diary:
                op = self.request.get('op')
                if op == 'del':
                    diary.delete()
                    self.redirect('/diary')
                else:
                    self.render('newdiary.html', subject=diary.subject, 
                        content=diary.get_content(raw=True))
                    return 
        self.render('newdiary.html')
Ejemplo n.º 6
0
    def flush(self, reset = False):
        if reset:
            SportDiary.clear()
        url = 'http://i.cs.hku.hk/~wbtang/have_fun.txt'
        event_en = ['run', 'pull up', 'push up'] # , 'sit up', 'horizontal bar'
        event_cn = [u'跑步', u'引体向上', u'俯卧撑']

        self.parse_raw_data(url, event_en)
        date, activity = self.parse_database(event_en)
        x, y = self.decode_data(date, activity, since='20140911')
        img_b64 = self.draw(x, y, labels=event_en)

        cache = self.render_str('activity.html', image_activity=img_b64, 
            date = date, activity = activity, labels = event_cn,
            last_updated = Secure.get_format_system_time())
        SportDiary.insert_diary(subject = 'cache', content = repr(cache))

        return cache
Ejemplo n.º 7
0
 def register(cls, username, password):
     username = username.lower()
     password_hash = Secure.make_password_hash(username, password)
     user = User(username = username, password_hash = password_hash)
     user.put()
     return user
Ejemplo n.º 8
0
 def get_created(self):
     return Secure.format_time(self.created, 8)