class ShowUserHandler(webapp.RequestHandler): def get(self): self.session = Session() pkey = self.session.get('userkey') current_user = db.get(pkey) if current_user.admin == "True": doRender(self, 'show_user.html', { }) else: doRender(self, 'main.html', {'msg' : 'Require admin previlege!'}) def post(self): self.session = Session() pkey = self.session.get('userkey') current_user = db.get(pkey) if current_user.admin == "False": doRender(self, 'main.html', {'msg' : 'Require admin previlege!'}) return que = db.Query(User) if self.request.get('show_admin') == 'True': # if this will show admin admin = que.filter('admin =', 'True') admin = admin.fetch(limit = 100) doRender(self, 'show_user.html', {'user_list' : admin } ) return else: user = que.filter('admin =', 'False') user = user.fetch(limit = 500) doRender(self, 'show_user.html', {'user_list' : user } ) return
class LoginHandler(webapp.RequestHandler): def get(self): doRender(self, "loginscreen.htm") def post(self): self.session = Session() acct = self.request.get("account") pw = self.request.get("password") logging.info("Checking account=" + acct + " pw=" + pw) self.session.delete_item("username") self.session.delete_item("userkey") if pw == "" or acct == "": doRender(self, "loginscreen.htm", {"error": "Please specify Account and Password"}) return que = db.Query(User) que = que.filter("account =", acct) que = que.filter("password = "******"userkey"] = user.key() self.session["username"] = acct doRender(self, "index.htm", {}) else: doRender(self, "loginscreen.htm", {"error": "Incorrect password"})
def post(self): self.session = Session() mode = self.session.get("mode") msg = self.session.get("msg") txtinput = self.request.get('method') if (txtinput == 't'): txtinput = "You have chosen Transposition cipher. Your mode is " + mode + " and your message is " + msg + ". Please enter a key(1<= key <= length of your message) (ex: tkey-3)" elif (txtinput == 'key'): key = int(self.request.get("keystr")) maxlen = len(msg) trans = transposition.TranspositionCipherTool(mode, msg, maxlen) keynum = trans.display() if (key >= 1 and key <= int(maxlen)): trans.storekey(key) translated = trans.getTranslatedMessage() txtinput = "Your translated message is " + translated else: self.session.delete_item("msg") txtinput = "Your key is not valid. Please re-enter a new message( ex: tmsg-{'This is message'})" elif (txtinput == 'tmsg'): msg = self.request.get("keystr") self.session['msg'] = msg txtinput = "Please enter a key(1<= key <= length of your message) (ex: tkey-3)" array = {'text': txtinput} # Output the JSON self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(array))
class SubstitutionHandler(webapp.RequestHandler): def post(self): self.session = Session() mode = self.session.get("mode") msg = self.session.get("msg") txtinput = self.request.get('method') if (txtinput == 's'): txtinput = "You have chosen Substitution. Your mode is " + mode + " and your message is " + msg + ". Please enter the 26-letter string of characters to use as a key (ex skey-QWERTYUIOPASDFGHJKLZXCVBNM)" elif (txtinput == 'key'): key = str(self.request.get("keystr")) subs = substitution.SubstitutionCipherTool(mode, msg) if (subs.checkValidKey(key) != True): txtinput = "The key you entered is not valid. Please re-enter the 26-letter string of characters to use as a key (ex skey-QWERTYUIOPASDFGHJKLZXCVBNM)" else: subs.storekey(key) translated = subs.getTranslatedMessage() txtinput = "Your translated message is " + translated array = {'text': txtinput} # Output the JSON self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(array))
def post(self): self.session = Session() mode = self.session.get("mode") msg = self.session.get("msg") txtinput = self.request.get('method') if (txtinput == 'c'): txtinput = "You have chosen Caesar cipher. Your mode is " + mode + " and your message is " + msg + ". Please enter key size(1-26) as key-{key size} (ex ckey-22)" elif (txtinput == 'key'): key = self.request.get("keynum") caes = caesar.CaesarCipherTool(mode, msg) #get key if (int(key) >= 1 and int(key) <= 26): txtinput = "Your key is " + key caes.storekey(key) txtinput = "Your translated message: " + caes.getTranslatedMessage( ) + ". Please type tb for toolbox, h for help" else: txtinput = "Your key is not valid it must be in range (1 <= key <= 26). Please try again. key-{key size} (ex ckey-22)" + key array = {'text': txtinput} # Output the JSON self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(array))
def get(self): self.session = Session() level = self.session.get("userCheck") username = self.session.get("username") userid = self.session.get("id") #Create new db for student result = (db.GqlQuery("SELECT * FROM StudentDB WHERE student_id = :1", userid)).get() result.attempt = level result.put() level = str(level) addr = "game" + level msg = "Your game is saved" temp = os.path.join(os.path.dirname(__file__), 'templates/' + addr + '.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write( str( template.render(temp, { "username": username, 'msg': msg, "level": level + " / 5" })))
def post(self): self.session = Session() mode = self.session.get("mode") msg = self.session.get("msg") symbols = """ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\] ^_`abcdefghijklmnopqrstuvwxyz{|}~""" lenofsym = len(symbols) maxsize = len(msg) txtinput = self.request.get('method') if (txtinput == 'a'): txtinput = "You have chosen Affine cipher. Your mode is " + mode + " and your message is " + msg + ". Please enter a key (ex: akey-87)." elif (txtinput == 'key'): key = self.request.get("keynum") aff = affine.AffineCipherTool(mode, msg, maxsize, lenofsym) #get key if (aff.storeKey(key) == False): txtinput = aff.badKey else: translated = aff.getTranslatedMessage() txtinput = "Your translated message is " + translated array = {'text': txtinput} # Output the JSON self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(array))
class LogoutHandler(webapp.RequestHandler): def get(self): self.session = Session() self.session.delete_item('username') self.session.delete_item('userkey') doRender(self, 'index.htm')
class SubstitutionHandler(webapp.RequestHandler): def post(self): self.session=Session() mode = self.session.get("mode") msg=self.session.get("msg") txtinput = self.request.get('method') if (txtinput=='s'): txtinput="You have chosen Substitution. Your mode is " + mode +" and your message is " + msg +". Please enter the 26-letter string of characters to use as a key (ex skey-QWERTYUIOPASDFGHJKLZXCVBNM)" elif (txtinput == 'key'): key=str(self.request.get("keystr")) subs = substitution.SubstitutionCipherTool(mode,msg) if (subs.checkValidKey(key) != True): txtinput="The key you entered is not valid. Please re-enter the 26-letter string of characters to use as a key (ex skey-QWERTYUIOPASDFGHJKLZXCVBNM)" else: subs.storekey(key) translated=subs.getTranslatedMessage() txtinput="Your translated message is " + translated else: txtinput="Error, invalid command! Please type again. Please select which cipher you would like to use - Caesar cipher(c), Substitution cipher(s), Transposition cipher(t), Vigenere cipher(v), or Affine cipher(a). Please type \"use-cipher method\"(ex - use-s)" array = {'text': txtinput} # Output the JSON self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(array))
class VigenereHandler(webapp.RequestHandler): def post(self): self.session=Session() mode = self.session.get("mode") msg=self.session.get("msg") txtinput = self.request.get('method') if (txtinput=='v'): txtinput="You have chosen Vigenere cipher. Your mode is " + mode +" and your message is " + msg +". Please enter a string of letters to use as a key(ex: vkey-ELFMENG)" elif (txtinput == 'key'): key=self.request.get("keystr") vig = vigenere.VigenereCipherTool(mode,msg) vig.storekey(key) translated=vig.getTranslatedMessage() txtinput="Your translated message is " + translated array = {'text': txtinput} # Output the JSON self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(array))
class SubstitutionHandler(webapp.RequestHandler): def post(self): self.session=Session() mode = self.session.get("mode") msg=self.session.get("msg") txtinput = self.request.get('method') if (txtinput=='s'): txtinput="You have chosen Substitution. Your mode is " + mode +" and your message is " + msg +". Please enter the 26-letter string of characters to use as a key (ex skey-QWERTYUIOPASDFGHJKLZXCVBNM)" elif (txtinput == 'key'): key=str(self.request.get("keystr")) subs = substitution.SubstitutionCipherTool(mode,msg) if (subs.checkValidKey(key) != True): txtinput="The key you entered is not valid. Please re-enter the 26-letter string of characters to use as a key (ex skey-QWERTYUIOPASDFGHJKLZXCVBNM)" else: subs.storekey(key) translated=subs.getTranslatedMessage() txtinput="Your translated message is " + translated array = {'text': txtinput} # Output the JSON self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(array))
def post(self): self.session = Session() name = self.request.get('name') acct = self.request.get('account') pw = self.request.get('password') logging.info('Adding account='+acct) if pw == '' or acct == '' or name == '': doRender( self, 'applyscreen.htm', {'error' : 'Please fill in all fields'} ) return # Check if the user already exists que = db.Query(User).filter('account =',acct) results = que.fetch(limit=1) if len(results) > 0 : doRender( self, 'applyscreen.htm', {'error' : 'Account Already Exists'} ) return # Create the User object and log the user in newuser = User(name=name, account=acct, password=pw); pkey = newuser.put(); self.session['username'] = acct self.session['userkey'] = pkey self.session = Session() doRender(self,'index.htm',{ })
class LogoutHandler(webapp.RequestHandler): def get(self): self.session = Session() self.session.delete_item('username') self.session.delete_item('user_key') doRender(self, 'index.htm')
def get(self): self.session = Session() if 'username' in self.session: del self.session['username'] self.session.delete_item('username') self.session.delete_item('userkey') doRender(self, '/index.html')
class TDSettingHandler(BaseHandler): def get(self): if self.guest(): return self.session = Session() key = self.session.get('userkey') user = db.get(key) form = UserForm() self.doRender( 'td_setting.html', {'form': form, 'u': user, \ 'info': ', please update your profile'}) def post(self): self.session = Session() pkey = self.session.get('userkey') user = db.get(pkey) form = UserForm(self.request.POST) if form.validate(): user.cwid = form.cwid.data user.major = form.major.data user.email = form.email.data user.phone = form.phone.data user.d_hours = form.d_hours.data user.put() self.doRender( 'td_setting.html', {'msg' : ', profile updated', 'u': user} ) else: # form validation failed self.doRender('td_setting.html', {'form': form})
class CaesarHandler(webapp.RequestHandler): def post(self): self.session=Session() mode = self.session.get("mode") msg=self.session.get("msg") txtinput = self.request.get('method') if (txtinput=='c'): txtinput="You have chosen Caesar cipher. Your mode is " + mode +" and your message is " + msg +". Please enter key size(1-26) as key-{key size} (ex ckey-22)" elif (txtinput == 'key'): key=self.request.get("keynum") caes = caesar.CaesarCipherTool(mode,msg) #get key if(int(key) >= 1 and int(key) <= 26): txtinput="Your key is " + key caes.storekey(key) txtinput="Your translated message: " + caes.getTranslatedMessage() + ". Please type tb for toolbox, h for help" else: txtinput="Your key is not valid it must be in range (1 <= key <= 26). Please try again. key-{key size} (ex ckey-22)" + key array = {'text': txtinput} # Output the JSON self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(array))
def post(self): logging.info('Login Attempt') self.session = Session() acct = self.request.get('account') pw = self.request.get('password') #logging.info('Checking account='+acct+' pw='+pw) self.session.delete_item('username') if pw == '' or acct == '': doRender(self, 'loginscreen.htm', {'error': 'Please specify Email and Password'}) return logging.info('password: '******'': #Salts Password for db check pw = functions.getSaltedHash(pw) logging.info('password: '******'account =', acct) que = que.filter('password = '******'username'] = acct doRender(self, 'index.htm', {}) else: doRender(self, 'loginscreen.htm', {'error': 'Incorrect password'})
def post(self): self.session = Session() acct = self.request.get('account') pw = self.request.get('password') logging.info('Checking account='+acct+' pw='+pw) # Make sure no other user is login self.session.delete_item('username') self.session.delete_item('userkey') # Still no sender or transporter self.session['senderflag'] = False self.session['transporterflag'] = False # Check if there is a registered user que = db.Query(User) que = que.filter('account =',acct) que = que.filter('password = '******'userkey'] = user.key() self.session['username'] = acct doRender(self,'StartPage.html',{ } ) else: doRender(self,'login.html', {'error' : 'Please fill in the correct details!'})
def get(self): logging.info('RatingsHandler.get()') self.session = Session() if 'user_key' not in self.session: logging.warn('User attempting to access ratings without logging in') return drink_id = self.request.get('drink_id') user_key = self.session.get('user_key') if(drink_id == ''): logging.warn('RatingsHandler called with no drink-id') return # get current user's rating of drink (if any) drink = Drink.get_by_id(int(drink_id)) if drink is None: logging.warn("drink not found for id == " + drink_id) return else: logging.info(drink) query1 = db.Query(DrinkRating).filter('drink = ', drink.key()).filter('ratedBy = ', user_key) my_rating = query1.get() if my_rating is None: my_score = 0 else: my_score = my_rating.score # get average rating query2 = db.Query(AverageRating).filter('drink = ',drink.key()) ave_rating = query2.get() logging.info(ave_rating) if ave_rating is None: ave_score = 0.0 else: ave_score = ave_rating.ave_score doRender(self,'ratings.html',{'drink_key':drink.key(), 'drink_id':drink.key().id(), 'ave_score':ave_score, 'my_score':my_score})
def get(self): self.session = Session() start_msg = "" gid = self.request.get("gid") self.session['game_id'] = gid #get current level for game id result_game = (db.GqlQuery("SELECT * FROM GameDB WHERE game_id = :1", gid)).get() glevel = result_game.current_level if (glevel): start_msg = "START THE GAME" #level=self.request.get("level") if (self.session.get('level')): self.session.delete_item('level') self.session['level'] = glevel temp = os.path.join(os.path.dirname(__file__), 'templates/gameload.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write( str( template.render(temp, { "start_msg": start_msg, "level": glevel })))
def post(self): self.session = Session() un = self.request.get('username') pw = self.request.get('password') self.session.delete_item('username') self.session.delete_item('userkey') if pw == '' or un == '': doRender(self, 'loginscreen.html', {'error': 'Please specify Username and Password'}) return que = db.Query(User) que = que.filter('username ='******'password ='******'userkey'] = user.key() self.session['username'] = un doRender(self, 'main.html', {}) # if ok, go to main.html (logged in) else: doRender(self, 'loginscreen.html', {'error': 'Username or Password wrong'})
class LogoutHandler(webapp.RequestHandler): def get(self): self.session = Session() un = self.session.get('username') self.session.delete_item('username') self.session.delete_item('userkey') doRender(self, 'index.html', {'msg' : un + ' logout successful.'} )
class LoginHandler(webapp.RequestHandler): def get(self): doRender(self, 'loginscreen.htm') def post(self): self.session = Session() acct = self.request.get('account') pw = self.request.get('password') logging.info('Checking account='+acct+' pw='+pw) self.session.delete_item('username') if pw == '' or acct == '': doRender( self, 'loginscreen.htm', {'error' : 'Please specify Account and Password'} ) return que = db.Query(User) que = que.filter('account =',acct) que = que.filter('password = '******'username'] = acct doRender(self,'index.htm',{ } ) else: doRender( self, 'loginscreen.htm', {'error' : 'Incorrect password'} )
class LogoutHandler(webapp.RequestHandler): def get(self): self.session = Session() un = self.session.get('username') self.session.delete_item('username') self.session.delete_item('userkey') doRender(self, 'index.html', {'msg': un + ' logout successful.'})
class ShowUserHandler(webapp.RequestHandler): def get(self): self.session = Session() pkey = self.session.get('userkey') current_user = db.get(pkey) if current_user.admin == "True": doRender(self, 'show_user.html', {}) else: doRender(self, 'main.html', {'msg': 'Require admin previlege!'}) def post(self): self.session = Session() pkey = self.session.get('userkey') current_user = db.get(pkey) if current_user.admin == "False": doRender(self, 'main.html', {'msg': 'Require admin previlege!'}) return que = db.Query(User) if self.request.get('show_admin') == 'True': # if this will show admin admin = que.filter('admin =', 'True') admin = admin.fetch(limit=100) doRender(self, 'show_user.html', {'user_list': admin}) return else: user = que.filter('admin =', 'False') user = user.fetch(limit=500) doRender(self, 'show_user.html', {'user_list': user}) return
class LoginHandler(webapp.RequestHandler): def get(self): doRender(self, 'loginscreen.htm') def post(self): self.session = Session() acct = self.request.get('account') pw = self.request.get('password') logging.info('Checking account='+acct+' pw='+pw) self.session.delete_item('username') if pw == '' or acct == '': doRender(self,'loginscreen.htm',{'error' : 'Please specify Account and Password'} ) return que = db.Query(User) que = que.filter('account =',acct) que = que.filter('password = '******'username'] = user.account self.session['user_key'] = user.key() doRender(self,'index.htm',{ } ) else: doRender(self,'loginscreen.htm',{'error' : 'Incorrect password'} )
def post(self): self.session = Session() name = self.request.get('name') emailaddress = self.request.get('emailaddress') password = self.request.get('password') logging.info('Checking emailaddress=' + emailaddress + ' password='******'username') self.session.delete_item('userkey') if name == '' or password == '' or emailaddress == '': doRender(self, 'loginscreen.htm', {'error': 'Please fill all the Fields'}) return que = db.Query(User) que = que.filter('name = ', name) que = que.filter('emailaddress =', emailaddress) que = que.filter('password = '******'userkey'] = user.key() self.session['username'] = name doRender(self, 'profile.htm', {}) else: doRender(self, 'loginscreen.htm', {'error': 'All Details Need to Match!! '}) return
class MainHandler(webapp.RequestHandler): def get (self): #filepath = self.request.path self.session = Session() loggedUser="" greeting="" if (self.session.get('username')): greeting="Welcome, " loggedUser = self.session.get('username') if (self.session.get('role') == 'teacher'): temp = os.path.join(os.path.dirname(__file__), 'templates/teachermain.html') #self.response.out.write(temp) self.response.headers['Content-Type'] = 'text/html' self.response.out.write(str(template.render(temp,{'loggedUser':loggedUser, "greeting":greeting}))) elif (self.session.get('role') == 'student'): temp = os.path.join(os.path.dirname(__file__), 'templates/studentmain.html') #self.response.out.write(temp) self.response.headers['Content-Type'] = 'text/html' self.response.out.write(str(template.render(temp,{'loggedUser':loggedUser, "greeting":greeting}))) else: temp = os.path.join(os.path.dirname(__file__), 'templates/main.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write(str(template.render(temp,{'loggedUser':loggedUser, "greeting":greeting})))
class LogOutHandler(webapp.RequestHandler): def get(self): self.session = Session() self.session.delete_item('user') self.redirect('main.html')
def post(self): self.session = Session() acct = self.request.get('account') pw = self.request.get('password') #logging.info('Checking account='+acct+' pw='+pw) self.session.delete_item('username') self.session.delete_item('userkey') if pw == '' or acct == '': doRender(self, 'loginscreen.html', {'error' : 'Please specify Acct and PW'} ) return # Check to see if our data is correct que = db.Query(User) que = que.filter('account =',acct) que = que.filter('password = '******'userkey'] = user.key() self.session['username'] = acct doRender(self,'index.html',{ } ) else: doRender(self,'loginscreen.html',{'error' : 'Incorrect password'} )
class VigenereHandler(webapp.RequestHandler): def post(self): self.session=Session() mode = self.session.get("mode") msg=self.session.get("msg") txtinput = self.request.get('method') if (txtinput=='v'): txtinput="You have chosen Vigenere cipher. Your mode is " + mode +" and your message is " + msg +". Please enter a string of letters to use as a key(ex: vkey-ELFMENG)" elif (txtinput == 'key'): key=self.request.get("keystr") vig = vigenere.VigenereCipherTool(mode,msg) vig.storekey(key) translated=vig.getTranslatedMessage() txtinput="Your translated message is " + translated else: txtinput="Error, invalid command! Please type again. Please select which cipher you would like to use - Caesar cipher(c), Substitution cipher(s), Transposition cipher(t), Vigenere cipher(v), or Affine cipher(a). Please type \"use-cipher method\"(ex - use-s)" array = {'text': txtinput} # Output the JSON self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(array))
class CaesarHandler(webapp.RequestHandler): def post(self): self.session=Session() mode = self.session.get("mode") msg=self.session.get("msg") txtinput = self.request.get('method') if (txtinput=='c'): txtinput="You have chosen Caesar cipher. Your mode is " + mode +" and your message is " + msg +". Please enter key size(1-26) as key-{key size} (ex ckey-22)" elif (txtinput == 'key'): key=self.request.get("keynum") caes = caesar.CaesarCipherTool(mode,msg) #get key if(int(key) >= 1 and int(key) <= 26): txtinput="Your key is " + key caes.storekey(key) txtinput="Your translated message: " + caes.getTranslatedMessage() + ". Please type tb for toolbox, h for help" else: txtinput="Your key is not valid it must be in range (1 <= key <= 26). Please try again. key-{key size} (ex ckey-22)" + key else: txtinput="Error, invalid command! Please type again. Please select which cipher you would like to use - Caesar cipher(c), Substitution cipher(s), Transposition cipher(t), Vigenere cipher(v), or Affine cipher(a). Please type \"use-cipher method\"(ex - use-s)" array = {'text': txtinput} # Output the JSON self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(array))
def get(self): self.session = Session() pkey = self.session.get('userkey') current_user = db.get(pkey) if current_user.admin == "True": doRender(self, 'show_user.html', {}) else: doRender(self, 'main.html', {'msg': 'Require admin previlege!'})
class logout(webapp.RequestHandler): def get(self): self.session = Session() self.session.delete_item('username') render(self,"logout.html") def post(self): render()
class LogoutHandler(webapp.RequestHandler): def get(self): self.session = Session() if 'username' in self.session: del self.session['username'] self.session.delete_item('username') self.session.delete_item('userkey') doRender(self, '/index.html')
class LogoutHandler(webapp.RequestHandler): def get(self): self.session=Session() self.session.delete_item('username') self.session.delete_item('ft_client') path=self.request.path temp=os.path.join(os.path.dirname(__file__),'templates/index.html') html=template.render(temp,{'path':path}) self.response.out.write(html)
class SmainHandler(webapp.RequestHandler): def get(self): self.session = Session() userid = self.session.get("id") username = self.session.get("username") operation = self.request.get("op") error_msg = "" goback = "" #control if (operation == '0'): result = (db.GqlQuery("SELECT * FROM GameDB WHERE student_id = :1", userid)).fetch(limit=100) temp = os.path.join(os.path.dirname(__file__), 'templates/scontrol.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write( str( template.render(temp, { "loggedUser": username, "result": result }))) #start a new game elif (operation == '1'): temp = os.path.join(os.path.dirname(__file__), 'templates/sgameintro.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write( str(template.render(temp, {"username": username}))) elif (operation == '2'): greeting = "Hello, " temp = os.path.join(os.path.dirname(__file__), 'templates/gameload.html') result = (db.GqlQuery("SELECT * FROM GameDB WHERE student_id = :1", userid)).fetch(limit=100) if (len(result) == 0): error_msg = "Error! No saved game!" goback = "Back to Main" self.response.headers['Content-Type'] = 'text/html' self.response.out.write( str( template.render( temp, { "greeting": greeting, "username": userid, "result": result, "error_msg": error_msg, "goback": goback }))) else: temp = os.path.join(os.path.dirname(__file__), 'templates/main.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write(str(template.render(temp, {})))
def get(self): self.session = Session() self.session.delete_item('username') self.session.delete_item('userkey') self.session.delete_item('sender_key') self.session.delete_item('transporter_key') self.session.delete_item('senderflag') self.session.delete_item('transporterflag') self.session.delete_item('matchingkey') doRender(self, 'login.html')
def post(self): self.session = Session() guess_capital = str(self.request.get('capital')) for country in country_data: if country['name'] == self.session['country']: self.session['capital'] = country['capital'] true_capital = self.session['capital'] if guess_capital != true_capital: doRender(self, 'country.html', {'error': 'Guess again...'}) else: doRender(self, 'capital.html', {'capital': true_capital})
class TmainHandler(webapp.RequestHandler): def get(self): self.session=Session() logged_name=self.session.get("username") logged_id=self.session.get("id") greeting="Hello" lookup=(db.GqlQuery("SELECT * FROM TeacherDB WHERE teacher_id = :1", logged_id)).get() classid_teacher=lookup.teacher_class_id result=(db.GqlQuery("SELECT * FROM StudentDB WHERE classid = :1", classid_teacher)).fetch(limit=100) temp = os.path.join(os.path.dirname(__file__), 'templates/tcontrol.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write(str(template.render(temp,{'loggedUser':logged_id, "greeting":greeting,"result":result})))
class MainHandler(webapp.RequestHandler): def get(self): #filepath = self.request.path self.session = Session() loggedUser = "" greeting = "" if (self.session.get('username')): greeting = "Welcome, " loggedUser = self.session.get('username') if (self.session.get('role') == 'teacher'): temp = os.path.join(os.path.dirname(__file__), 'templates/teachermain.html') #self.response.out.write(temp) self.response.headers['Content-Type'] = 'text/html' self.response.out.write( str( template.render(temp, { 'loggedUser': loggedUser, "greeting": greeting }))) elif (self.session.get('role') == 'student'): temp = os.path.join(os.path.dirname(__file__), 'templates/studentmain.html') #self.response.out.write(temp) self.response.headers['Content-Type'] = 'text/html' self.response.out.write( str( template.render(temp, { 'loggedUser': loggedUser, "greeting": greeting }))) else: temp = os.path.join(os.path.dirname(__file__), 'templates/main.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write( str( template.render(temp, { 'loggedUser': loggedUser, "greeting": greeting })))
def get(self): self.session = Session() self.session.delete_item('username') self.session.delete_item('role') self.session.delete_item('tid') self.session.delete_item('level') self.session.delete_item('game_id') msg = "Thank you for playing. Bye!" temp = os.path.join(os.path.dirname(__file__), 'templates/logout.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write(str(template.render(temp, {"logoutmsg": msg})))
def post(self): self.session = Session() pkey = self.session.get('userkey') current_user = db.get(pkey) t_rname = self.request.get('name') t_camera = self.request.get('camera') t_size = self.request.get('size') new_location = Location(rname=t_rname, camera=t_camera, size=t_size) new_location.put() que = db.Query(Location) location_list = que.fetch(limit=5000) doRender(self, 'setting.html', {'location_list': location_list})
class ExitHandler(webapp.RequestHandler): def get(self): self.session=Session() self.session.delete_item('username') self.session.delete_item('role') self.session.delete_item('tid') self.session.delete_item('level') self.session.delete_item('game_id') msg="Thank you for playing. Bye!" temp = os.path.join(os.path.dirname(__file__), 'templates/logout.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write(str(template.render(temp,{"logoutmsg":msg})))
class CipherInterfaceHandler(webapp.RequestHandler): def get(self): temp=os.path.join(os.path.dirname(__file__), 'templates/sample.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write(str(template.render(temp,{}))) def post(self): # Our POST Input self.session=Session() txtinput = self.request.get('txtValue') txtinput=txtinput.lower() mode=self.request.get('mode') if (txtinput =='show files' or txtinput == 'sf'): txtinput="Show Files: Ciphers.py Subsitution.py transposition.py vigenere.py Affine.py ciphers.py" elif (txtinput == "help" or txtinput =='h'): txtinput="Would you like to go to the tutorial for the Caesar cipher(chelp or ch), Substitution cipher(shelp or sh), Transposition cipher(thelp or th), Vigenere cipher(vhelp or vh), or Affine cipher(ahelp or ah)? You can also type toolbox(toolbox or tb) to use the ciphers." elif(txtinput == "chelp" or txtinput=="ch"): txtinput="The Caesar cipher works by substituting letters for different letters a certain number away from the original letter. For example, the letter 'A' with a key of 2 would become 'C' because C is 2 letters away from 'A'. The word 'CAT' would be encoded to say 'ECV'. To figure out the key to decode a message, you can keep trying numbers between 1 and 26 until one decodes the message into something that makes sense." elif(txtinput == "shelp" or txtinput=="sh"): txtinput="The substitution cipher has a key of 26 letters, each one in the alphabet, all reordered, and matches the old letters of the alphabet to the new ones. So if the letter 'A' maps to 'V' because it is the first letter of the key, 'B' maps to 'Q' because 'Q' is the second letter in the key. If 'T' maps to 'P', the code word for 'TAB' would be 'PVQ'." elif(txtinput == "thelp" or txtinput=="th"): txtinput="The transposition cipher works by mapping different letters to columns in a table, and then putting the rows of the table together to make the ciphertext. For example, to encode the sentence 'The apple is red.' with a key of 3, the cipher will make a table with 3 columns. Because there are 17 characters in this sentence, we take 17/3 which gives 5 with a remainder of 2. This means we need 6 rows and one space will not be used since there are 17 characters and 18 table entries. The cipher will put one letter in each column of the table so that they read [T,h,e; ,a,p;p,l,e; ,i,s; ,r,e;d,.,X] (commas separate columns, semicolumns separate rows) The resulting ciphertext will go down each column one at a time putting together the characters, giving the ciphertext 'T p dhalir.epese'" elif(txtinput == "vhelp" or txtinput=="vh"): txtinput="The Vigenere cipher works almost like the Caesar cipher, except for every letter, the number of letters it shifts is different. The alphabet index of each letter in the key tells how many letters to shift each letter of plaintext. To encode the sentence 'The sky is blue' with the key 'cat', the index of each letter in the key 'cat' is the shift number. The first letter of the message 'T' will shift 3 letters since the first letter of the key is 'c', and its index is 3. So, the first letter of the ciphertext will be 'W'. The next letter will shift 1 because the index of a is one, so 'h' will become 'i'. The index of 't' is 20, so 'e' will shift 20 to become 'y'. When the letters in the key run out, it just starts over, so the next letter of the message 's' will shift 3 to 'v' because the next shift will be the letter 'c' again." elif(txtinput == "ahelp" or txtinput=="ah"): txtinput="The affine cipher has a few more steps than the other ciphers. First, it maps each letter of the plaintext to its alphabetic index starting at 0. The word 'SLEUTH' would map to the numbers 18, 11, 4, 20, 19, 7. Let's say we want to include special characters in our encoded alphabet, which will now have a length of 96 instead of 26. We then need to select two numbers for the key, and the first number has to be coprime with 96, meaning it does not share any factors with 96. Since 96's prime factors are 2 and 3, the first part of the key can be any number not divisible by 2 or 3. Our numbers a and b will be used in the equation ax+b, where x is the letter index and the result of which needs to be bigger than 96 for reasons we'll explain in a minute. We'll choose a to be 31 and b to be 57. When we use each letter's index as x in the equation, we get 615, 398, 181, 677, 646, 274. To map these numbers to our alphabet of symbols and letters, we need them to be mod 96. This means we want to divide them by 96 and use the remainder as the new number. After doing that, our new numbers are 39, 14, 85, 5, 70, 82. To get our key, we can multiply a by 96 and add b, which gives us 3033. Mapping the new numbers to their indexes in our alphabet gives us the ciphertext '&lTcEQ'." elif(txtinput == "tb" or txtinput=='toolbox'): txtinput="You have selected toolbox. Please select a mode(e for Encryption, d for Decryption) and type a message( ex: d-Hello )?" elif(mode=='e' or mode=='d'): self.session.delete_item('mode') self.session['mode']=mode msg=self.request.get('msg') self.session.delete_item('msg') self.session['msg']=msg if (mode =='e'): mo="Encryption" else: mo="Decryption" txtinput="You have chosen " + mo +" and your message is " + msg + ". Please select which cipher you would like to use - Caesar cipher(c), Substitution cipher(s), Transposition cipher(t), Vigenere cipher(v), or Affine cipher(a). Please type \"use-cipher method\"(ex - use-s)" else: txtinput="Error, invalid command! Please type again." array = {'text': txtinput} # Output the JSON self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(array))
class DeleteUserHandler(webapp.RequestHandler): def post(self): self.session = Session() pkey = self.session.get('userkey') current_user = db.get(pkey) if current_user.admin == "False": doRender(self, 'main.html', {'msg': 'Require admin previlege!'}) return delete_list = self.request.get_all('key_to_delete') ''' # Testing! doRender(self, 'test.html', {'msg' : first[0], 'msg2': str(len(first))}) return ''' if len(delete_list) == 0: doRender(self, 'show_user.html', {}) return for item in delete_list: que = db.Query(User).filter('username ='******'show_user.html', {})
def post(self): self.session = Session() form = LoginForm(self.request.POST) if form.validate(): self.session.delete_item('username') self.session.delete_item('userkey') self.session.delete_item('admin') un = form.username.data pw = form.password.data m = hashlib.sha224(pw) que = db.Query(User).filter('username ='******'password ='******'password ='******'userkey'] = user.key() self.session['username'] = un self.session['admin'] = user.admin self.redirect('/main') #self.doRender('main.html', {} ) # if ok, go to main.html (logged in) else: self.doRender( 'loginscreen.html', {'error': 'Username or Password wrong', \ 'form': form} ) else: # if form.validate() Fails. self.doRender('loginscreen.html', {'form': form} )
def post(self): if self.guest(): return self.session = Session() pkey = self.session.get('userkey') user = db.get(pkey) # got current user ckey = self.request.get('session_key') csession = db.get(ckey) # got the target session td = csession.td # target session.td event = csession.event # target session.event if event != None: message_list = toList(event) self.doRender('show_event.html', {'td': td, 'session': csession, \ 'event': event, 'session_key': ckey, 'message_list': message_list}) else: # not event yet if td != None and td.username == user.username: self.doRender('add_event.html', {'td': td, 'session': csession, \ 'session_key': ckey, 'apply_off': 'True' }) else: self.doRender('add_event.html', {'td': td, 'session': csession, \ 'session_key': ckey})
def post(self): if self.guest(): return self.session = Session() pkey = self.session.get('userkey') current_user = db.get(pkey) # got user t_note = self.request.get('note') t_active = self.request.get('active_status') ckey = self.request.get('session_key') update = self.request.get('update_event') ckey = self.request.get('session_key') csession = db.get(ckey) # got session td = csession.td # got TD if update == 'True': new_event = csession.event new_event.active = (t_active == 'True') new_message = Message(note = t_note, user = current_user) new_event.messages.append( new_message.put()) new_event.put() else: new_message = Message(note = t_note, user = current_user) new_event = Event(active = t_active == 'True', csession = ckey) new_event.messages.append( new_message.put() ) csession.event = new_event.put() # put event, and, update session.event csession.put() message_list = toList(new_event) self.doRender('show_event.html', {'td': td, 'session': csession, \ 'event': new_event, 'msg':'Event just updated', \ 'message_list': message_list, 'session_key': ckey})
def post(self): self.session = Session() un = self.request.get('username') pw = self.request.get('password') self.session.delete_item('username') self.session.delete_item('userkey') if pw == '' or un == '': doRender( self, 'loginscreen.html', {'error': 'Please specify Username and Password'} ) return que = db.Query(User) que = que.filter('username ='******'password ='******'userkey'] = user.key() self.session['username'] = un doRender(self,'main.html', {} ) # if ok, go to main.html (logged in) else: doRender( self, 'loginscreen.html', {'error' : 'Username or Password wrong' } )
def get(self): data = {} #check if there's a username entry in the session self.session = Session() data['user'] = self.session.get('username', None) render(self, "create_question.html",data)
class DeleteUserHandler(webapp.RequestHandler): def post(self): self.session = Session() pkey = self.session.get('userkey') current_user = db.get(pkey) if current_user.admin == "False": doRender(self, 'main.html', {'msg' : 'Require admin previlege!'}) return delete_list = self.request.get_all('key_to_delete') ''' # Testing! doRender(self, 'test.html', {'msg' : first[0], 'msg2': str(len(first))}) return ''' if len(delete_list) == 0: doRender(self, 'show_user.html', {}) return for item in delete_list: que = db.Query(User).filter('username ='******'show_user.html', {})
def get(self): self.session = Session() que = db.Query(User) user_list = que.fetch(limit=100) newval = dict({}) newval['username'] = self.session['username'] doRender(self, 'memberscreen.htm', newval)
def get(self): self.session=Session() userid=self.session.get("id") username = self.session.get("username") operation = self.request.get("op") error_msg="" goback="" #control if(operation=='0'): result=(db.GqlQuery("SELECT * FROM GameDB WHERE student_id = :1", userid)).fetch(limit=100) temp = os.path.join(os.path.dirname(__file__), 'templates/scontrol.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write(str(template.render(temp,{"loggedUser":username, "result":result}))) #start a new game elif(operation=='1'): temp = os.path.join(os.path.dirname(__file__), 'templates/sgameintro.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write(str(template.render(temp,{"username":username}))) elif(operation=='2'): greeting="Hello, " temp = os.path.join(os.path.dirname(__file__), 'templates/gameload.html') result=(db.GqlQuery("SELECT * FROM GameDB WHERE student_id = :1", userid)).fetch(limit=100) if (len(result) == 0): error_msg="Error! No saved game!" goback="Back to Main" self.response.headers['Content-Type'] = 'text/html' self.response.out.write(str(template.render(temp,{"greeting": greeting, "username":userid, "result":result,"error_msg":error_msg, "goback":goback}))) else: temp = os.path.join(os.path.dirname(__file__), 'templates/main.html') self.response.headers['Content-Type'] = 'text/html' self.response.out.write(str(template.render(temp,{})))
def post(self): self.session=Session() mode = self.session.get("mode") msg=self.session.get("msg") symbols=""" !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\] ^_`abcdefghijklmnopqrstuvwxyz{|}~""" lenofsym=len(symbols) maxsize=len(msg) txtinput = self.request.get('method') if (txtinput=='a'): txtinput="You have chosen Affine cipher. Your mode is " + mode +" and your message is " + msg + ". Please enter a key (ex: akey-87)." elif (txtinput == 'key'): key=self.request.get("keynum") aff = affine.AffineCipherTool(mode,msg,maxsize,lenofsym) #get key if(aff.storeKey(key) == False): txtinput = aff.badKey else: translated = aff.getTranslatedMessage() txtinput="Your translated message is " + translated else: txtinput="Error, invalid command! Please type again. Please select which cipher you would like to use - Caesar cipher(c), Substitution cipher(s), Transposition cipher(t), Vigenere cipher(v), or Affine cipher(a). Please type \"use-cipher method\"(ex - use-s)" array = {'text': txtinput} # Output the JSON self.response.headers['Content-Type'] = 'application/json' self.response.out.write(json.dumps(array))
def post(self): data = {} em = self.request.get('em') pw = self.request.get('pw') self.session = Session() #destroy former session data self.session.delete_item('username') if em =="" and pw == "": data['noCredos'] = True #self.session = Session() #data['user'] = self.session.get('username', None) data['error_msg'] = "pls fill in your email and password" render(self,"login.html",data) else: que = db.Query(Poller) que.filter('email', em) que.filter('password', pw) results = que.fetch(limit=1) if len(results) > 0: self.session['username'] = em #set session data['user'] = em render(self,"create_question.html",data) else: data['usernotfound'] = True data['error_msg'] = "incorrect password or email; pls try again" render(self,"login.html",data)
def doRender(handler, tname='index.html', values={}): if tname == '/' or tname == '' or tname == None: tname = 'index.html' handler.session = Session() flag = True if tname == '/loginscreen.html' or tname == '/register.html' or \ tname =='loginscreen.html' or tname =='register.html': flag = False if handler.session.get('username') == None and flag: tname = 'index.html' temp = os.path.join(os.path.dirname(__file__), 'templates/' + tname) if not os.path.isfile(temp): return False # Make a copy of the dictionary and add basic values newval = dict(values) newval['path'] = handler.request.path if 'username' in handler.session: newval['username'] = handler.session['username'] outstr = template.render(temp, newval) handler.response.out.write(outstr) return True
def post(self): self.session = Session() datastore = DataStoreInterface() email = self.request.get('txtEmail').strip() password = self.request.get('txtPassword') self.session.delete_item('user') #Check for any fields left empty if email == '' or password == '': render.doRender(self, 'main.html', {'error' : 'Please fill in all the details'}) return username = datastore.loginUser(email, password) if datastore.isUser(email)== 1: if datastore.checkPass(email, password)==1: self.session['user'] = username self.redirect('controlpanel.html') else: render.doRender(self, 'main.html', {'error' : 'Wrong password'}) else: render.doRender(self, 'main.html', {'error' : 'Email Address does not exist'})
def post(self): self.session = Session() n = self.request.get("name") un = self.request.get("username") pw = self.request.get("password") if pw == '' or un == '' or n == '': doRender(self, 'register.html', {'error': 'Please fill in all fields'}) return que = db.Query(User).filter('username ='******'register.html', {'error': 'Username already exists'}) return #if success, create new user newuser = User(name=n, username=un, password=pw, admin="False") pkey = newuser.put() self.session['username'] = un self.session['userkey'] = pkey doRender(self, 'register.html', \ {'error' : 'Register Success! Welcome, ' + un} )
def get(self): data = {} #check if there's a username entry in the session self.session = Session() data['user'] = self.session.get('username', None) render(self, "view_responses.html",data)