Example #1
0
def comment():
    tid = request.form.get("tid")
    content = request.form.get("content")
    comment_floor = request.form.get("comment_floor", 1)
    last_floor = session.query(Post).order_by(Post.fid.desc()).first()
    message = Post(tid=tid,
                   content=content,
                   comment_floor=int(comment_floor),
                   fid=last_floor.fid + 1,
                   like=0,
                   uid=g.uid)
    session.add(message)
    commentee = session.query(Post).filter(Post.fid == comment_floor).first()
    relation = session.query(Comment).filter(
        Comment.uid_commenter == g.uid,
        Comment.uid_commentee == commentee.uid).first()
    if commentee.uid != g.uid:
        if relation is None:
            comment = Comment(uid_commenter=g.uid,
                              uid_commentee=commentee.uid,
                              counter=1)
            session.add(comment)
        elif relation.uid_commentee != g.uid:
            relation.counter += 1
    session.commit()
    result = {
        "code": status.get("SUCCESS"),
        "message": "回复成功!",
    }
    return jsonify(result)
Example #2
0
def like():
    tid = request.form.get("tid")
    fid = request.form.get("fid")
    likeValue = int(request.form.get("like"))
    if likeValue < -2 or likeValue > 2:
        ret = {"code": status.get('ERROR'), "MESSAGE": '点赞值超过限制'}
        return jsonify(ret)
    like_uid = g.uid
    floor = session.query(Post).filter(Post.tid == tid,
                                       Post.fid == fid).first()
    liked_uid = floor.uid
    if like_uid == liked_uid:
        ret = {"code": status.get('ERROR'), "MESSAGE": '无法点赞自己'}
        return jsonify(ret)
    floor.like += likeValue
    comment = session.query(Comment).filter(
        Comment.uid_commenter == like_uid,
        Comment.uid_commentee == liked_uid).first()
    if comment is None:
        comment = Comment(uid_commenter=like_uid,
                          uid_commentee=liked_uid,
                          counter=0)
        session.add(comment)
    comment.counter += likeValue
    session.commit()
    result = {
        "code": status.get("SUCCESS"),
        "MESSAGE": "点赞成功",
    }
    return jsonify(result)
Example #3
0
def sendSecMessage():
    to_uid = request.form.get("to_uid", None)
    from_uid = g.uid
    msg_type = int(request.form.get("msg_type", 0))
    if msg_type == 0:
        message = request.form.get('message', None)
    else:
        message = request.files.get('message', None)
    if message is None or to_uid is None:
        ret = {'code': status.get('ERROR'), 'MESSAGE': '参数不合法'}
        return jsonify(ret)
    intimate1 = session.query(Comment).filter(
        Comment.uid_commentee == from_uid,
        Comment.uid_commenter == to_uid).first()
    intimate2 = session.query(Comment).filter(
        Comment.uid_commentee == to_uid,
        Comment.uid_commenter == from_uid).first()
    if intimate1 is None or intimate2 is None or min(intimate1.counter,
                                                     intimate2.counter) < 30:
        ret = {'code': status.get('PERMISSION'), 'MESSAGE': '亲密度未达到文本私信要求'}
        return jsonify(ret)
    from_name = session.query(User).filter(User.uid == from_uid).first()
    to_name = session.query(User).filter(User.uid == to_uid).first()
    if to_name is None:
        ret = {'code': status.get('ERROR'), 'MESSAGE': '参数不合法'}
        return jsonify(ret)
    if msg_type == 1:
        if intimate1 is None or intimate2 is None or min(
                intimate1.counter, intimate2.counter) < 50:
            ret = {'code': status.get('PERMISSION'), 'MESSAGE': '亲密度未达到文本私信要求'}
            return jsonify(ret)
        pic_info = requests.post('http://api.cugxuan.cn:8080/upload',
                                 files={'file': message})
        pic_info = pic_info.json()
        if pic_info['code'] == 200:
            pic_url = 'http://pic1.cugapp.com/' + pic_info['name']
            message = pic_url
        else:
            ret = {'code': status.get('ERROR'), 'MESSAGE': '无法上传图片'}
            return jsonify(ret)
    new_message = SecMessage(uid_sender=from_uid,
                             uid_receiver=to_uid,
                             message=message,
                             name_sender=from_name.username,
                             name_receiver=to_name.username,
                             msg_type=msg_type)
    session.add(new_message)
    session.commit()
    result = {
        "code": status.get("SUCCESS"),
        "message": "发送成功!",
    }
    return jsonify(result)
Example #4
0
    def grava_informacoes(self,id_mensagem):
        try:
            mensagem = Mensagens()

            result, data = self.mail.fetch(id_mensagem, "(RFC822)")
            raw_email = data[0][1]

            email_message = email.message_from_string(raw_email)
            mensagem.data = email_message['Date']
            mensagem.origem = email.utils.parseaddr(email_message['From'])[1]
            mensagem.assunto = email_message['Subject']
            session.add(mensagem)
            session.commit()

        except Exception as e:
            print ("Erro: %s"%e)
            session.rollback()
Example #5
0
def register():
    username = request.form.get("username")
    password = request.form.get("password")
    phone = request.form.get("phone")
    email = request.form.get("email")
    qq = request.form.get("qq")
    wechat = request.form.get("wechat")
    if username and password and phone and email:
        hash = hashlib.md5()
        hash.update(password.encode(encoding='utf-8'))
        user = session.query(User).filter(User.username == username).first()
        if not user:
            token = str(int(random.uniform(100, 10000)))
            active[token] = username
            user = User(username=username,
                        password=hash.hexdigest(),
                        avatar_url='http://pic1.cugapp.com/FikstAllXLweowBEXpy5FQxPd8td.jpg',
                        phone=phone,
                        email=email,
                        qq=qq,
                        wechat=wechat,
                        is_active=0)
            session.add(user)
            session.commit()
            send_mail(email, token)
            result = {
                "code": status.get("SUCCESS"),
                "MESSAGE": "邮件发送成功",
            }
            return jsonify(result)
        result = {
            "code": status.get("FAIL"),
            "message": "注册失败,用户名已存在",
        }
        return jsonify(result)
    result = {
        "code": status.get("FAIL"),
        "MESSAGE": "参数不足",
    }
    return jsonify(result)
Example #6
0
def post():
    title = request.form.get('title', None)
    content = request.form.get("content")
    uid = g.uid
    if title is None:
        ret = {'code': status.get('ERROR'), 'MESSAGE': '参数不合法'}
        return jsonify(ret)
    new_subject = Subject(uid=uid, title=title)
    session.add(new_subject)
    session.commit()

    message = Post(tid=new_subject.tid,
                   content=content,
                   comment_floor=1,
                   fid=1,
                   like=0,
                   uid=g.uid)
    session.add(message)
    session.commit()
    result = {
        "code": status.get("SUCCESS"),
        "message": "发帖成功!",
    }
    return jsonify(result)
Example #7
0
def postSubject(uid, title):
    new_subject = Subject(uid=uid, title=title)
    session.add(new_subject)
    session.commit()