Exemple #1
0
 def get(self):
     user = users.get_current_user()
     username = None
     if not user:
         login = users.create_login_url(self.request.uri)
     else:
         if User.find(user) is None:
             User.create(user)
             self.redirect('/profile')
         username = user.nickname()
         login = users.create_logout_url(self.request.uri)
     params = {
         'title': 'Main Page',
         'login': login,
         'username': username
     }
     self.response.out.write(Render.render('index.html', params))
Exemple #2
0
 def post(self):
     user = users.get_current_user()
     user_db = User.find(user)
     logging.info(self.request.get('display_name'))
     user_db.nick = self.request.get('display_name')
     user_db.car_number = self.request.get('car_number')
     user_db.put()
     self.redirect('/profile')
Exemple #3
0
 def post(self):
     upload_files = self.get_uploads('car_photo')
     logging.info(upload_files.__len__())
     blob_info = upload_files[0]
     user = users.get_current_user()
     user_db = User.find(user)
     user_db.car_photo_blob_id = blob_info.key()
     user_db.put()
     self.redirect('/profile')
Exemple #4
0
def crawl_user_info(user: User) -> bool:
    """
    爬取用户题数
    :param user:
    :return 如果变动返回True,否则返回False
    """
    url = HDU_URL + '/userstatus.php?user='******'Problems Solved</td><td align=center>(.*?)<', re.S)
    item = re.findall(pattern, content)
    solved_num = int(item[0])
    if solved_num != user.solved_num:
        user.solved_num = solved_num
        user.status = User.ACTIVE_STATUS
        user.update_solved_num()
        return True
    else:
        return False
Exemple #5
0
def remove_user():
    """
    删除用户
    """
    id = request.args.get('id', type=int)
    user = User()
    user.id = id

    admin = session.get('admin', None)
    current_user = session.get('user', None)
    if not admin:
        if not current_user:
            return jsonify(status=False, msg='请先登录!')
        else:
            if current_user['id'] != user.id:
                return jsonify(status=False, msg='不能删除别人账号!')
    user.remove()
    if not admin and current_user['id'] == user.id:
        session.clear()
    return jsonify(status=True)
Exemple #6
0
def put_user():
    """
    添加或者修改用户
    :return:
    """
    user = User()
    for key in user.__dict__.keys():
        if key in request.args.keys():
            user.__dict__[key] = request.args.get(key)
            if key == 'id':
                user.id = int(user.id)

    if user.id:
        for item in user.__dict__.items():
            if item[1]:
                res = __validate_user(item[0], item[1])
                if res:
                    return res
        admin = session.get('admin', None)
        current_user = session.get('user', None)
        if not (admin or current_user):
            return jsonify(status=False, msg="请先登录!")
        if not admin and current_user['id'] != user.id:
            return jsonify(status=False, msg="没有权限!")
        if user.status and not admin:
            return jsonify(status=False, msg="没有权限!")
        user.update()
        if current_user:
            if user.pwd:
                session.clear()
            else:
                for key in current_user.keys():
                    if user.__dict__[key]:
                        current_user[key] = user.__dict__[key]
                session['user'] = current_user
    else:
        for item in user.__dict__.items():
            res = __validate_user(item[0], item[1])
            if res:
                return res
        user.add()
    return jsonify(status=True)
Exemple #7
0
 def get(self):
     user = users.get_current_user()
     if user:
         user_db = User.find(user)
         blob_key = user_db.car_photo_blob_id
         if blob_key is not None:
             car_url = '/serve/%s' % blob_key.key()
         else:
             car_url = '/img/car.jpg'
         params = {
             'title': 'Main Page',
             'upload_url': blobstore.create_upload_url('/upload'),
             'nick': user_db.nick,
             'car_number': user_db.car_number,
             'car_url': car_url,
             'login': users.create_logout_url(self.request.uri),
             'username': user.nickname()
         }
         self.response.out.write(Render.render('profile.html', params))
     else:
         self.redirect('/')