def verify_password(username_or_token, password): user = User.verify_auth_token(username_or_token) if not user: user = get_user(username_or_token) if not user or not user.verify_password(password): return False return True
def manage(): user_name = twitter.token["screen_name"] if len(get_user(user_name)) == 0: resp = twitter.get("account/verify_credentials.json", params={'include_email': 'true', "skip_status": 'true', "include_entities": 'false'}) insert_into_users(user_name, resp.json()["name"], resp.json()["email"]) udhaars = get_udhaars(user_name) return render_template("manage.html", udhaars=udhaars)
def get(self, username): '''Generates token for user Attributes: username Username of user ''' user = get_user(username) try: token = user.generate_auth_token(600) except AttributeError: abort(404) return jsonify({'token': token.decode('ascii'), 'duration': 600})
def delete(self, username): '''Deletes a user and all Attributes: username Username of user ''' user = get_user(username) try: session.delete(user) session.commit() except orm_exc.UnmappedInstanceError: return 'Unable to delete user: %s' % username return 204
def get(self, username): '''Gets users attributes Attributes: username Username of user ''' user = get_user(username) projects = user.projects mods_per_project = {} for project in projects: mods_per_project[project.project_name] = [ str(i.model_name) for i in project.models ] return jsonify({'user': username, 'projects': mods_per_project})
async def get_user(user_name: str) -> Dict[str, Any]: user = db_utils.get_user(user_name=user_name) if user: return { "success": True, "message": "user found", "data": UserOut(pk=str(user.id), first_name=user.first_name, last_name=user.last_name, user_name=user.user_name, email=user.email) } return {"success": False, "message": "user does not exist", "data": {}}
def do_sign_in(): # This is meant to be reached from AJAX request. # We return a JSON response that will be used by # The JS code making the request. if (request.form['signin_request_token'] != login_session['signin_request_token']): return response.error('Invalid token.') g_id_token = request.form['id_token'] try: idinfo = id_token.verify_oauth2_token(g_id_token, requests.Request(), CLIENT_ID) if (idinfo['iss'] not in ['accounts.google.com', 'https://accounts.google.com']): raise ValueError('Wrong issuer.') if idinfo['aud'] != CLIENT_ID: raise ValueError('Invalid client id.') except ValueError: return response.error('Could not sign in') user_id = idinfo['sub'] stored_id_token = login_session.get('id_token') stored_user_id = login_session.get('user_id') user = db_utils.get_user(user_id) if user is None: # Add user to database if id does not exist. db_utils.add_user(user_id, idinfo['email'], idinfo['name']) if stored_id_token is not None and stored_user_id == user_id: return response.success() # Store the access token in the session for later use. login_session['id_token'] = g_id_token login_session['user_id'] = user_id login_session['name'] = idinfo['name'] login_session['email'] = idinfo['email'] login_session['picture'] = idinfo['picture'] return response.success()
def get_my_items_page(user_id=0): if user_id == 0 and not auth.is_signed_in(): # This would be reached when /myitems is requested. # Redirect to login page. # The url to which we are redirected will contain a paramenter # which will be the url to redirect back to # after logging in redirect_parameter = 'redirect={}'.format(url_for('get_my_items_page')) url = '{path}?{parameter}'.format(path=url_for('get_login_page'), parameter=redirect_parameter) return redirect(url, 302) page_title = 'My Items' if user_id != 0: user = db_utils.get_user(user_id) page_title = 'Items by {}'.format(user.name) categories = db_utils.get_categories() items = db_utils.get_user_items(user_id if user_id else auth.get_user_id()) for item in items: item.nice_date = '{month} {day}, {year}'.format( month=calendar.month_name[item.created_at.month], day=item.created_at.day, year=item.created_at.year) signed_in = auth.is_signed_in() is_user_admin = False if signed_in: is_user_admin = auth.is_user_admin() return render_template( 'index.html', page_title=page_title, categories=categories, items=items, CLIENT_ID=CLIENT_ID, signed_in=signed_in, is_user_admin=is_user_admin, user_name=auth.get_user_name(), picture=auth.get_user_picture(), SIGNIN_REQUEST_TOKEN=auth.get_signin_request_token())
def post(self): parser = reqparse.RequestParser() parser.add_argument('project_name', type=str, required=True, help='Name of project') parser.add_argument('users', type=str, action='append') args = parser.parse_args() project_name = args['project_name'] all_users = args['users'] project = Project(project_name=project_name, date_added=datetime.datetime.now()) session.add(project) all_names = get_all_usernames() user_objects = [] for name in all_users: if name in all_names: user_objects.append(get_user(name)) else: abort(404, {'message': 'Username %s does not exist' % name}) project.add_users(user_objects) try: session.commit() except Exception as project_exception: session.rollback() abort(404, {'message': str(project_exception)}) return jsonify({ 'project': 'http://%s:%s/project/%s' % (HOST, PORT, project_name), 'users': all_users })
async def handle_message_leaderboard(message, client): parser = argparse.ArgumentParser(prog="!leaderboard", description="Display Leaderboard") parser.add_argument("-l", "--length", type=int, help="number of positions to list", nargs="?", default=10) parser.add_argument( "-a", "--after", type=str, help="consider problems on or after this date (YYYY-MM-DD)", nargs="?", default="2019-1-1") parser.add_argument( "-b", "--before", type=str, help="consider problems on or before this date (YYYY-MM-DD)", nargs="?", default="2099-1-1") parser.add_argument("-i", "--ignore-diff", help="if this flag is true, ignore problem weight", action='store_true') response = "" help = "-h" in message.content if help: output = io.StringIO() parser.print_help(output) response += output.getvalue() + "\n\n" await send_message(message.channel, response) return parsed = None try: parsed = parser.parse_args(message.content[12:].strip().split()) except: await send_message(message.channel, "invalid syntax") return lb_size = parsed.length after = parsed.after before = parsed.before ignore_diff = 2 if parsed.ignore_diff == True else 1 before_arr = before.split("-") after_arr = after.split("-") probs = get_problems_between_dates(int(after_arr[0]), int(after_arr[1]), int(after_arr[2]), int(before_arr[0]), int(before_arr[1]), int(before_arr[2])) diffMap = dict() numMap = dict() for prob in probs: discordId = prob[0] if discordId not in diffMap: diffMap[discordId] = 0 numMap[discordId] = 0 diffMap[discordId] += prob[2] numMap[discordId] += 1 users = [] for key in diffMap.keys(): user = get_user(key) display_name = await get_display_name(user[1], client) users.append((display_name, diffMap[key], numMap[key])) index_to_sort_by = 1 #2 would be by abolute number of probs users = sorted(users, key=sort_by_tuple_index(ignore_diff, False)) ans = [] for i in range(min(lb_size, len(users))): ans.append((i + 1, users[i][0], users[i][1], users[i][2])) if len(ans) == 0: response = "no problems solved at this time" else: response = table(("Rank", "User", "Diff Sum", "Solved"), ans, True) await send_message(message.channel, response)