Esempio n. 1
0
def UserAddAchievement(UserID, AchievementID):

    # Does the current user have this achivement?
    UserAchievements = Achievements.AchievementsQueryUserID(UserID)
    for achievement in UserAchievements:
        if achievement.AchievementID == AchievementID:
            return

            # New achievement for this user!
    NewAchievement = UserAchievementsTable()
    NewAchievement.UserID = UserID
    NewAchievement.AchievementID = AchievementID

    # Commit to DB
    Session.add(NewAchievement)
    Session.commit()

    # Recompute the latest user points and force it onto this user
    UpdateUserPoints(UserID)
Esempio n. 2
0
def UserAddAchievement(UserID, AchievementID):
	
	# Does the current user have this achivement?
	UserAchievements = Achievements.AchievementsQueryUserID(UserID)
	for achievement in UserAchievements:
		if achievement.AchievementID == AchievementID:
			return
	
	# New achievement for this user!
	NewAchievement = UserAchievementsTable()
	NewAchievement.UserID = UserID
	NewAchievement.AchievementID = AchievementID
	
	# Commit to DB
	Session.add(NewAchievement)
	Session.commit()
	
	# Recompute the latest user points and force it onto this user
	UpdateUserPoints(UserID)
Esempio n. 3
0
def UserRegister(UserName, UserEMail, UserPassword, UserPasswordConfirm):

    # Check for cookies - are we already logged in?
    if session.get("UserName"):
        return "redirect"

        # Did we get the entire form correctly?
    if not UserName or not UserEMail or not UserPassword or not UserPasswordConfirm:
        return "Error: Missing fields. Please fill out all fields completely."

        # Check username lengths
    if len(UserName) <= 5:
        return "Error: User name is not long enough. Must be at least 6 characters long."
    if len(UserName) > 32:
        return "Error: User name is too long. May be at most 32 characters long."

        # Check email lengths
    if len(UserEMail) <= 5:
        return "Error: User e-mail is not long enough. Must be at least 6 characters long."
    if len(UserEMail) > 32:
        return "Error: User e-mail is too long. May be at most 32 characters long."

        # Check password lengths
    if len(UserPassword) <= 5:
        return "Error: User password is not long enough. Must be at least 6 characters long."
    if len(UserPassword) > 32:
        return "Error: User password is too long. May be at most 32 characters long."

        # Validate against whitelist to make sure these are valid characters
    if h.string_check_whitelist(UserName, h.string_whitelist) == False:
        return "Error: User name contains invalid characters."
    if h.string_check_whitelist(UserEMail, h.string_whitelist) == False:
        return "Error: User e-mail contains invalid characters."
    if h.string_check_whitelist(UserPassword, h.string_whitelist_password) == False:
        return "Error: Password contains invalid characters."

        # Confirm the passwords are the same...
    if UserPassword != UserPasswordConfirm:
        return "Error: Passwords do not match."

        # Finally, make sure no other users with the same name exist..
    ExistingUsers = Session.query(UsersTable).filter(UsersTable.UserName == UserName).all()
    if len(ExistingUsers) > 0:
        return "Error: User name already exists! Please select a new user name."

        # Register this new user into the database
    NewUser = UsersTable()

    # Note that the user ID will auto-increment
    NewUser.UserName = UserName
    NewUser.UserEMail = UserEMail
    NewUser.UserPoints = 0
    NewUser.UserPassword = __GeneratePasswordHash(UserPassword)
    NewUser.LogInCount = 0
    NewUser.LastLogin = datetime.datetime.now()
    NewUser.IsAdmin = False
    NewUser.IconID = 0

    # Commit to DB
    Session.add(NewUser)
    Session.commit()

    # Special achivement earned by people who register now - alpha testers
    UserAddAchievement(NewUser.UserID, 0)

    # All done
    return ""
Esempio n. 4
0
def SolveChallenge(UserID, ChallengeID, ChallengeSourceCode, ChallengeLanguage):
	
	# Create a new solutions
	Solution = UserSolutionsTable()
	Solution.UserID = UserID
	Solution.ChallengeID = ChallengeID
	Solution.ResultCode = 0
	Solution.ResultString = "Internal CoreJudge Failure."
	Solution.SampleResultString = "" # Leave empty
	Solution.MemoryUsage = 0
	Solution.RuntimeUsage = 0
	Solution.SourceCode = ChallengeSourceCode
	Solution.SourceLanguage = ChallengeLanguage
	Solution.SubmitDateTime = datetime.datetime.now()
	
	# Failure flag
	Failed = False
	
	# Load the challenge information
	Challenge = Challenges.ChallengeQueryID(ChallengeID)
	if not Challenge:
		Failed = True
	
	# Is this a supported language?
	# Formally accepted strings: Python, GCC C, C++, Java
	if not Failed:
		if ChallengeLanguage != "Python" and ChallengeLanguage != "GCC C" and ChallengeLanguage != "C++" and ChallengeLanguage != "Java":
			Failed = True
	
	# Check source code for viability to execute...
	if not Failed:
		SourceSafeErr = __IsSourceSafe(ChallengeSourceCode, ChallengeLanguage)
		if len(SourceSafeErr) > 0:
			Failed = True
			Solution.ResultCode = 8
	
	# Attempt to execute the code against both the challenge test cases and the sample inputs
	if not Failed:
		
		# Execute the sample code
		Attempt = __ExecuteSource(Challenge.SampleCode, Challenge.SampleInput, Challenge.SampleOutput, ChallengeSourceCode, ChallengeLanguage, True)
		Solution.ResultString = Attempt.ResultString
		Solution.SampleResultString = Attempt.ResultString
		
		# Execute the official test case
		# Note that we don't post the result string, we just ignore the output
		# since we do the comparison of correct I/O within the exec source function
		Attempt = __ExecuteSource(Challenge.TestCode, Challenge.TestInput, Challenge.TestOutput, ChallengeSourceCode, ChallengeLanguage)
		Solution.MemoryUsage = Attempt.MemoryUsage
		Solution.RuntimeUsage = Attempt.RuntimeUsage
		Solution.ResultCode = Attempt.ResultCode
		Solution.ResultString = Attempt.ResultString
	
	# Commit to DB
	Session.add(Solution)
	Session.commit()
	
	# Force update the user's score if this solution is valid
	if Solution.ResultCode == 1:
		Users.UpdateUserPoints(UserID)
	
	# Return this new result ID (So the browser redirects)
	return Solution.SolutionID
Esempio n. 5
0
def UserRegister(UserName, UserEMail, UserPassword, UserPasswordConfirm):
	
	# Check for cookies - are we already logged in?
	if session.get("UserName"):
		return "redirect"
	
	# Did we get the entire form correctly?
	if not UserName or not UserEMail or not UserPassword or not UserPasswordConfirm:
		return "Error: Missing fields. Please fill out all fields completely."
	
	# Check username lengths
	if len(UserName) <= 5:
		return "Error: User name is not long enough. Must be at least 6 characters long."
	if len(UserName) > 32:
		return "Error: User name is too long. May be at most 32 characters long."
	
	# Check email lengths
	if len(UserEMail) <= 5:
		return "Error: User e-mail is not long enough. Must be at least 6 characters long."
	if len(UserEMail) > 32:
		return "Error: User e-mail is too long. May be at most 32 characters long."
	
	# Check password lengths
	if len(UserPassword) <= 5:
		return "Error: User password is not long enough. Must be at least 6 characters long."
	if len(UserPassword) > 32:
		return "Error: User password is too long. May be at most 32 characters long."
	
	# Validate against whitelist to make sure these are valid characters
	if h.string_check_whitelist(UserName, h.string_whitelist) == False:
		return "Error: User name contains invalid characters."
	if h.string_check_whitelist(UserEMail, h.string_whitelist) == False:
		return "Error: User e-mail contains invalid characters."
	if h.string_check_whitelist(UserPassword, h.string_whitelist_password) == False:
		return "Error: Password contains invalid characters."
	
	# Confirm the passwords are the same...
	if UserPassword != UserPasswordConfirm:
		return "Error: Passwords do not match."
	
	# Finally, make sure no other users with the same name exist..
	ExistingUsers = Session.query(UsersTable).filter(UsersTable.UserName == UserName).all()
	if len(ExistingUsers) > 0:
		return "Error: User name already exists! Please select a new user name."
	
	# Register this new user into the database
	NewUser = UsersTable()
	
	# Note that the user ID will auto-increment
	NewUser.UserName = UserName
	NewUser.UserEMail = UserEMail
	NewUser.UserPoints = 0
	NewUser.UserPassword = __GeneratePasswordHash(UserPassword)
	NewUser.LogInCount = 0
	NewUser.LastLogin = datetime.datetime.now()
	NewUser.IsAdmin = False
	NewUser.IconID = 0
	
	# Commit to DB
	Session.add(NewUser)
	Session.commit()
	
	# Special achivement earned by people who register now - alpha testers
	UserAddAchievement(NewUser.UserID, 0)
	
	# All done
	return ""
Esempio n. 6
0
def SolveChallenge(UserID, ChallengeID, ChallengeSourceCode,
                   ChallengeLanguage):

    # Create a new solutions
    Solution = UserSolutionsTable()
    Solution.UserID = UserID
    Solution.ChallengeID = ChallengeID
    Solution.ResultCode = 0
    Solution.ResultString = "Internal CoreJudge Failure."
    Solution.SampleResultString = ""  # Leave empty
    Solution.MemoryUsage = 0
    Solution.RuntimeUsage = 0
    Solution.SourceCode = ChallengeSourceCode
    Solution.SourceLanguage = ChallengeLanguage
    Solution.SubmitDateTime = datetime.datetime.now()

    # Failure flag
    Failed = False

    # Load the challenge information
    Challenge = Challenges.ChallengeQueryID(ChallengeID)
    if not Challenge:
        Failed = True

    # Is this a supported language?
    # Formally accepted strings: Python, GCC C, C++, Java
    if not Failed:
        if ChallengeLanguage != "Python" and ChallengeLanguage != "GCC C" and ChallengeLanguage != "C++" and ChallengeLanguage != "Java":
            Failed = True

    # Check source code for viability to execute...
    if not Failed:
        SourceSafeErr = __IsSourceSafe(ChallengeSourceCode, ChallengeLanguage)
        if len(SourceSafeErr) > 0:
            Failed = True
            Solution.ResultCode = 8

    # Attempt to execute the code against both the challenge test cases and the sample inputs
    if not Failed:

        # Execute the sample code
        Attempt = __ExecuteSource(Challenge.SampleCode, Challenge.SampleInput,
                                  Challenge.SampleOutput, ChallengeSourceCode,
                                  ChallengeLanguage, True)
        Solution.ResultString = Attempt.ResultString
        Solution.SampleResultString = Attempt.ResultString

        # Execute the official test case
        # Note that we don't post the result string, we just ignore the output
        # since we do the comparison of correct I/O within the exec source function
        Attempt = __ExecuteSource(Challenge.TestCode, Challenge.TestInput,
                                  Challenge.TestOutput, ChallengeSourceCode,
                                  ChallengeLanguage)
        Solution.MemoryUsage = Attempt.MemoryUsage
        Solution.RuntimeUsage = Attempt.RuntimeUsage
        Solution.ResultCode = Attempt.ResultCode
        Solution.ResultString = Attempt.ResultString

    # Commit to DB
    Session.add(Solution)
    Session.commit()

    # Force update the user's score if this solution is valid
    if Solution.ResultCode == 1:
        Users.UpdateUserPoints(UserID)

    # Return this new result ID (So the browser redirects)
    return Solution.SolutionID