def archives(): page = helpers.to_int(flask.request.args.get('page'), default=1) year = helpers.to_int(flask.request.args.get('year')) month = helpers.to_int(flask.request.args.get('month')) group_slug = flask.request.args.get('group') category_slug = flask.request.args.get('category') if month and month > 12: month = None friendly_date = None group = None after = None before = None if year: if month: after = datetime(year=year, month=month, day=1) before = after + relativedelta(months=1) friendly_date = after.strftime('%B %Y') if not month: after = datetime(year=year, month=1, day=1) before = after + relativedelta(years=1) friendly_date = after.strftime('%Y') if group_slug: groups = api.get_groups(slugs=[group_slug]) if groups: group = groups[0] if category_slug: categories = api.get_categories(slugs=[category_slug]) category_ids = [category['id'] for category in categories] else: categories = [] category_ids = [] posts, total_posts, total_pages = helpers.get_formatted_posts( page=page, after=after, before=before, group_ids=[group['id']] if group else [], category_ids=category_ids if category_ids else [], ) return flask.render_template( 'archives.html', categories=categories, category_ids=category_ids, category_slug=category_slug if category_slug else None, current_page=page, friendly_date=friendly_date, group=group, now=datetime.now(), posts=posts, total_pages=total_pages, total_posts=total_posts, )
def press_centre(): group = api.get_groups(slugs=['canonical-announcements'])[0] posts, total_posts, total_pages = helpers.get_formatted_expanded_posts( group_ids=[group['id']]) return flask.render_template('press-centre.html', posts=posts, page_slug='press-centre', group=group, current_year=datetime.now().year)
def create_org_structure(ip, port, username, password): access_token, refresh_token = login(ip, port, username, password) org_struct = {} o_res = get_orgs(ip, port, access_token) for org in o_res: org_struct[org] = {} f_res = get_facultys(ip, port, access_token, org) for faculty in f_res: org_struct[org][faculty] = get_groups(ip, port, access_token, org, faculty) return org_struct
async def on_certify(client, config, member, email): config_ranks = config['servers'][member.guild.id]['ranks'] user_groups = api.get_groups(config, email=email) user_groups = user_groups if user_groups else [] ranks = [] for group in user_groups: if group['group'] in config_ranks['classic']: ranks += config_ranks['classic'][group['group']] if not email.split('@')[1] in config['servers'][ member.guild.id]['domains']: ranks = config_ranks['banned'] elif check_ban(member, email, user_groups, config): ranks = config_ranks['banned'] else: ranks += config_ranks['confirmed'] await set_roles(client, config, member, ranks)
def _group_view(group_slug, page_slug, template): """ View function which gets all posts for a given group slug, and returns a response loading those posts with the template provided """ page = int(flask.request.args.get('page') or '1') category_slug = flask.request.args.get('category') groups = api.get_groups(slugs=[group_slug]) category = None if not groups: flask.abort(404) group = groups[0] if category_slug: categories = api.get_categories(slugs=[category_slug]) if categories: category = categories[0] posts, total_posts, total_pages = helpers.get_formatted_expanded_posts( group_ids=[group['id']], category_ids=[category['id']] if category else [], page=page, per_page=12 ) return flask.render_template( template, posts=posts, group=group, category=category if category_slug else None, current_page=page, page_slug=page_slug, total_posts=total_posts, total_pages=total_pages, )
def groups(self): return api.get_groups(self.info.get('session_id'))
def groups(self): return api.get_groups(self.info.get('session_id'), db_name=self.db_name)
def run(self): while not self.kill_received: print("Connection from : ", clientAddress) auth = False valid_user = False valid_password = False # self.csocket.send(bytes("Hi, This is from Server..",'utf-8')) while auth is False: while valid_user is False: msg = 'Please enter an alphanumeric username' self.client_ssl.send(bytes(msg.encode('UTF-8'))) data = self.client_ssl.recv(2048) username = data.decode() if username.isalnum() is True: valid_user = True print("User entered username: "******"Enter your password" vs. "error: wrong password" while correct_password is False: if first_run: msg = 'User ' + username + ', please enter your password' self.client_ssl.send(bytes(msg.encode('UTF-8'))) first_run = False # receive password attempt from user password = self.client_ssl.recv(2048).decode() # if hashed attempt matches retrieved hash, authenticate hash_obj = hashlib.sha256() hash_obj.update(oursalt + password) attempted_hash_str = hash_obj.hexdigest() print "attempted hash str: " + attempted_hash_str + "\n" print "actual hash str: " + hashed_pass_str + "\n" if attempted_hash_str == hashed_pass_str: correct_password = True # otherwise, tell the user else: msg = 'Error: Incorrect password. Try again' print "Client entered incorrect password.\n" self.client_ssl.send(bytes(msg.encode('UTF-8'))) #break if correct_password is True: auth = True print("User ", username, " entered password ", password) msg = 'Welcome, ' + username + '! List of groups: ' + ' '.join( api.get_groups()) self.client_ssl.send(bytes(msg.encode('UTF-8'))) while True: data = self.client_ssl.recv(2048) msg = data.decode() if msg == 'END': self.client_ssl.send( bytes("Connection closed".encode('UTF-8'))) break if msg.split()[0] not in ['GET', 'POST' ] or len(msg.split()) <= 1: self.client_ssl.send( bytes("Invalid operation.".encode('UTF-8'))) msg = msg.split(' ', 2) print msg if len(msg) > 1: if msg[0] == "GET": messages = api.get_messages(msg[1]) #self.client_ssl.send("these are the messages in the group".join(messages).encode('UTF-8')) if len(messages) > 0: messages_string = ''.join(messages) self.client_ssl.send( bytes(messages_string.encode('UTF-8'))) print "these are the messages in the group", messages else: self.client_ssl.send( bytes( "No messages found for that group".encode( 'UTF-8'))) elif msg[0] == "POST": if len(msg) > 2: api.put_messages(msg[1], username, msg[2]) self.client_ssl.send( bytes(("POST received for message: " + "\"" + msg[2] + "\"").encode('UTF-8'))) else: self.client_ssl.send( bytes("Please enter a message to POST".encode( 'UTF-8'))) else: self.client_ssl.send( bytes("Invalid operation.".encode('UTF-8'))) #self.client_ssl.send(bytes("".join(msg).encode('UTF-8'))) self.kill_received = True print("Client at ", clientAddress, " disconnected...")
async def unban_group(data): users = api.get_groups(config, group=data['value']) for user in users: await unban_email(user)