def get(self):
        group = Group.get_by_id(int(self.request.get('group_id')))
        user = None
        if self.request.cookies.get('our_token'):    #the cookie that should contain the access token!
            user = User.checkToken(self.request.cookies.get('our_token'))

        if not user or group.admin != user.key:
            self.error(403)
            self.response.write('access denied')
            return

        new_user_email = self.request.get('member_email')
        logging.info("Email {}".format(new_user_email))
        new_user = User.query(User.email == new_user_email).get()

        if not new_user:
            self.error(404)
            self.response.write('User with email {} not found'.format(new_user_email))
            return

        group.members.append(new_user.key)
        group.put()
        members = group.getMembers()

        time.sleep(0.5)
        self.response.write(json.dumps({"status": "OK", "members": members}))
	def get(self, group_id):
		template_params={}
		user = None
		if self.request.cookies.get('our_token'):    #the cookie that should contain the access token!
			user = User.checkToken(self.request.cookies.get('our_token'))
		if not user:
			html = template.render("web/templates/index.html", {})
			self.response.write(html)
			return
		#newlinks
		linkslist=Link.getAllLinksPerUser(user)	
		newurls = []
		template_params = {}
		if linkslist:
			for link in linkslist:
				url = link.url_link
				des = link.description
				fromlink=link.from_link
				if fromlink is not None:
					urlandlink =[url,des,fromlink]
					newurls.append(urlandlink)
			template_params['newurls'] = newurls
		#newlinks
		template_params['useremail'] = user.email
		grouplist= Group.getAllGroups(user)
		groups= []
		if grouplist:
			for group in grouplist:
				group_name= group['group_name']
				groupid=group['id']
				one=[group_name,groupid]
				groups.append(one)
			template_params['groupss']= groups
		
		group = Group.get_by_id(int(group_id))
		if group is None:
			return
		if group.admin != user.key and user.key not in group.members:
			template_params['no_access'] = True
			html = template.render('web/templates/mygroups.html', template_params)
			self.response.write(html)
			return
		else:
			template_params['group_name'] = group.group_name
			template_params['group_id'] = group_id
			linksInGroup=group.getLinks()
			links= []
			for link in linksInGroup:
				link_user_name= link['email']
				link_description= link['description']
				link_url_link= link['url_link']
				link_date= link['time_of_enter_the_link']
				one=[link_user_name,link_description,link_url_link,link_date]
				links.append(one)
				links.reverse()
			template_params['links']= links			
			
		html = template.render('web/templates/mygroupschat.html', template_params)
		self.response.write(html)
Exemple #3
0
	def get(self):
		user = None
		if self.request.cookies.get('our_token'):    #the cookie that should contain the access token!
			user = User.checkToken(self.request.cookies.get('our_token'))
		if not user:
			self.error(403)
			self.response.write('No user')
			self.response.write(html)
			return
		member = User.checkIfUesr(self.request.get('emailMember'))
		group_to_remove_member= Group.get_by_id(int(self.request.get('groupid')))
		if group_to_remove_member is None:
			return
		if group_to_remove_member.admin == member.key:
			return
		else:
			group_to_remove_member.removeUserFromTheGroup(member)			
		self.response.set_cookie('our_token', str(user.key.id()))
		self.response.write(json.dumps({'status':'OK'}))
		
		return
	def get(self):
		user = None
		if self.request.cookies.get('our_token'):    #the cookie that should contain the access token!
			user = User.checkToken(self.request.cookies.get('our_token'))
		if not user:
			self.error(403)
			self.response.write('No user')
			self.response.write(html)
			return
		group_to_remove= Group.get_by_id(int(self.request.get('groupid')))
		if group_to_remove is None:
			return
		if group_to_remove.admin == user.key:
			group_to_remove.remove_group()
		else:
			group_to_remove.removeUserFromTheGroup(user)			
		time.sleep(0.5)
		self.response.set_cookie('our_token', str(user.key.id()))
		self.response.write(json.dumps({'status':'OK'}))
		
		return
Exemple #5
0
def join_group(message, user, group):
    """ Join group by code """
    match = regex_match(r'^join (?P<group_uid>.+)', message.text.lower())
    if not match:
        logging.info("No group code provided")
        return Result(response_type=INFO, messages=[JOIN_GROUP_INSTRUCTIONS], user=user, group=group)
    group_uid = match.groupdict().get('group_uid')
    if user.group_uid == group_uid:
        logging.info("Already in group for group_uid: %s", group_uid)
        return Result(response_type=INFO, messages=[ALREADY_IN_GROUP], user=user, group=group)
    if not group_uid:
        logging.info("Need to specify a group_uid")
        return Result(response_type=INFO, messages=[NO_GROUP_FOUND], user=user, group=None)
    group = Group.get_by_id(group_uid)
    if not group:
        logging.info("Couldn't find group for group_uid: %s", group_uid)
        return Result(response_type=INFO, messages=[NO_GROUP_FOUND], user=user, group=None)
    group.user_keys.append(user.key)
    user.group_uid = group.uid
    clue = group.clue
    return Result(response_type=JOINED, messages=[JOINED_GROUP, clue], user=user, group=group)
Exemple #6
0
 def get(self):
     template_params = {}
     members = json.loads(self.request.get('members'))
     user = None
     if self.request.cookies.get(
             'our_token'
     ):  #the cookie that should contain the access token!
         user = User.checkToken(self.request.cookies.get('our_token'))
     if not user:
         self.error(403)
         self.response.write('No user')
         self.response.write(html)
         return
     group = Group.get_by_id(int(self.request.get('group_id')))
     for newM in members:
         usermem = User.checkIfUesr(newM)
         if not group.checkIfinTheMember(usermem):
             group.members.append(usermem.key)
     group.put()
     self.response.set_cookie('our_token', str(user.key.id()))
     self.response.write(json.dumps({'status': 'OK'}))
     return
Exemple #7
0
 def get(self):
     des = self.request.get('des')
     url_link = self.request.get('url_link')
     user = None
     if self.request.cookies.get(
             'our_token'
     ):  #the cookie that should contain the access token!
         user = User.checkToken(self.request.cookies.get('our_token'))
     if not user:
         self.error(403)
         self.response.write('No user')
         self.response.write(html)
         return
     group = Group.get_by_id(int(self.request.get('groupid')))
     link = Link()
     link.description = des
     link.url_link = url_link
     link.user = user.key
     link.ifInTheGroup = True
     link.put()
     group.links.append(link.key)
     group.put()
     self.response.write(json.dumps({"status": "OK"}))
Exemple #8
0
    def get(self):
        user = None
        if self.request.cookies.get(
                'our_token'
        ):  #the cookie that should contain the access token!
            user = User.checkToken(self.request.cookies.get('our_token'))
        if not user:
            self.error(403)
            self.response.write('No user')
            self.response.write(html)
            return
        group_to_remove = Group.get_by_id(int(self.request.get('groupid')))
        if group_to_remove is None:
            return
        if group_to_remove.admin == user.key:
            group_to_remove.remove_group()
        else:
            group_to_remove.removeUserFromTheGroup(user)
        time.sleep(0.5)
        self.response.set_cookie('our_token', str(user.key.id()))
        self.response.write(json.dumps({'status': 'OK'}))

        return
Exemple #9
0
	def get(self, group_id):
		template_params={}
		user = None
		if self.request.cookies.get('our_token'):    #the cookie that should contain the access token!
			user = User.checkToken(self.request.cookies.get('our_token'))
		if not user:
			html = template.render("web/templates/index.html", {})
			self.response.write(html)
			return
		#newlinks
		linkslist=Link.getAllLinksPerUser(user)	
		newurls = []
		template_params = {}
		if linkslist:
			for link in linkslist:
				url = link.url_link
				des = link.description
				fromlink=link.from_link
				if fromlink is not None:
					urlandlink =[url,des,fromlink]
					newurls.append(urlandlink)
			template_params['newurls'] = newurls
		
		template_params['useremail'] = user.email
		grouplist= Group.getAllGroups(user)
		groups= []
		if grouplist:
			for group in grouplist:
				group_name= group['group_name']
				groupid=group['id']
				one=[group_name,groupid]
				groups.append(one)
			template_params['groupss']= groups
		
		group = Group.get_by_id(int(group_id))
		if group is None:
			return
		if group.admin != user.key and user.key not in group.members:
			template_params['no_access'] = True
			html = template.render('web/templates/mygroups.html', template_params)
			self.response.write(html)
			return
		else:
			template_params['admin_access'] =False
			if group.admin == user.key:
				template_params['admin_access'] =True		
			template_params['group_name'] = group.group_name
			template_params['group_id'] = group_id
			linksInGroup=group.getLinks()
			links= []
			for link in linksInGroup:
				link_user_name= link['email']
				link_description= link['description']
				link_url_link= link['url_link']
				link_date= link['time_of_enter_the_link']
				one=[link_user_name,link_description,link_url_link,link_date]
				links.append(one)
			sorted(links, key=lambda links: one[3])  
			links.reverse()
			template_params['links']= links			
			all_Member_In_The_Group=group.getMembers()
			all_Member_In_The_Group.insert(0,group.getAdminOfTheGroup())
			template_params['members']=all_Member_In_The_Group 			
			
		html = template.render('web/templates/mygroupschat.html', template_params)
		self.response.write(html)