<commit_before>import cgi
from google.appengine.ext import webapp
from model import *
from google.appengine.api import users
import registration as registration
import os
from google.appengine.ext.webapp import template
from hashlib import *

class GroupInvitationHandler(webapp.RequestHandler):
		
	def get(self):
		user = users.get_current_user()
		if not user:
			self.redirect(users.create_login_url(self.request.uri))
			return		
		group = Group.get(self.request.get("group"))
		userEmail = self.request.get("user")
		invitation = GroupInvitation(group, userEmail)
		if invitation.makeHash() != self.request.get("hash"):
			self.response.out.write("Invitation is invalid") # TODO HTTP ERROR
			return		
		if user.email() != userEmail:
			self.response.out.write("This invitation is not for you.") # TODO HTTP ERROR
			return
		
		exists = Membership.gql("WHERE user = :1 AND group = :2", user, group).count() > 0
		if exists:
			self.response.out.write("You are already a member of %s group" % group.name)
		else:
			Membership(user=user,group=group,balance=0.0).put()
			self.response.out.write("You have been added to %s group" % group.name)
	
class GroupInvitation:
	
	def __init__(self, group, userEmail):
		self.group = group
		self.userEmail = userEmail
	
	def getUrl(self):
		# TODO UNHACK HOST
		return "http://localhost:8080/groupInvitation?group=%s&user=%s&hash=%s" % (str(self.group.key()) , self.userEmail , self.makeHash())
	
	def makeHash(self):
		m = sha224()
		m.update(str(self.group.key()))
		m.update(self.userEmail)
		return m.hexdigest()
	<commit_msg>go to group link adfter invitation accepted.<commit_after>import cgi
from google.appengine.ext import webapp
from model import *
from google.appengine.api import users
import registration as registration
import os
from google.appengine.ext.webapp import template
from hashlib import *

class GroupInvitationHandler(webapp.RequestHandler):
		
	def get(self):
		user = users.get_current_user()
		if not user:
			self.redirect(users.create_login_url(self.request.uri))
			return		
		group = Group.get(self.request.get("group"))
		userEmail = self.request.get("user")
		invitation = GroupInvitation(group, userEmail)
		if invitation.makeHash() != self.request.get("hash"):
			self.response.out.write("Invitation is invalid") # TODO HTTP ERROR
			return		
		if user.email() != userEmail:
			self.response.out.write("This invitation is not for you.") # TODO HTTP ERROR
			return
		
		exists = Membership.gql("WHERE user = :1 AND group = :2", user, group).count() > 0
		if exists:
			self.response.out.write("You are already a member of %s group" % group.name)
		else:
			Membership(user=user,group=group,balance=0.0).put()
			self.response.out.write("You have been added to <a href='/group?group=%s'>%s</a> group" % (group.key(), group.name))
	
class GroupInvitation:
	
	def __init__(self, group, userEmail):
		self.group = group
		self.userEmail = userEmail
	
	def getUrl(self):
		# TODO UNHACK HOST
		return "http://localhost:8080/groupInvitation?group=%s&user=%s&hash=%s" % (str(self.group.key()) , self.userEmail , self.makeHash())
	
	def makeHash(self):
		m = sha224()
		m.update(str(self.group.key()))
		m.update(self.userEmail)
		return m.hexdigest()
	
{'fraction_non_alphanumeric': 0.1321981424148607, 'fraction_numerical': 0.007430340557275541, 'mean_word_length': 4.4120603015075375, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2327779', 'n_tokens_mistral': 1151, 'n_tokens_neox': 1035, 'n_words': 260}