def post(self): isLocal = os.environ['SERVER_SOFTWARE'].startswith('Dev') if not isLocal: return api_key = self.request.get('apikey') account_id = self.request.get('accountid') badge_id = self.request.get('badgeid') badge_theme = self.request.get('theme') user_id = self.request.get('user') if not badge_theme or not badge_id or not account_id or not api_key: ret = bad_args() self.response.out.write(ret) return user_key = users_dao.get_user_key(account_id, user_id) user_ref = users_dao.get_user(account_id, user_id) if user_ref: badge_instances = badges_dao.get_user_badges(user_ref) for b in badge_instances: badges_dao.delete_badge_instance(b.key().name()) users_dao.delete_user(user_key) trophy_case_widget = TrophyCase(key_name=account_id) points_widget = Points(key_name=account_id) rank_widget = Rank(key_name=account_id) notifier_widget = Notifier(key_name=account_id) leader_widget = Leaderboard(key_name=account_id) milestones_widget = Milestones(key_name=account_id) acc = Accounts(key_name=account_id, email=account_id, password="******", isEnabled=constants.ACCOUNT_STATUS.ENABLED, accountType="admin", paymentType="free", cookieKey="xxxxxxxxx", apiKey=api_key, trophyWidget=trophy_case_widget, pointsWidget=points_widget, rankWidget=rank_widget, leaderWidget=leader_widget, milestoneWidget=milestones_widget) # delete ten badges for ii in range(0,10): badgeKey = badges_dao.create_badge_key(account_id, badge_theme, str(ii), "private") badges_dao.delete_badge_image(badgeKey) badges_dao.delete_badge(badgeKey) widgets_dao.delete_widget(account_id, "TrophyCase") widgets_dao.delete_widget(account_id, "Points") widgets_dao.delete_widget(account_id, "Rank") widgets_dao.delete_widget(account_id, "Leaderboard") widgets_dao.delete_widget(account_id, "Notifier") widgets_dao.delete_widget(account_id, "Milestones") accounts_dao.delete_account(account_id) self.response.out.write(success_ret()) return
def post(self): #TODO # IN the future we should try to move this logic to data access utility layer # and have the handler portion be in console.py current_session = Session().get_current_session(self) account = current_session.get_account_entity() if not account: self.response.out.write( "Problem with your account. Please email support.") return #TODO make sure badge name is not taken, or warn if overwritting badge_name = self.request.get("badgename") badge_name = string.replace(badge_name, " ", "_") badge_name = string.replace(badge_name, "-", "_") badge_theme = self.request.get("badgetheme") badge_theme = string.replace(badge_theme, "-", "_") badge_theme = string.replace(badge_theme, " ", "_") badge_des = self.request.get("badgedescription") upload_files = self.get_uploads('file') blob_info = upload_files[0] badge_file_name = blob_info.filename badge_ext = get_file_ext(badge_file_name) if badge_ext not in constants.IMAGE_PARAMS.VALID_EXT_TYPES: delete_blob(blob_info) self.redirect('/adminconsole/badges?error=BadImageType') return logging.info("File ext:" + badge_ext) if not badge_name: delete_blob(blob_info) self.redirect('/adminconsole/badges?error=NoNameGiven') return if not badge_des: delete_blob(blob_info) self.redirect('/adminconsole/badges?error=NoDescriptionGiven') return if not badge_theme: delete_blob(blob_info) self.redirect('/adminconsole/badges?error=NoThemeGiven') return if not blob_info: delete_blob(blob_info) self.redirect('/adminconsole/badges?error=InternalError') return if blob_info.size > constants.MAX_BADGE_SIZE: delete_blob(blob_info) self.redirect('/adminconsole/badges?error=FileTooLarge') return perm = "private" if account.email == constants.ADMIN_ACCOUNT: perm = "public" badge_key = badges_dao.create_badge_key(account.email, badge_theme, badge_name, perm) badge = badges_dao.create_badge_type(badge_key, badge_name, badge_des, account, badge_theme, badge_ext, blob_info=blob_info) self.redirect('/adminconsole/badges')
def post(self): #TODO # IN the future we should try to move this logic to data access utility layer # and have the handler portion be in console.py current_session = Session().get_current_session(self) account = current_session.get_account_entity() if not account: self.response.out.write("Problem with your account. Please email support.") return #TODO make sure badge name is not taken, or warn if overwritting badge_name = self.request.get("badgename") badge_name = string.replace(badge_name, " ", "_") badge_name = string.replace(badge_name, "-", "_") badge_theme = self.request.get("badgetheme") badge_theme= string.replace(badge_theme, "-", "_") badge_theme = string.replace(badge_theme, " ", "_") badge_des = self.request.get("badgedescription") upload_files = self.get_uploads('file') blob_info = upload_files[0] badge_file_name = blob_info.filename badge_ext = get_file_ext(badge_file_name) if badge_ext not in constants.IMAGE_PARAMS.VALID_EXT_TYPES: delete_blob(blob_info) self.redirect('/adminconsole/badges?error=BadImageType') return logging.info("File ext:"+badge_ext) if not badge_name: delete_blob(blob_info) self.redirect('/adminconsole/badges?error=NoNameGiven') return if not badge_des: delete_blob(blob_info) self.redirect('/adminconsole/badges?error=NoDescriptionGiven') return if not badge_theme: delete_blob(blob_info) self.redirect('/adminconsole/badges?error=NoThemeGiven') return if not blob_info: delete_blob(blob_info) self.redirect('/adminconsole/badges?error=InternalError') return if blob_info.size > constants.MAX_BADGE_SIZE: delete_blob(blob_info) self.redirect('/adminconsole/badges?error=FileTooLarge') return perm = "private" if account.email == constants.ADMIN_ACCOUNT: perm = "public" badge_key = badges_dao.create_badge_key(account.email, badge_theme, badge_name, perm) badge = badges_dao.create_badge_type(badge_key, badge_name, badge_des, account, badge_theme, badge_ext, blob_info=blob_info) self.redirect('/adminconsole/badges')
def post(self): start = time.time() api_key = self.request.get('apikey') account_id = self.request.get('accountid') badge_name = self.request.get('name') theme = self.request.get('theme') description = self.request.get('description') imagelink = self.request.get('imagelink') acc = accounts_dao.authorize_api(account_id, api_key) logdiction = {'event':'createbadge', 'ip':self.request.remote_addr, 'is_api':'yes', 'api':'createbadge', 'account':account_id, 'success':'true'} if not acc: logdiction['success'] = 'false' logdiction['details'] = auth_error() logs.create(logdiction) self.response.out.write(auth_error()) return if not imagelink or not badge_name or not theme or not description: logdiction['success'] = 'false' logdiction['details'] = bad_args() logs.create(logdiction) self.response.out.write(bad_args()) return badge_key = badges_dao.create_badge_key(account_id, theme, badge_name, "private") logdiction['details'] = badge_key + " " + imagelink result = "" try: result = urlfetch.fetch(url=imagelink) except: error("Unable to download badge") self.response.out.write(bad_args()) return imgbuf = result.content if len(imgbuf) == 0: error("One of the downloads did not work! url:%s"%newbadge) self.response.out.write(bad_args()) return def get_file_ext(filename): ii = filename.rfind(".") if ii == -1: return "png" else: return filename[ii + 1:] file_name = files.blobstore.create(mime_type='image/'+ get_file_ext(imagelink)) with files.open(file_name, 'a') as f: f.write(imgbuf) files.finalize(file_name) blob_key = files.blobstore.get_blob_key(file_name) blob_info = blobstore.BlobInfo.get(blob_key) badges_dao.create_badge_type(badge_key, badge_name, description, acc, theme, get_file_ext(imagelink), blob_info=blob_info) self.response.out.write(success_ret()) return
def post(self): isLocal = os.environ['SERVER_SOFTWARE'].startswith('Dev') if not isLocal: return secret = self.request.get('secret') if secret != TOPSECRET: bad_args() return api_key = self.request.get('apikey') account_id = self.request.get('accountid') badge_id = self.request.get('badgeid') badge_theme = self.request.get('theme') if not badge_theme or not badge_id or not account_id or not api_key: ret = bad_args() self.response.out.write(ret) return acc = accounts_dao.create_account(account_id, "xxx000xxx", enable=True) from serverside.entities import memcache_db acc.apiKey = "ABCDEFGHI" memcache_db.save_entity(acc, account_id) # remote paths are used because the SDK cannot fetch from itself # because it is single threaded and would cause deadlock badge_list = ["http://cdn2.iconfinder.com/data/icons/crystalproject/128x128/apps/keditbookmarks.png", "http://cdn4.iconfinder.com/data/icons/Merry_Christmas_by_jj_maxer/golden%20star.png", "http://cdn1.iconfinder.com/data/icons/CrystalClear/128x128/actions/bookmark.png", "http://cdn4.iconfinder.com/data/icons/token/Token,%20128x128,%20PNG/Star-Favorites.png", "http://cdn4.iconfinder.com/data/icons/supermario/PNG/Star.png", "http://cdn5.iconfinder.com/data/icons/SOPHISTIQUE/graphics/png/128/star.png", "http://cdn3.iconfinder.com/data/icons/humano2/128x128/actions/bookmark-new.png", "http://cdn2.iconfinder.com/data/icons/web2/Icons/Favorite_128x128.png", "http://cdn5.iconfinder.com/data/icons/water_gaming_pack/128/star_wars_battlefront.png", "http://cdn2.iconfinder.com/data/icons/spaceinvaders/blackhole.png"] # Create ten badges for ii in range(0,10): newbadge = badge_list[ii] try: result = urlfetch.fetch(url=newbadge) except: error("Is one of the badges no longer available? Check %s"%newbadge) return imgbuf = result.content if len(imgbuf) == 0: error("One of the downloads did not work! url:%s"%newbadge) return badge_key = badges_dao.create_badge_key(account_id, badge_theme, str(ii), "private") # Create the file file_name = files.blobstore.create(mime_type='application/octet-stream') # Open the file and write to it with files.open(file_name, 'a') as f: f.write(imgbuf) # Finalize the file. Do this before attempting to read it. files.finalize(file_name) # Get the file's blob key blob_key = files.blobstore.get_blob_key(file_name) blob_info = blobstore.BlobInfo.get(blob_key) # TODO test with different types of images badges_dao.create_badge_type(badge_key, str(ii), "badge description", acc, badge_theme, "png", blob_info=blob_info) # End of for loop self.response.out.write(success_ret()) return
def post(self): #TODO # IN the future we should try to move this logic to data access utility layer # and have the handler portion be in console.py current_session = Session().get_current_session(self) account = current_session.get_account_entity() if not account: self.response.out.write( "Problem with your account. Please email support.") return #TODO make sure badge name is not taken, or warn if overwritting badge_name = self.request.get("badgename") badge_name = string.replace(badge_name, " ", "_") badge_name = string.replace(badge_name, "-", "_") badge_theme = self.request.get("badgetheme") badge_theme = string.replace(badge_theme, "-", "_") badge_theme = string.replace(badge_theme, " ", "_") badge_des = self.request.get("badgedescription") upload_files = self.get_uploads('file') blob_info = upload_files[0] badge_file_name = blob_info.filename badge_ext = get_file_ext(badge_file_name) if badge_ext not in constants.IMAGE_PARAMS.VALID_EXT_TYPES: self.redirect_error("Image must be png, jpeg, or gif") return logging.info("File ext:" + badge_ext) if not badge_name: self.redirect_error("No name given") return if not badge_des: self.redirect_error("No description given") return if not badge_theme: self.redirect_error("No theme given") return if not blob_info: self.redirect_error("No file given") return if blob_info.size > constants.MAX_BADGE_SIZE: self.redirect_error("File is too large. Must be smaller than " + str(constants.MAX_BADGE_SIZE) + " bytes") return perm = "private" if account.email == constants.ADMIN_ACCOUNT: perm = "public" badge_key = badges_dao.create_badge_key(account.email, badge_theme, badge_name, perm) badge = badges_dao.create_badge_type(badge_key, badge_name, badge_des, account, badge_theme, badge_ext, blob_info=blob_info) self.redirect('/adminconsole/badges') return # redirect to badge download for viewing values = { "badge_upload_success": True, "account_name": account.email, "badgekey": badge_key, "badgeLink": badge.downloadLink, "badgedescription": badge_des, "badgealt": badge_des, "badgename": badge_name, "badgeperm": perm } self.response.out.write( template.render(TEMPLATE_PATHS.CONSOLE_DASHBOARD, values))
def post(self): #TODO # IN the future we should try to move this logic to data access utility layer # and have the handler portion be in console.py current_session = Session().get_current_session(self) account = current_session.get_account_entity() if not account: self.response.out.write("Problem with your account. Please email support.") return #TODO make sure badge name is not taken, or warn if overwritting badge_name = self.request.get("badgename") badge_name = string.replace(badge_name, " ", "_") badge_name = string.replace(badge_name, "-", "_") badge_theme = self.request.get("badgetheme") badge_theme= string.replace(badge_theme, "-", "_") badge_theme = string.replace(badge_theme, " ", "_") badge_des = self.request.get("badgedescription") upload_files = self.get_uploads('file') blob_info = upload_files[0] badge_file_name = blob_info.filename badge_ext = get_file_ext(badge_file_name) if badge_ext not in constants.IMAGE_PARAMS.VALID_EXT_TYPES: self.redirect_error("Image must be png, jpeg, or gif") return logging.info("File ext:"+badge_ext) if not badge_name: self.redirect_error("No name given") return if not badge_des: self.redirect_error("No description given") return if not badge_theme: self.redirect_error("No theme given") return if not blob_info: self.redirect_error("No file given") return if blob_info.size > constants.MAX_BADGE_SIZE: self.redirect_error("File is too large. Must be smaller than " + str(constants.MAX_BADGE_SIZE) + " bytes") return perm = "private" if account.email == constants.ADMIN_ACCOUNT: perm = "public" badge_key = badges_dao.create_badge_key(account.email, badge_theme, badge_name, perm) badge = badges_dao.create_badge_type(badge_key, badge_name, badge_des, account, badge_theme, badge_ext, blob_info=blob_info) self.redirect('/adminconsole/badges') return # redirect to badge download for viewing values = {"badge_upload_success": True, "account_name": account.email, "badgekey": badge_key, "badgeLink": badge.downloadLink, "badgedescription": badge_des, "badgealt": badge_des, "badgename": badge_name, "badgeperm": perm} self.response.out.write(template.render(TEMPLATE_PATHS.CONSOLE_DASHBOARD, values))