def channel_invite(token, channel_id, u_id): '''Adds existing user to a new channel''' channel_id = int(channel_id) u_id = int(u_id) # Raise error if invalid token if not Token.isValid(token): raise AccessError('Invalid Token.') database = db.load_DB() # Check if valid channel_id if channel_id not in db.get_all_channels(database): raise ValueError('Invalid Channel ID.') # Check if authorised user is a member of the channel channel = db.get_channel_by_id(database, channel_id) if not db.get_from_token('u_id', token, database) in channel['members']: raise AccessError('You are not a member of this channel so \ you cannot invite others to join.') # Check if valid user ID for user to be adde if u_id not in db.get_all_users(database): raise AccessError('Invalid user id.') if u_id in channel['members']: raise AccessError('User already part of the channel') database['channels'].remove(channel) channel['members'].append(u_id) database['channels'].append(channel) db.save_DB(database) return dumps({})
def index(): users = db.get_all_users() users = list(map(list, users)) for user in users: uid = user[0] user.append(db.get_record(uid)) return render_template('index.html', users=users)
def retrieve(event, context): try: origin = event["origin"] destination = event["destination"] type = event["type"] message = None if 'message' in event: message = event["message"] users = db.get_all_users() users_list = [] for user in users: u_origin = user['origin'] u_destination = user['destination'] if neo4j_db.is_contained(u_origin, u_destination, origin, destination): users_list.append(user['userId']) except Exception as e: print(e) return { "statusCode": 200, "origin": origin, "destination": destination, "type": type, "message": message, "users": users_list }
def authenticate(email, password): """Check whether the arguments match a user from the "database" of valid users.""" valid_users = db.get_all_users() for user in valid_users: if email == user['email'] and bcrypt.check_password_hash(user['password'], password): return email return None
def admin_users(): """ An app route for the handling of the user that is to be promoted or removed. :return: :rtype: Returns the rendered template and the list of users and if an action has been done, a message will also be sent. """ user_name = db.get_all_users() if request.method == 'POST': for x in user_name: if str(x[0]) in request.form: message = handle_users(x[1], "promote") return render_template("admin_users.html", all_users=user_name, message=message) elif str(x[1]) in request.form: message = handle_users(x[1], "remove") user_names = db.get_all_users() return render_template("admin_users.html", all_users=user_names, message=message) return render_template("admin_users.html", all_users=user_name)
def users(): tcontent = [] for i in db.get_all_users(): tcontent.append(i) vars = dict(title="All The Users!", theaders = ["User Id","First Name","Last Name", "User Name", "Password"], tcontent = tcontent) return JinjaLoader('bottle_type_pages.html', vars)
def notification_controller(): # Get all users users = get_all_users() for x in range(len(users)): # Get all saving bank data saving_data = savings_notifier(users[x], account_types) # Send finance data by email to specific user news_email(users[x], saving_data)
def index(): users = db.get_all_users() login_form = loginForm() print(users) if login_form.validate_on_submit(): return "Congrats, you've logged in!" return render_template("index.html", form=login_form, users=users)
def cron_start(xmpp): sched = apscheduler.scheduler.Scheduler() for user in db.get_all_users(): if user['access_key'] and user['access_secret'] and (user['timeline'] & ~db.MODE_EVENT): queue = xmpp.worker_threads[user['jid']].job_queue sched.add_interval_job(functools.partial(cron_timeline, user=user, queue=queue), seconds=CRON_INTERVAL) sched.add_interval_job(functools.partial(cron_block, user=user, xmpp=xmpp), seconds=CRON_BLOCKED_IDS_INTERVAL) sched.add_interval_job(functools.partial(cron_list, user=user, xmpp=xmpp), seconds=CRON_LIST_IDS_INTERVAL) sched.start() return sched
def list_users(): user_id = get_jwt_identity() users_raw = get_all_users() # returns a list of user objects users = [] for user_object in users_raw: if user_object.ID == user_id: users.insert(0, user_object.create_json()) else: users.append(user_object.create_json()) return jsonify(users), 200
def db_control_page(): retVal = {'error': 'none'} if g.user is None: retVal['error'] = "not logged in" return json.dumps(retVal) if not g.user.is_admin: retVal['error'] = "logged in user must be admin" return json.dumps(retVal) user = db.get_all_users() return render_template('db_control.html')
def get(self): adminId = self.get_secure_cookie('admin') forum = db.get_forum() allUsers = db.get_all_users() allPosts = db.get_all_posts() allReplys = db.get_all_replys() wealthList = db.get_wealth_list() cUser = db.get_admin(adminId) self.render( 't_admin.html', title='Ran - Admin', allUsers=allUsers, forum=forum, allReplys=allReplys, allPosts=allPosts, wealthList=wealthList, cUser=cUser, )
def admin_map(): start_time = time.time() visits = db.get_all_visits_anonymous_geojson() end_time = time.time() print("elapsed time (1): %s" % (end_time - start_time)) start_time = time.time() users = dict((u['user_id'], u) for u in db.get_all_users()) end_time = time.time() print("elapsed time (2): %s" % (end_time - start_time)) return render_template('admin/map.html', page='map', visits=visits, users=users)
def admin_dashboard(): start_time = time.time() users = db.get_all_users() end_time = time.time() print("elapsed time (1): %s" % (end_time - start_time)) start_time = time.time() stats = db.get_basic_stats(users) end_time = time.time() print("elapsed time (2): %s" % (end_time - start_time)) return render_template('admin/dashboard.html', page='dashboard', users=users, stats=stats)
def GET(seq): if not seq: print( "Usage: get [active | finished | sessions | users | types | time [...]]" ) elif seq[0] == "active": print(db.get_active_sessions(user)) elif seq[0] == "finished" or seq[0] == "sessions": print(db.get_finished_sessions(user)) elif seq[0] == "users": print(db.get_all_users()) elif seq[0] == "types": print(db.get_session_name(user)) elif seq[0] == "time": TIME(seq[1:])
def sign(): data_users = get_all_users() data = get_all_experience() logged_in = False if 'signin_username' in request.form: signin_username = request.form.get('signin_username') signin_password = request.form.get('signin_password') for user in data_users: if user['username'] == signin_username and user[ 'password'] == signin_password: session['username'] = signin_username return render_template('index.html', signin_username=signin_username, logged_in=True, data=data, gallery=get_all_images(), user=session['username']) return render_template('index.html', signin_username=signin_username, logged_in=False, data=data, gallery=get_all_images(), user=session['username']) else: signup_username = request.form.get('signup_username') signup_password = request.form.get('signup_password') message = "Signup completed" for user in data_users: if signup_username == user['username']: message = "Username already exists" return render_template('sign_up_noti.html', message=message, logged_in=logged_in, gallery=get_all_images()) if len(signup_username) < 6 or len(signup_username) > 15 or len( signup_password) < 6 or len(signup_password) > 15: message = "Username or password not available" return render_template('sign_up_noti.html', message=message, logged_in=logged_in, gallery=get_all_images()) insert_users(signup_username, signup_password) return render_template('sign_up_noti.html', message=message, logged_in=logged_in, gallery=get_all_images())
def send_picture_to_all(): logger.info("Sending today's picture to all users") json_resp = get_photo().json() users = db.get_all_users("sent = false") if users: for user in users: try: send_action(user['id'], json_resp) message_string = f"Hi! This is the image of today. Enjoy it!\n" \ f"**{json_resp['title']}**\n\n" \ f"{json_resp['explanation']}" if 'copyright' in json_resp: message_string += f"\n\n__© {json_resp['copyright']}__" bot.send_message(user['id'], message_string) except BadRequest: logger.error(f'Bad request sending picture to user @{user["username"]} ' f'({user["id"]}). Deleting the user.') db.delete_user(user['id']) db.change_sent(True)
def review_get(application): logging.info('Visited review') user = db.get_user(current_user.id) if user['role'] != 'admin': return 'You should be an admin' names, ids = db.get_all_users() ids.insert(0, 'all users') if request.method == 'POST': session['user_to_review'] = request.form['select_user'] files = [] if session.get('user_to_review') is not None: cur_user = session['user_to_review'] if not cur_user == 'all users': files_ = db.get_files(application, config[application]['output'], cur_user) else: files_ = db.get_files(application, config[application]['output'], ext='.json') for i in range(len(files_)): files.append(files_[i]['filename']) else: cur_user = '******' return render_template('review_choose_user.html', users=ids, application=application, cur_user=cur_user, files=files, output=config[application]['output'], log_in_or_out='out')
def identity(payload): userid_table = {u.id: u for u in get_all_users()} user_id = payload['identity'] return userid_table.get(user_id, None)
def userlist(): return my_render_template('userlist.html', userlist=db.get_all_users())
def admin_home(): users = db.get_all_users() stats = db.get_basic_stats(users) return render_template('admin/admin.html', users=users, stats=stats)
def userlist(): return my_render_template("userlist.html", userlist=db.get_all_users())
def index(): return render_template('index.html', users=get_all_users())
def sign(): data_users = get_all_users() data = get_all_experience() logged_in = False if 'signin_username' in request.form: signin_username = request.form.get('signin_username') signin_password = request.form.get('signin_password') for user in data_users: if user['username'] == signin_username and user[ 'password'] == signin_password: session['username'] = signin_username return render_template('index.html', signin_username=signin_username, logged_in=True, data=data, gallery=get_all_images(), user=session['username']) return render_template('index.html', signin_username=signin_username, logged_in=False, data=data, gallery=get_all_images(), user=session['username']) elif 'signup_username' in request.form: signup_username = request.form.get('signup_username') signup_password = request.form.get('signup_password') message = "Signup completed" for user in data_users: if signup_username == user['username']: message = "Username already exists" return render_template('sign_up_noti.html', message=message, logged_in=logged_in, gallery=get_all_images()) if len(signup_username) < 6 or len(signup_username) > 15 or len( signup_password) < 6 or len(signup_password) > 15: message = "Username or password not available" return render_template('sign_up_noti.html', message=message, logged_in=logged_in, gallery=get_all_images()) insert_users(signup_username, signup_password) return render_template('sign_up_noti.html', message=message, logged_in=logged_in, gallery=get_all_images()) else: gmail_user = '******' gmail_password = '******' sent_from = gmail_user to = request.form.get('email_to_send') subject = 'Thank you for subscribing' body = 'Thank you for subscribing viet-traveling' email_text = """\ From: %s To: %s Subject: %s %s """ % (sent_from, to, subject, body) try: server = smtplib.SMTP_SSL('smtp.gmail.com', 465) server.ehlo() server.login(gmail_user, gmail_password) server.sendmail(sent_from, to, email_text) server.close() return render_template('sub_noti.html', message="Thanks for subscribing") except: return render_template('sub_noti.html', message="Opps!! Some things went wrong!")
def get_users(): users_raw = get_all_users() users = list(map(lambda u: u.create_json(), users_raw)) return users
def rpc_get_users(self): results = [] for i in db.get_all_users(): results.append(i) return results
def start_streams(self): for user in db.get_all_users(): if user['access_key'] and user['access_secret']: self.start_stream(user['jid'])
def authenticate(username, password): username_table = {u.username: u for u in get_all_users()} user = username_table.get(username, None) if user and safe_str_cmp(user.password.encode('utf-8'), password.encode('utf-8')): return user
def members_list(): message = '' list_of_users = get_all_users() return render_template('members.html', users=list_of_users)
def admin(): user = db.get_all_users() return render_template('admin.html', users=user)
def create_all_reports(): orders = db.get_all_orders_from_basket() create_report('orders', orders) users = db.get_all_users() create_report('users', users)
def get_group_members(group_id): return db.get_all_users(group_id)