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'))
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'))
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'))
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)
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'))
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')
def utama(): return redirect(url_for('index'))
def logout(): session.pop('user', None) return redirect(url_for('index'))
def delet(id): data = Kategori.query.filter_by(id=id).first() db.session.delete(data) db.session.commit() return redirect(url_for('kategori'))
def user(): if 'user' in session: return render_template('user.html') return redirect(url_for('login'))