def load(request: Request): user = request.user post_id = int(request.inputs['ext'][0]) post = Post.query().select().where('id', post_id).getOne() post_like: Post_like = Post_like.query().select().where( 'post_id', post_id).where('user_id', user.id).getOne() liked = False if post_like is not None: liked = True if post is None: posts = Post.query().select().where('user_id', user.id).get() view = View( 'post.view', { 'user': user, 'posts': posts, 'error': 'Incorrect index position. Please try again.' }, request.json) else: view = View('post.load', { 'user': user, 'post': post, 'whether_post_liked_by_user': liked }, request.json) return Response(ResponseType.valid, view)
def gen_top_view(self, model): regs = [] insts = [] i = 0 regs.append(View(model.get_module(f"rf_{i}"))) insts.append(View(model.get_module(f"inst_{i}"))) regs = HSplit(regs[0], insts[0]) return regs
class BurpExtender(IBurpExtender, IExtensionStateListener, IScannerCheck, ITab, ITextEditor): EXTENSION_NAME = "HUNT Scanner" # TODO: Figure out why this gets called twice def __init__(self): self.issues = Issues() self.view = View(self.issues) def registerExtenderCallbacks(self, callbacks): self.callbacks = callbacks self.view.set_callbacks(callbacks) self.helpers = callbacks.getHelpers() self.view.set_helpers(self.helpers) self.callbacks.registerExtensionStateListener(self) self.callbacks.setExtensionName(self.EXTENSION_NAME) self.callbacks.addSuiteTab(self) self.callbacks.registerScannerCheck(self) def doPassiveScan(self, request_response): raw_request = request_response.getRequest() raw_response = request_response.getResponse() httpservice = request_response.getHttpService() request = self.helpers.analyzeRequest(httpservice, raw_request) response = self.helpers.analyzeResponse(raw_response) # Disregard all URLs out of scope url = request.getUrl() if (not self.callbacks.isInScope(url)): return [] parameters = request.getParameters() vuln_parameters = self.issues.check_parameters(self.helpers, parameters) is_not_empty = len(vuln_parameters) > 0 if is_not_empty: self.issues.create_scanner_issues(self.view, self.callbacks, self.helpers, vuln_parameters, request_response) # Do not show any HUNT found issues in the Burp Scanner window return [] def getTabCaption(self): return self.EXTENSION_NAME def getUiComponent(self): return self.view.get_pane() def extensionUnloaded(self): print "HUNT Scanner plugin unloaded" return
def add(request: Request): user = request.user post_id = int(request.inputs['ext'][0]) content = request.inputs['content'] Comment.query().insert( [post_id, user.id, content, datetime.today(), datetime.today()]) post = Post.query().select().where('id', post_id).getOne() post_like: Post_like = Post_like.query().select().where( 'post_id', post_id).where('user_id', user.id).getOne() liked = False if post_like is not None: liked = True view = View('post.load', { 'user': user, 'post': post, 'whether_post_liked_by_user': liked }, request.json) return Response(ResponseType.valid, view)
def setUp(self): self.io = MockIO() self.move_validator = MoveValidator() self.selection_validator = SelectionValidator() self.string_validator = StringValidator() self.board_presenter = TTTBoardPresenter() self.view = View(self.io, self.move_validator, self.selection_validator, self.string_validator, self.board_presenter)
def show(request: Request): user = request.user posts = Post.query().select().where('user_id', user.id).get() view = View('post.view', {'user': user, 'posts': posts}, request.json) return Response(ResponseType.valid, view)
def logout(request: Request): loggedUserId: int = request.json['user_id'] User_auth.query().delete().where('user_id', loggedUserId).get() view = View('', {}) return Response(ResponseType.valid, view)
def show_all(request: Request): user: User = request.user posts = Post.query().select().where('public_visibility', 1).sortBy('created_at', False).get() view = View('post.view', {'user': user, 'posts': posts}, request.json) return Response(ResponseType.valid, view)
def add_form(request: Request): user = request.user post_id = int(request.inputs['ext'][0]) post = Post.query().select().where('id', post_id).getOne() view = View('comment.add', {'user': user, 'post': post}, request.json) return Response(ResponseType.valid, view)
def show_all(request: Request): user = request.user notifications: List[Notification] = Notification.query().select().get() view = View('notifications.show', { 'user': user, 'notifications': notifications }, request.json) return Response(ResponseType.valid, view)
def edit_password(request: Request): loggedUserId: int = request.json['user_id'] old_password = request.json['inputs']['old_password'] password = request.json['inputs']['password'] re_password = request.json['inputs']['re_password'] user: User = User.query().select().where('id', loggedUserId).getOne() if password != re_password: view = View('user.edit', {'error': 'passwords do not match'}, request.json) return Response(ResponseType.valid, view) passHash = hashlib.sha256(old_password.encode()) passHash = passHash.hexdigest() if user.passwordHash != passHash: view = View('user.edit', {'error': 'old password is wrong'}, request.json) return Response(ResponseType.valid, view) passHash = hashlib.sha256(password.encode()) passHash = passHash.hexdigest() user.passwordHash = passHash user.save() notifications: List[Notification] = Notification.query().select( ).where('is_read', 0).get() posts = Post.query().select().where('user_id', user.id).get() view = View( 'home', { 'user': user, 'notification_count': len(notifications), 'my_post_count': len(posts) }, request.json) return Response(ResponseType.valid, view)
def login(request: Request): username = request.json['inputs']['name'] password: str = request.json['inputs']['password'] passHash = hashlib.sha256(password.encode()) passHash = passHash.hexdigest() users: List[User] = User.query().select().where( 'name', username).where('passwordHash', passHash).get() if not users: view = View('', {'error': 'Invalid credentials. Please try again...'}, request.json) return Response(ResponseType.error, view) user = users[0] token = user.hash() User_auth.query().insert( [user.id, token, datetime.today(), datetime.today()]) notifications: List[Notification] = Notification.query().select( ).where('is_read', 0).get() posts = Post.query().select().where('user_id', user.id).get() view = View( 'home', { 'user': user, 'notification_count': len(notifications), 'my_post_count': len(posts) }, { 'user_id': user.id, 'authToken': token }) return Response(ResponseType.valid, view)
def view(request: Request): user = request.user post_id = int(request.inputs['ext'][0]) post = Post.query().select().where('id', post_id).getOne() comments: List[Comment] = Comment.query().select().where( 'post_id', post_id).sortBy('created_at', False).get() view = View('comment.load', { 'user': user, 'post': post, 'comments': comments }, request.json) return Response(ResponseType.valid, view)
def gen_top_view(self, model): regs = [] insts = [] wmem = [] remote = [] # This represents a fairly standard paradigm for creating Displays. # We start by creating a "View" of each module that we want to display. for i in range(X_DIM): for j in range(Y_DIM): regs.append(View(model.get_module(f"rf_{i}_{j}"))) insts.append(View(model.get_module(f"inst_{i}_{j}"))) wmem.append(View(model.get_module(f"wmem_{i}_{j}"))) remote.append(View(model.get_module(f"remote_{i}_{j}"))) # Then, we arrange the views with HSplits and VSplits. regs = HSplit( VSplit( HSplit(VSplit(regs[0], remote[0]), VSplit(insts[0], wmem[0])), HSplit(VSplit(regs[1], remote[1]), VSplit(insts[1], wmem[1]))), VSplit( HSplit(VSplit(regs[2], remote[2]), VSplit(insts[2], wmem[2])), HSplit(VSplit(regs[3], remote[3]), VSplit(insts[3], wmem[3])))) return regs
def show(request: Request): user = request.user notifications: List[Notification] = Notification.query().select( ).where('is_read', 0).get() Notification.query().updateMany({ 'is_read': 1 }).where('is_read', 0).getWithoutTransform() view = View('notifications.show', { 'user': user, 'notifications': notifications, 'show_option': 1 }, request.json) return Response(ResponseType.valid, view)
def home(request: Request): loggedUserId: int = request.json['user_id'] user: User = User.query().select().where('id', loggedUserId).getOne() notifications: List[Notification] = Notification.query().select( ).where('is_read', 0).get() posts = Post.query().select().where('user_id', user.id).get() view = View( 'home', { 'user': user, 'notification_count': len(notifications), 'my_post_count': len(posts) }, request.json) return Response(ResponseType.valid, view)
def add(request: Request): user: User = request.user title = request.inputs['title'] content = request.inputs['content'] allow_comments = 0 if request.inputs['allow_comments'] == 'n' else 1 visibility = 0 if request.inputs['visibility'] == '0' else 1 tags = request.inputs['tags'] Post.query().insert([ user.id, title, content, allow_comments, visibility, tags, datetime.today(), datetime.today() ]) view = View('home', {'user': user}, request.json) return Response(ResponseType.valid, view)
def like(request: Request): user = request.user post_id = int(request.inputs['ext'][0]) post_like: Post_like = Post_like.query().select().where( 'post_id', post_id).where('user_id', user.id).getOne() liked = False if post_like is None: liked = True Post_like.query().insert( [user.id, post_id, datetime.today(), datetime.today()]) else: post_like.delete() post = Post.query().select().where('id', post_id).getOne() view = View('post.load', { 'user': user, 'post': post, 'whether_post_liked_by_user': liked }, request.json) return Response(ResponseType.valid, view)
def show_login(request: Request): view = View('', {}, request.json) return Response(ResponseType.valid, view)
def __init__(self): self.issues = Issues() self.view = View(self.issues)
def main(): """ Prepara las ventanas, define modelos, controlador y vista y corre el programa :return: void """ # Se obtiene el checksum del juego checksum = [path_checksum('lib', VERBOSE), md5file('main.py', VERBOSE).upper(), path_checksum('bin', VERBOSE)] # Se cargan las configuraciones control_config = configLoader(DIR_CONFIG + "control.ini", verbose=VERBOSE) game_config = configLoader(DIR_CONFIG + "game.ini", verbose=VERBOSE) map_config = configLoader(DIR_CONFIG + "map.ini", verbose=VERBOSE) score_config = configLoader(DIR_CONFIG + "scoreboard.ini", verbose=VERBOSE) user_config = configLoader(DIR_CONFIG + "user.ini", verbose=VERBOSE) view_config = configLoader(DIR_CONFIG + "view.ini", verbose=VERBOSE) window_config = configLoader(DIR_CONFIG + "window.ini", verbose=VERBOSE) world_config = configLoader(DIR_CONFIG + "world.ini", verbose=VERBOSE) # Se carga el idioma lang = langs.langLoader(game_config.getValue("LANG")) # @UndefinedVariable # Se carga la información de la pantalla del cliente display_info = pygame.display.Info() # @UndefinedVariable # Se comprueba que el nombre de jugador no sea Player, si no es valido se pide uno nuevo if not username.validate( user_config.getValue("NAME")): # @UndefinedVariable new_name = username.request(lang.get(111), lang.get(112)) # @UndefinedVariable if new_name is not username.NO_VALID_NAME: # @UndefinedVariable user_config.setParameter("NAME", new_name) user_config.export() else: utils.destroyProcess() # @UndefinedVariable # Creación de ventana window = Window(window_config, lang.get(10), pygame.image.load(getIcons("icon")), display_info) # @UndefinedVariable clock = pygame.time.Clock() # reloj @UndefinedVariable fps = int(game_config.getValue("FPS")) # fps a dibujar # Se crea el mundo world = World(world_config, map_config, window, checksum, score_config, user_config, lang, game_config, verbose=VERBOSE) # TEST: world.loadMap(1) # Se crean los menús de inicio y pause menus = Createuimenu(lang, window, world, game_config, user_config, view_config, window_config, world_config, map_config) # Se crea la vista vista = View(window, clock, world, lang, view_config, menus) menus.addView(vista) # Se crea el controlador control = Controller(world, clock, lang, control_config, window, menus, verbose=VERBOSE) menus.addController(control) vista.add_controller(control) # Se lanza el mainloop while True: clock.tick(fps) vista.draw(control.event_loop())
def register(request: Request): username = request.json['inputs']['name'] email = request.json['inputs']['email'] password: str = request.json['inputs']['password'] re_password = request.json['inputs']['re_password'] role = 1 if request.json['inputs']['role'] == '1' else 2 if len(password) < 8: view = View( '', objects={'error': 'Password too short. Please try again...'}) return Response(ResponseType.error, view) if password != re_password: view = View('', objects={ 'error': 'Passwords do not match. Please try again...' }) return Response(ResponseType.error, view) if '@' not in email or '.' not in email: view = View('', objects={ 'error': 'Email format is wrong. Please try again...' }) return Response(ResponseType.error, view) user = User.query().select().where('name', username).getOne() if user is not None: view = View('', objects={ 'error': 'Username already taken. Please try again...' }) return Response(ResponseType.error, view) passHash = hashlib.sha256(password.encode()) passHash = passHash.hexdigest() User.query().insert([ username, email, '', passHash, role, datetime.today(), datetime.today() ]) user: User = User.query().select().where('name', username).getOne() token = user.hash() User_auth.query().insert( [user.id, token, datetime.today(), datetime.today()]) NotificationController.notifyUser( user, 'Welcome to freelancerHub, Feel free to look around the site.') notifications: List[Notification] = Notification.query().select( ).where('is_read', 0).get() posts = Post.query().select().where('user_id', user.id).get() view = View( 'home', { 'user': user, 'notification_count': len(notifications), 'my_post_count': len(posts) }, { 'user_id': user.id, 'authToken': token }) return Response(ResponseType.valid, view)
def show_add_form(request: Request): user = request.user view = View('post.add', {'user': user}, request.json) return Response(ResponseType.valid, view)
def main(): """ Prepara las ventanas, define modelos, controlador y vista y corre el programa. :return: void """ # Se obtiene el checksum del juego checksum = [ path_checksum('lib', VERBOSE), '8e1fd1c03d2bfe89d7dbdab8b0c4c69a'.upper(), path_checksum('bin', VERBOSE) ] # Se cargan las configuraciones control_config = Configloader(DIR_CONFIG + 'control.ini', verbose=VERBOSE) game_config = Configloader(DIR_CONFIG + 'game.ini', verbose=VERBOSE) map_config = Configloader(DIR_CONFIG + 'map.ini', verbose=VERBOSE) score_config = Configloader(DIR_CONFIG + 'scoreboard.ini', verbose=VERBOSE) user_config = Configloader(DIR_CONFIG + 'user.ini', verbose=VERBOSE) view_config = Configloader(DIR_CONFIG + 'view.ini', verbose=VERBOSE) window_config = Configloader(DIR_CONFIG + 'window.ini', verbose=VERBOSE) world_config = Configloader(DIR_CONFIG + 'world.ini', verbose=VERBOSE) # Se carga el idioma lang = langs.Langloader(game_config.getValue('LANG')) # Se carga la información de la pantalla del cliente display_info = pygame.display.Info() # Se comprueba que el nombre de jugador no sea Player, si no es valido se pide uno nuevo if not username.validate(user_config.getValue('NAME')): new_name = username.request(lang.get(111), lang.get(112)) if new_name is not username.NO_VALID_NAME: user_config.setParameter('NAME', new_name) user_config.export() else: utils.destroy_process() # Creación de ventana window = Window(window_config, lang.get(10), pygame.image.load(getIcons('icon')), display_info) clock = pygame.time.Clock() # Reloj fps = int(game_config.getValue('FPS')) # FPS a dibujar # Se crea el mundo world = World(world_config, map_config, window, checksum, score_config, user_config, lang, game_config, verbose=VERBOSE) # world.load_map(1) # Se crean los menús de inicio y pause menus = Createuimenu(lang, window, world, game_config, user_config, view_config, window_config, world_config, map_config) # Se crea la vista vista = View(window, clock, world, lang, view_config, menus) menus.addView(vista) # Se crea el controlador control = Controller(world, clock, lang, control_config, window, menus, verbose=VERBOSE) menus.addController(control) vista.add_controller(control) # Se lanza el mainloop while True: clock.tick(fps) vista.draw(control.event_loop())
def show_edit(request: Request): view = View('user.edit', {}, request.json) return Response(ResponseType.valid, view)
def gen_top_view(self, model): return HSplit(View(model.get_module('memory')), View(model.get_module('r0_data')))
class TestView(unittest.TestCase): def setUp(self): self.io = MockIO() self.move_validator = MoveValidator() self.selection_validator = SelectionValidator() self.string_validator = StringValidator() self.board_presenter = TTTBoardPresenter() self.view = View(self.io, self.move_validator, self.selection_validator, self.string_validator, self.board_presenter) def tearDown(self): del self.io def test_prompt_numbered_options(self): options = ['option1', 'option2'] self.view.prompt_numbered_options(options) self.assertEquals(self.io.display_called, True) self.assertEquals(self.io.display_called_with, options[-1]) def test_get_numbered_options_selection(self): self.io.stub_user_input('1') options = ['1', '2'] self.assertEquals(self.view.get_numbered_option_selection(options), '1') self.assertEquals(self.io.get_user_input_called, True) self.assertEquals(self.io.get_user_input_called_with, ('')) def test_get_player_name(self): order = 'First' self.io.stub_user_input('John Doe') self.assertEquals(self.view.get_player_name(order), 'John Doe') self.assertEquals(self.io.get_user_input_called, True) self.assertEquals(self.io.get_user_input_called_with, '\nFirst player, what is your name?') def test_display_coin_flip(self): self.view.display_coin_flip() self.assertEquals(self.io.display_called, True) self.assertEquals(self.io.display_called_with, '\nFlipping a coin to determine order ') self.assertEquals(self.io.display_with_sleep_called, True) def test_display_player_order(self): player_name = 'Player 1' self.view.display_player_order(player_name) self.assertEquals(self.io.display_called, True) self.assertEquals(self.io.display_called_with, '\nPlayer 1 will go first') def test_prompt_player_move(self): player_name = 'Player 1' self.view.prompt_player_move(player_name) self.assertEquals(self.io.display_called, True) self.assertEquals(self.io.display_called_with, 'Player 1, select a position for your move: ') def test_get_player_move(self): self.io.stub_user_input('2') board_size = 9 board = TTTBoard(board_size) self.assertEquals(self.view.get_player_move(board), '2') self.assertEquals(self.io.get_user_input_called, True) self.assertEquals(self.io.get_user_input_called_with, '') def test_print_board_positions(self): board = [1, 2, 3, 4, 5, 6, 7, 8, 9] self.view.print_board(board) self.assertEquals(self.io.display_called, True) self.assertEquals(self.io.display_called_with, ' 1 | 2 | 3\n===+===+===\n 4 | 5 | 6\n===+===+===\n 7 | 8 | 9\n') def test_print_board_active_board(self): board = [' '] * 9 self.view.print_board(board) self.assertEquals(self.io.display_called, True) self.assertEquals(self.io.display_called_with, ' | | \n===+===+===\n | | \n===+===+===\n | | \n') def test_display_computer_thinking(self): self.view.display_computer_thinking() self.assertEquals(self.io.display_called, True) self.assertEquals(self.io.display_called_with, '\nThe computer is thinking') self.assertEquals(self.io.display_with_sleep_called, True) self.assertEquals(self.io.sleep_called, True) def test_display_tie_message(self): self.view.display_tie_message() self.assertEquals(self.io.display_called, True) self.assertEquals(self.io.display_called_with, 'Game over. It\'s a tie.') def test_display_winning_message(self): wining_player_name = 'Player 1' self.view.display_winning_message(wining_player_name) self.assertEquals(self.io.display_called, True) self.assertEquals(self.io.display_called_with, 'Game over. Player 1 wins!') def test_clear_screen(self): self.view.clear_screen() self.assertEquals(self.io.clear_called, True) def test_loading(self): self.view.loading(3, '. ') self.assertEquals(self.io.display_with_sleep_called, True) self.assertEquals(self.io.display_with_sleep_called_with, '. ') self.assertEquals(self.io.sleep_called, True)