def makeResourceUpdater(): # check for user login token in cookies _user = getLoggedInUser(request) if _user != None: return template('tpl/js/resourceUpdate', user=_user) else: redirect('/userLogin')
def error404(error): _user = getLoggedInUser(request) if _user != None: return template('tpl/pages/404', chunks=CHUNKS, user=_user, config=Settings(MASTER_CONFIG, showBG=False), pageTitle="LOST IN SPACE") else: redirect('/userLogin')
def systemView(): _user = getLoggedInUser(request) if _user != None: return template('tpl/systemView', user=_user, chunks=CHUNKS, config=Settings('default',showFrame=False,showResources=False,showBG=False,controlBG=True), pageTitle="system View" ) else: redirect('/userLogin')
def setLoginCookie(): uid = request.forms.get('userid') pw = request.forms.get('password') rem = request.forms.get('remember_me') _user = USERS.getUserByName(uid) # TODO: replace this with db lookup if _user: # if user has existing login if uid in demoIDs or False: # TODO: replace this false with password check loginToken = uid+"loginToken"+''.join(random.choice(string.ascii_letters + string.digits) for _ in range(5)) userObj = getProfile(uid) try: USERS.addUser(userObj,loginToken) except ValueError as e: print e.message response.set_cookie("cosmosium_login",loginToken,max_age=60*60*5) redirect('/play') else: return userLogin('user not found')
def makeContentHTML(): name=request.query.name # content page name subDir = request.query.section=request.query.section # specific section of page (like type of research page) # check for user login token in cookies if request.get_cookie("cosmosium_login"): userLoginToken = request.get_cookie("cosmosium_login") try: _user = USERS.getUserByToken(userLoginToken) except (KeyError, ReferenceError) as E: # user token not found or user has been garbage-collected redirect('/userLogin') treeimg='' if name == 'research': # then get research subDir info if subDir=='spaceIndustry': treeimg="img/space_industry_tech_tree_images.svg"; elif subDir=='humanHabitation': treeimg="img/space_industry_tech_tree.svg"; elif subDir=='roboticsAndAI': treeimg="img/space_industry_tech_tree_images.svg"; else: return template('tpl/content/404') # error404('404') fileName='tpl/content/'+name if os.path.isfile(fileName+'.tpl'): #if file exists, use it return template(fileName, tree_src=treeimg, #used only for research pages chunks=CHUNKS, user=_user, oois=GAMES.games[0].OOIs, config=Settings(MASTER_CONFIG), pageTitle=name) else: # else show content under construction print 'unknown content request: '+fileName return template('tpl/content/under_construction') else: redirect('/userLogin')