예제 #1
0
def note_user(username, number, password, password1):
    """
    简单判断输入框中字段是否填写, 判断数据库中用户名是否存在, 并注册
    :param username:
    :param number:
    :param password:
    :param password1:
    :return:
    """
    msg = ''
    if username and number and password:
        # 判断用户名是否存在, 如果存在 则注册不成功
        if not User.is_exists(username):
            if password == password1:
                # 注册成功
                User.add_user(username, hash_data(password), number)
                session.commit()
            else:
                msg = 'password is not =='
                return msg
        else:
            msg = 'username is life'
            return msg
    else:
        msg = 'letter is not all'
        return msg
예제 #2
0
 def del_upload_img(cls, pid, user_id):
     post = Post.get_post(pid)
     os.remove('static/{}'.format(post.img_url))
     os.remove('static/{}'.format(post.thumb_url))
     session.execute('DELETE FROM posts WHERE id={} AND user_id={}'.format(
         pid, user_id))
     session.commit()
     return True
예제 #3
0
 def add_user(cls, username, password, number):
     """
     添加用户
     :param username:
     :param password:
     :param number:
     :return:
     """
     session.add(User(username=username, password=password, number=number))
     session.commit()
예제 #4
0
 def add_like(cls, user_id, post_id):
     """
     添加喜欢
     :param user_id:
     :param post_id:
     :return:
     """
     session.add(Like(user_id=user_id, post_id=post_id))
     session.commit()
     return True
예제 #5
0
 def add_atte(cls, m_id, y_id):
     """
     添加关注
     :param m_id: 关注人
     :param y_id: 被关注人
     :return:
     """
     data = Atte(m_id=m_id, y_id=y_id)
     session.add(data)
     session.commit()
     return True
예제 #6
0
 def del_like(cls, user_id, post_id):
     """
     再次点击红心 删除喜欢
     :param user_id:
     :param post_id:
     :return:
     """
     like = session.query(cls).filter(cls.user_id == user_id,
                                      cls.post_id == post_id).first()
     session.delete(like)
     session.commit()
예제 #7
0
 def delete_atte(cls, m_id, y_id):
     """
     删除关注用户
     :param m_id:
     :param y_id:
     :return:
     """
     data = session.query(cls).filter(cls.m_id == m_id,
                                      cls.y_id == y_id).first()
     session.delete(data)
     session.commit()
     return True
예제 #8
0
def add_post_db(img_url, thumb_url, user_name):
    """
    将路径添加到post表中
    :param img_url:
    :param thumb_url:
    :param user_name:
    :return:
    """
    user = session.query(User.id).filter(User.username == user_name).first()
    post = Post(img_url=img_url, thumb_url=thumb_url, user_id=user.id)
    session.add(post)
    session.commit()
    # 返回post.id为了上传成功后直接跳到大图页
    return post
예제 #9
0
def del_upload_img(pid, user_id):
    """
    删除自己上传的图片
    :param pid:
    :param user_id:
    :return:
    """
    post = get_post(pid)
    os.remove('static/{}'.format(post.img_url))
    os.remove('static/{}'.format(post.thumb_url))
    session.execute('DELETE FROM posts WHERE id={} AND user_id={}'.format(
        pid, user_id))
    session.commit()
    return True