def routeLogin(): u = Admin.objects(username=request.form.get('user')) if len(u) and checkPw(request.form.get('pw'), u[0].password): session['loggedin'] = True flash('Welcome back %s!' % u[0].username, 'success') return redirect('/') flash('Invalid login details!', 'error') return redirect('/')
def routeMod(id=None, action=None): if not isMod(): return redirect(url_for('/find')) if action == 'adduser': if request.form.get('user') and request.form.get('pw'): u = Admin(username=request.form.get('user'), password=hashPw(request.form.get('pw'))) u.save() flash('Added user "%s" successfully!' % request.form.get('user'), 'success') return redirect('/mod') elif action =='rmvuser': q = Admin.objects(id=id) if len(q): q[0].delete() flash('Deleted user successfully!', 'success') return redirect('/mod') flash('Error deleting user!', 'error') return redirect('/mod') if not id: flash('Error processing your request!', 'error') return redirect('/mod') act = action.split('_', 1) if act[-1] == 'provider': q = Provider.objects(id=id) text = 'submission' url = '/mod/provider' elif act[-1] == 'school': q = School.objects(id=id) text = 'request' url ='/mod/school' if not len(q): flash('Error processing your request! (Could not find %s)' % text, 'error') return redirect(url+'s') q = q[0] if act[0] == 'del': q.delete() flash('Deleted %s!' % text, 'success') return redirect(url+'s') elif act[0] == 'mark': q.active = False q.save() flash('Marked %s as done!' % text, 'success') return redirect(url+'/%s' % id)
def routeMody(): if not isMod(): flash('You must be logged in to do that!', 'error') return redirect('/') return render('admin.html', users=Admin.objects())
def main(): inventory = Inventory() admin = Admin("admin", "admin", inventory) # Default admin. main_menu(inventory)