def logout(): userid = session['currentuserid'] uf = userfactory.Userfactory() db = get_db() user = uf.getuser(db, userid) session.pop('logged_in', None) session.pop('currentuserid', None) flash('Logged out ' + user.first + ' ' + user.last) return redirect(getjqm_url('show_home'))
def user_list(): if isloggedin() == True: uf = userfactory.Userfactory() db = get_db() user = uf.getuser(db, session['currentuserid']) users = uf.getusers(db) return render_template('userlist.html', user=user, users=users) else: error = 'Not authorised' return render_template('home.html', error=error)
def room_list(): if isloggedin() == True: uf = userfactory.Userfactory() db = get_db() user = uf.getuser(db, session['currentuserid']) rf = roomfactory.RoomFactory() rooms = rf.get_rooms(db) return render_template('roomlist.html', user=user, rooms=rooms) else: error = 'Not authorised' return render_template('home.html', error=error)
def device_list(): if isloggedin() == True: uf = userfactory.Userfactory() db = get_db() user = uf.getuser(db, session['currentuserid']) df = devicefactory.DeviceFactory() devices = df.get_devices(db) return render_template('devicelist.html', user=user, devices=devices) else: error = 'Not authorised' return render_template('home.html', error=error)
def adduser(): error = None if request.method == 'POST': username = request.form['username'] password = request.form['password'] firstname = request.form['firstname'] lastname = request.form['lastname'] usergroup = request.form['usergroup'] db = get_db() uf = userfactory.Userfactory() uf.createuser(db, username, password, firstname, lastname, usergroup) return render_template('login.html', error=error)
def login(): error = None if request.method == 'POST': db = get_db() uf = userfactory.Userfactory() userid = uf.validuser(db, request.form['username'], request.form['password']) if userid > 0: user = uf.getuser(db, userid) session['currentuserid'] = userid session['logged_in'] = True flash('Logged in ' + user.first + ' ' + user.last) return redirect(getjqm_url('show_home')) else: error = 'Invalid username or password' return render_template('login.html', error=error)
def edit(item, id): if isloggedin() == True: db = get_db() uf = userfactory.Userfactory() user = uf.getuser(db, session['currentuserid']) item = item.lower() if item == 'room': rgf = roomgroupfactory.Roomgroupfactory() roomgroups = rgf.getroomgroups(db) rf = roomfactory.RoomFactory() room = rf.get_room(db, id) df = devicefactory.DeviceFactory() available_devices = df.get_available_devices(db, room) return render_template('addeditroom.html', user=user, roomgroups=roomgroups, room=room, available_devices=available_devices) elif item == 'roomgroup': pass elif item == 'device': dgf = devicegroupfactory.DeviceGroupFactory() devicegroups = dgf.get_devicegroups(db) df = devicefactory.DeviceFactory() device = df.get_device(db, id) return render_template('addeditdevice.html', user=user, devicegroups=devicegroups, device=device) elif item == 'user': edituser = uf.getuser(db, id) ugf = usergroupfactory.UserGroupFactory() usergroups = ugf.get_user_groups(db) return render_template('addedituser.html', user=user, edituser=edituser, usergroups=usergroups) elif item == 'devicegroup': dgf = devicegroupfactory.DeviceGroupFactory() devicegroup = dgf.get_devicegroup(db, id) return render_template('addeditdevicegroup.html', user=user, devicegroup=devicegroup) else: error = 'Not authorised' return render_template('home.html', error=error)
def save_user(db): if 'save' in request.form: first = request.form['first'] last = request.form['last'] username = request.form['username'] userid = request.form['userid'] password = request.form['password'] usergroup = request.form['usergroup'] uf = userfactory.Userfactory() if userid == '': userid = uf.createuser(db, username, password, first, last, usergroup) else: uf.update_user(db, userid, username, password, first, last, usergroup) return edit('user', userid) else: return user_list()
def getroom(): db = get_db() rf = roomfactory.RoomFactory() roomid = int(request.args.get('roomid')) roomdetails = rf.get_room(db, roomid) lin = None if 'currentuserid' in session: lin = session['currentuserid'] else: lin = False if lin == True: uf = userfactory.Userfactory() db = get_db() user = uf.getuser(db, session['currentuserid']) return render_template('roomdetails.html', user=user, room=roomdetails) else: error = 'Not authorised' return render_template('home.html', error=error)
def list(item): if isloggedin() == True: db = get_db() uf = userfactory.Userfactory() user = uf.getuser(db, session['currentuserid']) item = item.lower() if item == 'room': return room_list() elif item == 'roomgroup': pass elif item == 'device': return device_list() elif item == 'user': return user_list() elif item == 'devicegroup': return device_group_list() else: error = 'Not authorised' return render_template('home.html', error=error)
def show_home(): # init_db() #init_defaultdata() #init_testdata() db = get_db() rf = roomfactory.RoomFactory() rooms = rf.get_rooms(db) lin = None if 'currentuserid' in session: lin = session['currentuserid'] else: lin = False if lin == True: uf = userfactory.Userfactory() dgf = devicegroupfactory.DeviceGroupFactory() user = uf.getuser(db, session['currentuserid']) devicegroups = dgf.get_devicegroups(db) return render_template('home.html', rooms=rooms, user=user, devicegroups=devicegroups) else: return render_template('welcome.html', user=None)
def getuser(): db = get_db() uf = userfactory.Userfactory() userid = int(request.args.get('userid')) userdetails = uf.getuser(db, userid) return render_template('userdetails.html', userdetails=userdetails)