def badge_award_submit(): if(request.get_cookie('loggedin')): useremail = request.get_cookie('loggedin', secret='applesauce') badge_list = m3.get_badges(pcrDB) # list of all badges user_list = m3.get_users(pcrDB) # list of all users current_user = request.params.user current_user_badges = m3.get_users_badges(pcrDB, current_user) current_badge = request.params.badge ## check that the user doesn't already have the badge # if so, send back to the menu if(current_badge in current_user_badges): return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:red;">That user already has that badge!</h2> '''.format(useremail) + template('admin-award.tpl', badges=badge_list, users=user_list) + "</body>" # if not, award the badge ## awarding badge magic else: m3.award_badge_to_user(pcrDB, current_badge, current_user) return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:blue;">Badge successfully awarded!<h2> '''.format(useremail) + template('admin-award.tpl', badges=badge_list, users=user_list) + "</body>" else: redirect("/login")
def badge_award_submit(): if (request.get_cookie('loggedin')): useremail = request.get_cookie('loggedin', secret='applesauce') badge_list = m3.get_badges(pcrDB) # list of all badges user_list = m3.get_users(pcrDB) # list of all users current_user = request.params.user current_user_badges = m3.get_users_badges(pcrDB, current_user) current_badge = request.params.badge ## check that the user doesn't already have the badge # if so, send back to the menu if (current_badge in current_user_badges): return template('base.tpl', title='PCR Hero', email=useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:red;">That user already has that badge!</h2> '''.format(useremail) + template('admin-award.tpl', badges=badge_list, users=user_list) + "</body>" # if not, award the badge ## awarding badge magic else: m3.award_badge_to_user(pcrDB, current_badge, current_user) return template('base.tpl', title='PCR Hero', email=useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:blue;">Badge successfully awarded!<h2> '''.format(useremail) + template( 'admin-award.tpl', badges=badge_list, users=user_list) + "</body>" else: redirect("/login")
def badge_submit(): if(request.get_cookie('loggedin')): useremail = request.get_cookie('loggedin', secret='applesauce') userbadges = m3.get_users_badges(pcrDB, useremail) issuers = m3.get_issuers(pcrDB) image_path = "/home/ubuntu/pythonproject/images" available_images = os.listdir(image_path) ## return args name = request.params.name if(m3.find_badge(pcrDB, name) != None): return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:red">A badge with that name already exists!</h2> '''.format(useremail) + template('admin-badge.tpl', badges=userbadges, issuers=issuers, images=available_images) + "</body>" else: description = request.params.description image = request.params.image criteria = request.params.criteria tags = request.params.tags issuer = request.params.issuer newBadge = m3.OpenBadge(name, description, image, criteria, tags, issuer) newBadge.establish_here() newBadge.add_badge(pcrDB) return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:blue">Your badge was successfully created!</h2> '''.format(useremail) + template('admin-badge.tpl', badges=userbadges, issuers=issuers, images=available_images) + "</body>" else: redirect("/login")
def upload_image(): if (request.get_cookie('loggedin')): useremail = request.get_cookie('loggedin', secret='applesauce') userbadges = m3.get_users_badges(pcrDB, useremail) image_path = "/home/ubuntu/pythonproject/images" available_images = os.listdir(image_path) upload = request.files.image name, ext = os.path.splitext(upload.filename) if ext not in ('.png'): return "File extension not allowed." save_path = "/home/ubuntu/pythonproject/images" file_path = "{path}/{file}".format(path=save_path, file=upload.filename) upload.save(file_path) return template('base.tpl', title='PCR Hero', email=useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:blue">Image successfully uploaded!</h2> '''.format(useremail) + template('admin-images.tpl', badges=userbadges, images=available_images, image_path=image_path) + "</body>" else: redirect("/login")
def issuer_create_submit(): name = request.params.name description = request.params.description url = request.params.url if (request.get_cookie('loggedin')): useremail = request.get_cookie('loggedin', secret='applesauce') userbadges = m3.get_users_badges(pcrDB, useremail) issuers = m3.get_issuers(pcrDB) if (m3.find_issuer(pcrDB, name) != None): return template('base.tpl', title='PCR Hero', email=useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <p style="color:red;">Sorry, that issuer is taken!</p> '''.format(useremail) + template('admin-issuer.tpl', badges=userbadges, issuers=issuers) + "</body>" else: newIssuer = m3.PCRIssuer(name, description, url) m3.add_issuer(pcrDB, newIssuer) newIssuer.establish_here() issuers = m3.get_issuers(pcrDB) return template('base.tpl', title='PCR Hero', email=useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <p style="color:blue;">Your issuer has been created!</p> '''.format(useremail) + template('admin-issuer.tpl', badges=userbadges, issuers=issuers) + "</body>" else: redirect("/login")
def issuer_create_menu(): if(request.get_cookie('loggedin')): useremail = request.get_cookie('loggedin', secret='applesauce') userbadges = m3.get_users_badges(pcrDB, useremail) issuers = m3.get_issuers(pcrDB) return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> '''.format(useremail) + template('admin-issuer.tpl', badges=userbadges, issuers=issuers) + "</body>" else: redirect("/login")
def images_menu(): if(request.get_cookie('loggedin')): useremail = request.get_cookie('loggedin', secret='applesauce') userbadges = m3.get_users_badges(pcrDB, useremail) image_path = "/home/ubuntu/pythonproject/images" available_images = os.listdir(image_path) return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> '''.format(useremail) + template('admin-images.tpl', badges=userbadges, images=available_images, image_path=image_path) + "</body>" else: redirect("/login")
def profile(): if(request.get_cookie('loggedin')): useremail = request.get_cookie('loggedin', secret='applesauce') userbadges = m3.get_users_badges(pcrDB, useremail) userapps = m3.get_users_apps(pcrDB, useremail) applist = {} for appname in userapps: applist[appname] = (m3.get_app(pcrDB, appname)) return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero - {}</h1> '''.format(useremail) + template('profile.tpl', badges=userbadges, apps=applist) + "</body>" else: redirect("/login")
def issuer_create_submit(): name = request.params.name description = request.params.description url = request.params.url if(request.get_cookie('loggedin')): useremail = request.get_cookie('loggedin', secret='applesauce') userbadges = m3.get_users_badges(pcrDB, useremail) issuers = m3.get_issuers(pcrDB) if(m3.find_issuer(pcrDB, name) != None): return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <p style="color:red;">Sorry, that issuer is taken!</p> '''.format(useremail) + template('admin-issuer.tpl', badges=userbadges, issuers=issuers) + "</body>" else: newIssuer = m3.PCRIssuer(name, description, url) m3.add_issuer(pcrDB, newIssuer) newIssuer.establish_here() issuers = m3.get_issuers(pcrDB) return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <p style="color:blue;">Your issuer has been created!</p> '''.format(useremail) + template('admin-issuer.tpl', badges=userbadges, issuers=issuers) + "</body>" else: redirect("/login")
def upload_image(): if(request.get_cookie('loggedin')): useremail = request.get_cookie('loggedin', secret='applesauce') userbadges = m3.get_users_badges(pcrDB, useremail) image_path = "/home/ubuntu/pythonproject/images" available_images = os.listdir(image_path) upload = request.files.image name, ext = os.path.splitext(upload.filename) if ext not in ('.png'): return "File extension not allowed." save_path = "/home/ubuntu/pythonproject/images" file_path = "{path}/{file}".format(path=save_path, file=upload.filename) upload.save(file_path) return template('base.tpl', title='PCR Hero', email= useremail) + '''\ <h1>Welcome to PCR Hero's Admin Menu - {}</h1> <h2 style="color:blue">Image successfully uploaded!</h2> '''.format(useremail) + template('admin-images.tpl', badges=userbadges, images=available_images, image_path=image_path) + "</body>" else: redirect("/login")