def login(): form = LogIn() Branch.branch_types() Types.stall_types() print current_user if current_user.is_active(): if current_user.roleID == 1: return redirect(url_for('index2')) else: return redirect(url_for('index')) else: if request.method == "POST" and form.validate_on_submit(): user = Users.query.filter_by(username=form.username.data).first() if user: if user.roleID == 2: if user is not None and check_password_hash( user.passwrd, form.passwrd.data): msg = user.username + " logs in" lgdate = str(now) print lgdate logmessage = Logs(details=msg, log_date=lgdate) dbase.session.add(logmessage) login_user(user) return redirect(url_for('index')) #return '<h1>Invalid username or password!</h1>' flash('Invalid username or password') elif user.roleID == 1: if user is not None and check_password_hash( user.passwrd, form.passwrd.data): msg = user.username + " logs in" lgdate = str(now) print lgdate logmessage = Logs(details=msg, log_date=lgdate) dbase.session.add(logmessage) login_user(user) login_user(user) flash('You were logged in') return redirect(url_for('index2')) #return '<h1>Invalid username or password!</h1>' flash('Invalid username or password') else: #return '<h1>Invalid username or password!</h1>' flash('Invalid username or password') else: #return '<h1>Invalid username or password!</h1>' flash('Invalid username or password') return render_template('login.html', form=form)
def save_types(self, place_id, types): session = Session() if not self.get_types(place_id, types): type = Types(place_id = place_id, types = types) session.add(type) session.commit() print '<TYPE>', place_id, types, 'saved successfully!' session.close()
def AddStalls(): form = addstalls() if request.method == "POST": if form.validate_on_submit(): stallNo = form.stallno.data stallLoc = form.stallloc.data Rate = form.rate.data stalltype = form.stalltype.data type = Types.query.filter_by(stall_type=stalltype).first() if type: t = type.typeID else: Stalltype = Types(stall_type=stalltype) dbase.session.add(Stalltype) dbase.session.commit() type1 = Types.query.filter_by(stall_type=stalltype).first() t = type1.typeID stallstat = Stalls.query.filter_by(stall_no=stallNo).first() if stallstat: flash('Stall already existing') else: stallform = Stalls(stall_rate=int(Rate), stall_loc=stallLoc, stall_status="0", stall_no=int(stallNo), typeID=t) dbase.session.add(stallform) user = current_user lgdate = str(now) msg = user.username + " added a tenant " logmessage = Logs(details=msg, log_date=lgdate) dbase.session.add(logmessage) dbase.session.commit() flash("Stall Added!!") return render_template("addstall.html", page_title='Add Stall', form=form, result=search_panel(0)[0], x=search_panel(0)[1], result2=search_panel(1)[0], y=search_panel(1)[1], notif_count=notif_count())