def autologin(req, username): req.content_type = 'text/html' # don't permit brute force password guessing: time.sleep(1) websutil.sanityCheckUsername(username) s = Session.Session(req) if not s.is_new(): #TODO take the username from session return json.dumps({ 'status': True, 'username': username, 'info': 'Already logged in' }) if not req.connection.remote_ip == '127.0.0.1': s.invalidate() return json.dumps({ 'status': False, 'username': "", 'info': req.connection.remote_ip }) s["username"] = username.lower() s.save() return json.dumps({ 'status': True, 'username': username, 'info': 'Success!' })
def login(req, username, password): #### BIG FAT WARNING: #### # If you ever try to use Vmchecker on a UserDir-type environment # (i.e., ~/public_html), **DON'T**. # It appears that mod_python tries to set a cookie with the path # determined by DocumentRoot. This means that the path itself # gets mangled and the browser doesn't send the cookie back. # # This results in the app never logging in, simply coming back # to the login screen. # # If you have access to the browser config, you can try and # manually set 'ApplicationPath' to '/' in order to circumvent # this. #### / BIG FAT WARNING #### req.content_type = 'text/html' # don't permit brute force password guessing: time.sleep(1) s = Session.Session(req) websutil.sanityCheckUsername(username) if not s.is_new(): #TODO take the username from session return json.dumps({ 'status': True, 'username': username, 'info': 'Already logged in' }) strout = websutil.OutputString() try: user = websutil.get_user(username, password) except: traceback.print_exc(file=strout) return json.dumps({ 'errorType': websutil.ERR_EXCEPTION, 'errorMessage': "", 'errorTrace': strout.get() }) if user is None: s.invalidate() return json.dumps({ 'status': False, 'username': "", 'info': 'Invalid username/password' }) s["username"] = username.lower() s.save() return json.dumps({ 'status': True, 'username': user, 'info': 'Succesfully logged in' })
def getTeamResults(req, courseId, assignmentId, teamname=None, locale=websutil.DEFAULT_LOCALE): """Get the results for a given team name. If the team name is empty, get the results of the current user's team.""" websutil.install_i18n(websutil.sanityCheckLocale(locale)) websutil.sanityCheckAssignmentId(assignmentId) websutil.sanityCheckCourseId(courseId) if teamname != None: websutil.sanityCheckUsername(teamname) req.content_type = 'text/html' strout = websutil.OutputString() # Check permission s = Session.Session(req) if s.is_new(): s.invalidate() return json.dumps({'errorType':websutil.ERR_AUTH, 'errorMessage':"", 'errorTrace':""}) try: s.load() current_user = s['username'] except: traceback.print_exc(file = strout) return json.dumps({'errorType' : websutil.ERR_EXCEPTION, 'errorMessage' : "", 'errorTrace' : strout.get()}) (hasTeam, current_team) = websutil.getAssignmentAccountName(courseId, assignmentId, current_user, strout) if teamname == None: if not hasTeam: # User is not part of any team for the assignment return json.dumps({'errorType' : websutil.ERR_OTHER, 'errorMessage' : "User is not part of any team for this assignment", 'errorTrace' : ""}) teamname = current_team # Reset the timeout s.save() return websutil.getResultsHelper(courseId, assignmentId, current_user, strout, teamname = teamname, currentTeam = current_team)
def getUserResults(req, courseId, assignmentId, username=None, locale=websutil.DEFAULT_LOCALE): """Get the individual results for a given username. If the username is empty, get the results of the current user.""" websutil.install_i18n(websutil.sanityCheckLocale(locale)) websutil.sanityCheckAssignmentId(assignmentId) websutil.sanityCheckCourseId(courseId) if username != None: websutil.sanityCheckUsername(username) req.content_type = 'text/html' strout = websutil.OutputString() # Check permission s = Session.Session(req) if s.is_new(): s.invalidate() return json.dumps({ 'errorType': websutil.ERR_AUTH, 'errorMessage': "", 'errorTrace': "" }) try: s.load() current_user = s['username'] except: traceback.print_exc(file=strout) return json.dumps({ 'errorType': websutil.ERR_EXCEPTION, 'errorMessage': "", 'errorTrace': strout.get() }) # Reset the timeout s.save() return websutil.getResultsHelper(courseId, assignmentId, current_user, strout, username=username)
def getUserResults(req, courseId, assignmentId, username): """Get the results for a given username""" websutil.sanityCheckAssignmentId(assignmentId) websutil.sanityCheckCourseId(courseId) websutil.sanityCheckUsername(username) req.content_type = 'text/html' # Check permission s = Session.Session(req) if s.is_new(): s.invalidate() return json.dumps({ 'errorType': websutil.ERR_AUTH, 'errorMessage': "", 'errorTrace': "" }) # Reset the timeout s.save() return websutil.getUserResultsHelper(req, courseId, assignmentId, username)
def getUserResults(req, courseId, assignmentId, username=None, locale=websutil.DEFAULT_LOCALE): """Get the individual results for a given username. If the username is empty, get the results of the current user.""" websutil.install_i18n(websutil.sanityCheckLocale(locale)) websutil.sanityCheckAssignmentId(assignmentId) websutil.sanityCheckCourseId(courseId) if username != None: websutil.sanityCheckUsername(username) req.content_type = 'text/html' strout = websutil.OutputString() # Check permission s = Session.Session(req) if s.is_new(): s.invalidate() return json.dumps({'errorType':websutil.ERR_AUTH, 'errorMessage':"", 'errorTrace':""}) try: s.load() current_user = s['username'] except: traceback.print_exc(file = strout) return json.dumps({'errorType' : websutil.ERR_EXCEPTION, 'errorMessage' : "", 'errorTrace' : strout.get()}) # Reset the timeout s.save() return websutil.getResultsHelper(courseId, assignmentId, current_user, strout, username = username)
def login(req, username, password, remember_me=False, locale=websutil.DEFAULT_LOCALE): websutil.install_i18n(websutil.sanityCheckLocale(locale)) #### BIG FAT WARNING: #### # If you ever try to use Vmchecker on a UserDir-type environment # (i.e., ~/public_html), **DON'T**. # It appears that mod_python tries to set a cookie with the path # determined by DocumentRoot. This means that the path itself # gets mangled and the browser doesn't send the cookie back. # # This results in the app never logging in, simply coming back # to the login screen. # # If you have access to the browser config, you can try and # manually set 'ApplicationPath' to '/' in order to circumvent # this. #### / BIG FAT WARNING #### req.content_type = 'text/html' # don't permit brute force password guessing: time.sleep(1) s = Session.Session(req) websutil.sanityCheckUsername(username) strout = websutil.OutputString() if not s.is_new(): try: s.load() username = s['username'] fullname = s['fullname'] except: traceback.print_exc(file=strout) return json.dumps({ 'errorType': websutil.ERR_EXCEPTION, 'errorMessage': "Getting user info from existing session failed", 'errorTrace': strout.get() }) return json.dumps({ 'status': True, 'username': username, 'fullname': fullname, 'info': 'Already logged in' }) try: user = websutil.get_user(username, password) except: traceback.print_exc(file=strout) return json.dumps({ 'errorType': websutil.ERR_EXCEPTION, 'errorMessage': "", 'errorTrace': strout.get() }) if user is None: s.invalidate() return json.dumps({ 'status': False, 'username': "", 'fullname': "", 'info': _('Invalid username/password') }) # Use extended session timeout if requested if remember_me != False: c = s.make_cookie() expiration = datetime.datetime.now() expiration += datetime.timedelta( seconds=websutil.EXTENDED_SESSION_TIMEOUT) c.expires = expiration.strftime("%a, %d-%b-%Y %H:%M:%S GMT") req.headers_out.clear() Cookie.add_cookie(req, c) s.set_timeout(websutil.EXTENDED_SESSION_TIMEOUT) username = username.lower() s["username"] = username s["fullname"] = user s.save() return json.dumps({ 'status': True, 'username': username, 'fullname': user, 'info': 'Succesfully logged in' })
def login(req, username, password, remember_me=False, locale=websutil.DEFAULT_LOCALE): websutil.install_i18n(websutil.sanityCheckLocale(locale)) #### BIG FAT WARNING: #### # If you ever try to use Vmchecker on a UserDir-type environment # (i.e., ~/public_html), **DON'T**. # It appears that mod_python tries to set a cookie with the path # determined by DocumentRoot. This means that the path itself # gets mangled and the browser doesn't send the cookie back. # # This results in the app never logging in, simply coming back # to the login screen. # # If you have access to the browser config, you can try and # manually set 'ApplicationPath' to '/' in order to circumvent # this. #### / BIG FAT WARNING #### req.content_type = 'text/html' # don't permit brute force password guessing: time.sleep(1) s = Session.Session(req) websutil.sanityCheckUsername(username) strout = websutil.OutputString() if not s.is_new(): try: s.load() username = s['username'] fullname = s['fullname'] except: traceback.print_exc(file = strout) return json.dumps({'errorType' : websutil.ERR_EXCEPTION, 'errorMessage' : "Getting user info from existing session failed", 'errorTrace' : strout.get()}) return json.dumps({'status' : True, 'username' : username, 'fullname' : fullname, 'info' : 'Already logged in'}) try: user = websutil.get_user(username, password) except: traceback.print_exc(file = strout) return json.dumps({'errorType' : websutil.ERR_EXCEPTION, 'errorMessage' : "", 'errorTrace' : strout.get()}) if user is None: s.invalidate() return json.dumps({'status' : False, 'username' : "", 'fullname' : "", 'info':_('Invalid username/password')}) # Use extended session timeout if requested if remember_me != False: c = s.make_cookie() expiration = datetime.datetime.now() expiration += datetime.timedelta(seconds = websutil.EXTENDED_SESSION_TIMEOUT) c.expires = expiration.strftime("%a, %d-%b-%Y %H:%M:%S GMT") req.headers_out.clear() Cookie.add_cookie(req, c) s.set_timeout(websutil.EXTENDED_SESSION_TIMEOUT) username = username.lower() s["username"] = username s["fullname"] = user s.save() return json.dumps({'status' : True, 'username' : username, 'fullname' : user, 'info' : 'Succesfully logged in'})