Exemplo n.º 1
0
def admin():
    if 'user' in session:
        user = session['user']
        data = User.query.filter_by(user=user).first()
        if data.rol_id == 1:
            return render_template('admin.html')
        return redirect(url_for('user'))
    return redirect(url_for('login'))
Exemplo n.º 2
0
def upload():
    if 'user' in session:
        if request.method == 'POST':
            s = session['user']
            user = User.query.filter_by(user=s).first()
            title = request.form['title']
            isi = request.form['isi']
            kat = request.form.get('kategori')
            ket = request.form['ket']
            kteg = Kategori.query.filter_by(kat=kat).first()
            id_kateg = kteg.id
            save = Conten(tilte=title,
                          isi=isi,
                          data_time=datetime.now(),
                          userku_id=user.id,
                          ket=ket,
                          kategori_id=id_kateg)
            db.session.add(save)
            db.session.commit()
            return 'berhasil di upload'

        ktr = Kategori.query.all()
        ar = []
        for i in ktr:
            ar.append(i.kat)
        ar.insert(0, '--pilih kategori--')

        log = session['user']
        datalogin = User.query.filter_by(user=log).first()
        if datalogin.rol_id == 1:
            return render_template('upload.html', data=ar)
        return render_template('userupload.html', data=ar)
    return redirect(url_for('login'))
Exemplo n.º 3
0
def usrconten():
    if 'user' in session:
        datalog = session['user']
        datalog = User.query.filter_by(user=datalog).first()
        user_id = datalog.id
        conten = Conten.query.filter_by(userku_id=user_id).all()
        return render_template('userconten.html', data=conten)
    return redirect(url_for('login'))
Exemplo n.º 4
0
def kategori():
    if request.method == 'POST':
        kt = request.form['kategori']
        save = Kategori(kat=kt)
        if kt == "":
            return redirect(url_for('kategori'))
        db.session.add(save)
        db.session.commit()
        return redirect(url_for('kategori'))
    ktr = Kategori.query.all()
    no = []
    a = 0
    for i in ktr:
        a += 1
        no.append(a)

    return render_template('addkt.html', data=ktr, no=no)
Exemplo n.º 5
0
def adminconten():
    if 'user' in session:
        datalog = session['user']
        datalog = User.query.filter_by(user=datalog).first()
        user_id = datalog.id
        conten = Conten.query.filter_by(userku_id=user_id).all()
        no = []
        a = 0
        for i in conten:
            a += 1
            no.append(a)
        return render_template('adminconten.html', data=conten, no=no)
    return redirect(url_for('login'))
Exemplo n.º 6
0
def login():
    if 'user' in session:
        user = session['user']
        data = User.query.filter_by(user=user).first()
        if data.rol_id == 1:
            return redirect(url_for('admin'))
        elif data.rol_id == 2:
            return redirect(url_for('user'))

    if request.method == 'POST':
        usr = request.form['username']
        paswords = request.form['password']
        user = User.query.filter_by(user=usr).first()
        rol = user.rol_id
        if user:
            if user.pas == paswords:
                session['user'] = str(user.user)
                if rol == 1:
                    return redirect(url_for('admin'))
                return redirect(url_for('user'))
            return 'posword  and password not compatible'
        return 'user not exist'
    return render_template('login.html')
Exemplo n.º 7
0
def utama():
    return redirect(url_for('index'))
Exemplo n.º 8
0
def logout():
    session.pop('user', None)
    return redirect(url_for('index'))
Exemplo n.º 9
0
def delet(id):
    data = Kategori.query.filter_by(id=id).first()
    db.session.delete(data)
    db.session.commit()
    return redirect(url_for('kategori'))
Exemplo n.º 10
0
def user():
    if 'user' in session:
        return render_template('user.html')
    return redirect(url_for('login'))