def recomment(token):
    if request.method == 'POST':
        title = request.form.get('title')
        content = request.form.get('content')
        animepicture = request.files.getlist('animepicture')
        photo = request.files.getlist('photo')
        animetitle = request.form.get('animetitle')
        user_id = r.get(token)
        describe = request.form.get('describe')
        datafrom = request.form.get('datafrom')
        link = request.form.get('link')
        seasonid = request.form.get('seasonid')
        tag1 = request.form.get('tag1')
        tag2 = request.form.get('tag2')
        tag3 = request.form.get('tag3')
        if int(datafrom) == 1:
            drama = Drama(title=title, content=content, user_id=user_id)
            db.session.add(drama)
            db.session.commit()
            anime = Anime(title=animetitle,describe=describe,datafrom=datafrom,seasonId=seasonid,dramaid=drama.id,tag1=tag1,tag2=tag2,tag3=tag3)
            db.session.add(anime)
        elif int(datafrom) == 2:
            drama = Drama(title=title, content=content, user_id=user_id)
            db.session.add(drama)
            db.session.commit()
            anime = Anime(title=animetitle,describe=describe, link=link,datafrom=datafrom, dramaid=drama.id,tag1=tag1,tag2=tag2,tag3=tag3)
            db.session.add(anime)
        db.session.commit()
        for file in animepicture:
            file.filename = random_filename(file.filename)
            coverp = Photo(image= 'http://' + HOST + '/user/image/' + file.filename, drama_id=drama.id, cover=True)
            file.save(os.path.join(current_app.config['UPLOAD_PATH'], file.filename))
            anime.picture = coverp.image
            db.session.add(coverp)
        for file in photo:
            file.filename = random_filename(file.filename)
            contentp = Photo(image='http://' + HOST + '/user/image/' + file.filename, drama_id=drama.id, content=True)
            file.save(os.path.join(current_app.config['UPLOAD_PATH'], file.filename))
            db.session.add(contentp)
        db.session.commit()
        user = User.query.get(r.get(token))
        for follow in user.followed.all():
            send_email('你关注的用户更新啦',follow.followed.email,follow.followed.name+'——'+'['+title+']'+'(推荐番)')
        return jsonify(Event0(token=token, dramaid=drama.id))
    elif request.method == 'DELETE':
        dramaid = request.form.get('dramaid')
        drama = Drama.query.get(dramaid)
        if drama is None:
            return jsonify(Event1002())
        db.session.delete(drama)
        db.session.commit()
        if Drama.query.get(dramaid) is not None:
            return jsonify(Event1005('删除失败'))
        return jsonify(Event0(token=token))
    return jsonify(Event1004())
Beispiel #2
0
def create():
    if request.method == 'POST':
        name = request.form.get('name')
        password = request.form.get('password')
        repeatpd = request.form.get('repeatpd')
        avatar = request.files.get('avatar')
        email = request.form.get('email')
        if User.query.filter_by(name=name).first() is not None:  #用户名存在,返回错误
            return jsonify(Event1003())
        if User.query.filter_by(email=email).first() is not None:  #邮箱存在,返回错误
            return jsonify(Event1005('邮箱已被注册'))
        if password == repeatpd:
            user = User(name=name, password=password, email=email)
            db.session.add(user)
            db.session.commit()
            if avatar and avatar.filename != '':
                avatar.filename = random_filename(avatar.filename)
                avatar.save(
                    os.path.join(current_app.config['UPLOAD_PATH'],
                                 avatar.filename))
                user.avatar = 'http://127.0.0.1:5000/user/image/' + avatar.filename
            db.session.commit()
            send_email('注册成功', user.email, '注册成功欢迎加入我们')
            token = user.make_token()
            r.set(token, str(user.id), ex=3600)
            return jsonify(Event0(token=token))
        return jsonify(Event1005('密码不一致'))
    return jsonify(Event1004())
def ask(token):
    if request.method == 'POST':
        title = request.form.get('title')
        content = request.form.get('content')
        photos = request.files.getlist('photos')
        userid = r.get(token)
        drama = Drama(title=title, content=content, solution='false',user_id=userid)
        db.session.add(drama)
        db.session.commit()
        for file in photos:
            file.filename = random_filename(file.filename)
            contentp = Photo(image='http://' + HOST + '/user/image/' + file.filename, drama_id=drama.id, content=True)
            file.save(os.path.join(current_app.config['UPLOAD_PATH'], file.filename))
            db.session.add(contentp)
        db.session.commit()
        user = User.query.get(r.get(token))
        for follow in user.followed.all():
            send_email('你关注的用户更新啦', follow.followed.email, follow.followed.name + '——' + '[' + title + ']' + '(推荐番)')
        return jsonify(Event0(token=token, dramaid=drama.id))
    if request.method == 'DELETE':
        dramaid = request.form.get('dramaid')
        drama = Drama.query.get(dramaid)
        if drama is None:
            return jsonify(Event1002())
        db.session.delete(drama)
        db.session.commit()
        if Drama.query.get(dramaid) is not None:
            return jsonify(Event1005('删除失败'))
        return jsonify(Event0(token=token))
    return jsonify(Event1004())
def updata(token):
    name = request.form.get('name')
    avatar = request.files.get('avatar')
    password = request.form.get('password')
    email = request.form.get('email')
    user = User.query.filter_by(id=r.get(token)).first()
    if name is not None:
        if User.query.filter_by(name=name).first() is not None:             #用户名存在,返回错误
            return jsonify(Event1003())
        user.name = name
    if avatar is not None:
        avatar.filename = random_filename('user' + str(user.id) + os.path.splitext(avatar.filename)[1])
        avatar.save(os.path.join(current_app.config['UPLOAD_PATH'], avatar.filename))
        user.avatar = 'http://101.200.157.252/user/image/' + avatar.filename
    if password is not None:
        user.password = password
    if email is not None:
        if User.query.filter_by(email=email).first() is not None:       #邮箱存在,返回错误
            return jsonify(Event1005('邮箱已被注册'))
        user.email = email
    db.session.commit()
    return jsonify(Event0(token=token))
Beispiel #5
0
def recomment(token):
    if request.method == 'POST':
        title = request.form.get('title')
        content = request.form.get('content')
        animepicture = request.files.getlist('animepicture')
        photo = request.files.getlist('photo')
        animetitle = request.form.get('animetitle')
        user_id = r.get(token)
        animedescribe = request.form.get('animedescribe')
        animefrom = request.form.get('animefrom')
        animelink = request.form.get('animelink')
        animeseasonid = request.form.get('animeseasonid')
        if int(animefrom) == 1:
            drama = Drama(title=title,
                          content=content,
                          user_id=user_id,
                          animetitle=animetitle,
                          animedescribe=animedescribe,
                          animefrom=animefrom,
                          animeseasonid=animeseasonid)
            db.session.add(drama)
        elif int(animefrom) == 2:
            drama = Drama(title=title,
                          content=content,
                          user_id=user_id,
                          animetitle=animetitle,
                          animedescribe=animedescribe,
                          animefrom=animefrom,
                          animelink=animelink)
            db.session.add(drama)
        db.session.commit()
        for file in animepicture:
            file.filename = random_filename(file.filename)
            coverp = Photo(image='http://127.0.0.1:5000/user/image/' +
                           file.filename,
                           drama_id=drama.id,
                           cover=True)
            file.save(
                os.path.join(current_app.config['UPLOAD_PATH'], file.filename))
            db.session.add(coverp)
        for file in photo:
            file.filename = random_filename(file.filename)
            contentp = Photo(image='http://127.0.0.1:5000/user/image/' +
                             file.filename,
                             drama_id=drama.id,
                             content=True)
            file.save(
                os.path.join(current_app.config['UPLOAD_PATH'], file.filename))
            db.session.add(contentp)
        db.session.commit()
        follows = Follow.query.filter(Follow.followid == user_id).all()
        for follow in follows:
            send_email('你关注的用户更新啦', follow.user.email,
                       follow.user.name + '——' + '[' + title + ']' + '(推荐番)')
        return jsonify(Event0(token=token, dramaid=drama.id))
    elif request.method == 'DELETE':
        dramaid = request.form.get('dramaid')
        drama = Drama.query.get(dramaid)
        if drama is None:
            return jsonify(Event1002())
        db.session.delete(drama)
        db.session.commit()
        if Drama.query.get(dramaid) is not None:
            return jsonify(Event1005('删除失败'))
        return jsonify(Event0(token=token))
    return jsonify(Event1004())