def testSendEmail(self): callback = my_callback data = {'mail':'*****@*****.**'} email = {'subject':'subject', 'sender':'*****@*****.**'} with patch('test_activation.my_callback') as c: with self.app.test_request_context(): c.return_value = url_for('index') signature = signature_serialize(callback, data) with self.mail.record_messages() as outbox: send_activation_email(self.mail, '*****@*****.**', callback=callback, data=data, email_context=email, template_context={}, body_template='test.html') self.assertEquals(1, len(outbox), 'Email was sent') self.assertIn(url_for('emailactivation.activation', signature=signature, _external=True), outbox[0].body) with self.app.test_client() as client: response = client.get(url_for('emailactivation.activation', signature=signature,)) self.assertEquals(302, response.status_code) self.assertEquals(url_for('index', _external=True), response.location)
def profile_page(): try: if request.method == 'POST': with dbapi2.connect(app.config['dsn']) as connection: cursor = connection.cursor() friend=request.form['friend'] if request.form['action'] == 'add': query = """INSERT INTO FRIENDS(USERNAME, FRIEND) VALUES(%s, %s)""" cursor.execute(query,(current_user.userName, friend)) connection.commit() elif request.form['action'] == 'remove': query = """DELETE FROM FRIENDS WHERE (USERNAME= %s and FRIEND = %s)""" cursor.execute(query,(current_user.userName, friend)) connection.commit() return redirect(url_for('profile_page')) else: with dbapi2.connect(app.config['dsn']) as connection: cursor = connection.cursor() query = """SELECT * FROM USERS""" cursor.execute(query) info=cursor.fetchall() connection.commit() query = """SELECT * FROM INFO""" cursor.execute(query) details=cursor.fetchall() query = """SELECT * FROM FRIENDS """ cursor.execute(query) friends=cursor.fetchall() connection.commit() return render_template('profile.html',info=info,user=current_user,details=details,friends=friends) except Exception as e: return redirect(url_for('profile_page'))
def post(self): # One can only delete themselves, if they are logged in and post with a # vaild state if not self.request.form.get("csrf") == session.get('state'): return self.flash_out( "The state does not match the session, please try again", 401, url_for("myaccount_view")) # Get the user id from session uid = session.get('uid') if not uid: self.auth.logout() return self.flash_out( "No valid login detected", 401, url_for("login_view")) # Revoke the access token for the provider provider = session.get('provider') if provider == "google": self.google.disconnect() elif provider == 'facebook': self.facebook.disconnect() # Delete all the items that belong to the user Items.delete_by_user(dbs, uid) # Delete the user's image Images.delete_by_id(dbs, self.user.picture) # Delete the user User.delete_user(dbs, uid) self.auth.logout() return self.flash_out("The account has been deleted", 200, "/")
def init_oidc_provider(app): with app.app_context(): issuer = url_for('oidc_provider.index')[:-1] authentication_endpoint = url_for('oidc_provider.authentication_endpoint') jwks_uri = url_for('oidc_provider.jwks_uri') token_endpoint = url_for('oidc_provider.token_endpoint') userinfo_endpoint = url_for('oidc_provider.userinfo_endpoint') configuration_information = { 'issuer': issuer, 'authorization_endpoint': authentication_endpoint, 'jwks_uri': jwks_uri, 'token_endpoint': token_endpoint, 'userinfo_endpoint': userinfo_endpoint, 'scopes_supported': ['openid'], 'response_types_supported': ['code', 'code id_token', 'code token', 'code id_token token'], # code and hybrid 'response_modes_supported': ['query', 'fragment'], 'grant_types_supported': ['authorization_code', 'implicit'], 'subject_types_supported': ['pairwise'], 'token_endpoint_auth_methods_supported': ['client_secret_basic'], 'claims_parameter_supported': True } clients_db = OpStorageWrapper(app.config['DB_URI'], 'clients') userinfo_db = Userinfo(app.users) with open(app.config['PROVIDER_SIGNING_KEY']['PATH']) as f: key = f.read() signing_key = RSAKey(key=import_rsa_key(key), kid=app.config['PROVIDER_SIGNING_KEY']['KID'], alg='RS256') provider = Provider(signing_key, configuration_information, init_authorization_state(app), clients_db, userinfo_db) provider.authentication_request_validators.append(_request_contains_nonce) return provider
def submit(id): """ similar to the test submission. The code is submitted by this method , it stores the code in the `upload` folder and then finds the score :param id: :return: """ print(current_user.username) form = SubmitForm() if request.method == 'POST': file = request.files['code'] print(os.path.abspath("static")) if file and allowed_file(file.filename): filename = "_".join([current_user.username, str(id), str(int(time.time()))]) location = os.path.join(UPLOAD_LOCATION, filename) file.save(location) userid = int(current_user.id) code_process = Process(target=find_score, args=(location, id, userid)) code_process.start() flash("your code has been uploaded") return redirect(url_for("questions.getquestion", id=id)) else: flash("that file format is not allowed", category="warning") return redirect(url_for("questions.getquestion", id=id))
def countries_page(): connection = dbapi2.connect(app.config['dsn']) cursor = connection.cursor() now = datetime.datetime.now() if request.method == 'GET': query = """SELECT COUNTRY_ID,COUNTRY_NAME,COUNTRY_CONTINENT,COUNTRY_CAPITAL,COUNTRY_INDEPEN_YEAR FROM COUNTRIES GROUP BY COUNTRY_ID ORDER BY COUNTRY_NAME """ cursor.execute(query) return render_template('countries.html', countries = cursor.fetchall(), current_time=now.ctime()) elif "add" in request.form: country1 = Countries(request.form['country'], request.form['continent'], request.form['capital'], request.form['independency']) add_country(cursor, request,country1) connection.commit() return redirect(url_for('countries_page')) elif "delete" in request.form: for line in request.form: if "checkbox" in line: delete_country(cursor, int(line[9:])) connection.commit() return redirect(url_for('countries_page')) elif "search" in request.form: result=search_country(cursor, request.form['search_name']) return render_template('Country_search.html', countries = result, current_time=now.ctime())
def url_for_symbol(self, value): if value[collector.TYPE] in [collector.TYPE_FUNCTION]: return url_for("path", path=self.collector.qualified_symbol_name(value)) # file or folder path = value.get(collector.PATH, None) return url_for("path", path=path) if path else ""
def login(): """ Show the login page and handle login requests. :return: The login page. :rtype: flask.Response """ if request.method == 'POST': try: username = request.form.get('username', None) password = request.form.get('password', None) if username is None or password is None: flash('Invalid data', 'danger') return redirect(url_for('login')) user = User.query().filter_by(username=username).first() if user is None or not user.check_password(password): flash('Invalid login credentials', 'danger') else: flash('You were logged in successfully!', 'success') session['logged_in'] = True session['user'] = user.id if request.args.get('next', None): return redirect(request.args['next']) return redirect(url_for('main_page')) except KeyError: flash('Missing username or password', 'info') return render_template('login.html')
def get_clubs_page(app): if request.method == 'GET': now = datetime.datetime.now() clubs = get_all_clubs(app) countries = get_country_names(app) return render_template('clubs.html', clubs=clubs, countries=countries, current_time=now.ctime()) elif "add" in request.form: club = Clubs(request.form['name'], request.form['place'], request.form['year'], request.form['chair'], request.form['number_of_members'], request.form['rewardnumber']) add_club(app, request, club) return redirect(url_for('clubs_page')) elif "delete" in request.form: for line in request.form: if "checkbox" in line: delete_club(app, int(line[9:])) return redirect(url_for('clubs_page')) elif 'search' in request.form: clubs = search_club(app, request.form['club_to_search']) return render_template('clubs_search_page.html', clubs = clubs)
def raceinfo_page(): racs = Raceinfos(app.config['dsn']) method = Func(app.config['dsn']) tr_list = method.get_tracks() nat_list = method.get_nations() yr_list = method.get_years() dr_list = method.get_drivers() if request.method == 'GET': now = datetime.datetime.now() racinflist = racs.get_raceinfolist() return render_template('raceinfos.html', RaceList = racinflist, current_time = now.ctime(), TrackList = tr_list, NationList = nat_list, YearList = yr_list, DriverList = dr_list) elif 'raceinfos_to_delete' in request.form: raceinfos = request.form.getlist('raceinfos_to_delete') for raceinfo in raceinfos: racs.delete_raceinfo(raceinfo) return redirect(url_for('raceinfo_page')) elif 'raceinfos_to_add' in request.form: racs.add_raceinfo(request.form) return redirect(url_for('raceinfo_page')) elif 'raceinfos_to_update' in request.form: racs.update_raceinfo(request.form) return redirect(url_for('raceinfo_page')) elif 'raceinfos_to_searchwinner' in request.form: now = datetime.datetime.now() racinflist = racs.search_raceinfolist('winner', request.form) return render_template('raceinfos.html', RaceList = racinflist, current_time = now.ctime(), TrackList = tr_list, NationList = nat_list, YearList = yr_list, DriverList = dr_list) elif 'raceinfos_to_searchtrack' in request.form: now = datetime.datetime.now() racinflist = racs.search_raceinfolist('track', request.form) return render_template('raceinfos.html', RaceList = racinflist, current_time = now.ctime(), TrackList = tr_list, NationList = nat_list, YearList = yr_list, DriverList = dr_list)
def bd(source=None): """ 绑定微信与门户账户 :param source: :return: """ if source: w = WechatUser.query.filter(and_(WechatUser.source == source, WechatUser.checked == 1)).first() if w: staff = portal_user.query.filter(portal_user.user_code == w.usercode).first() login_user(staff, remember=True) flash('您已经绑定了' + w.usercode) return redirect(url_for('index')) from forms import WechatUserSendcode form = WechatUserSendcode() if form.validate_on_submit(): usercode = form.usercode.data.replace('@chinaunicom.cn', '') sendcode(source=source, usercode=usercode) flash('验证码发送成功!') return redirect(url_for('bdchk', usercode=usercode, source=source)) return render_template('WechatUserSendcode.html', title='绑定', form=form, source=source)
def f(*args,**kwargs): if not 'user' in session: return redirect(url_for("login-required")) user = get_user_object() if 'user' in session and not user: return redirect(url_for('logout')) return func(*args, user=user,**kwargs)
def test_valid_get(self): with self.test_client as client: bot_id = loads(client.get(url_for('init_game')).data).get('bot_id') response = client.get(url_for('admin_game_detail', bot_id=bot_id)) self.assertTrue('text/html' in response.content_type, 'Correct content type.') self.assertEqual(response.status_code, 200)
def save_update(self): id = _g('id', None) if not id : flash(MSG_NO_ID_SUPPLIED, MESSAGE_ERROR) return redirect(url_for('.view')) obj = DBSession.query(Customer).get(id) if not obj : flash(MSG_RECORD_NOT_EXIST, MESSAGE_ERROR) return redirect(url_for('.view')) try: fields = ['no', 'name', 'display_name', 'province_id', 'city_id', 'address', 'contact_person', 'mobile', 'phone', 'email', 'note_id', 'remark'] old_info = obj.serialize(fields) # to used for the history log for f in fields: setattr(obj, f, _g(f)) #handle the file upload old_attachment_ids = map(lambda (k, v) : v, _gp("old_attachment_")) old_attachment_ids.extend(multiupload()) obj.attachment = old_attachment_ids DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) # return redirect(url_for('.view',id=obj.id)) new_info = obj.serialize(fields) change_result = obj.compare(old_info, new_info) obj.insert_system_logs(change_result) except: _error(traceback.print_exc()) DBSession.rollback() flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(url_for('.view', action = "view", id = obj.id))
def get_penalty_page(app): if request.method == 'GET': now = datetime.datetime.now() penalties = get_all_penalties(app) curlers = get_curlers_names(app) return render_template('penalty.html', penalties = penalties, curlers=curlers, current_time=now.ctime()) elif "add" in request.form: penalty = Penalty(request.form['personname'], request.form['startdate'], request.form['enddate'], request.form['type']) add_penalty(app, request, penalty) return redirect(url_for('penalty_page')) elif "delete" in request.form: for line in request.form: if "checkbox" in line: delete_penalty(app, int(line[9:])) return redirect(url_for('penalty_page')) elif 'search' in request.form: penalties = search_penalty(app, request.form['penalty_to_search']) return render_template('penalty_search_page.html', penalties = penalties)
def get_fixture_page(app): if request.method == 'GET': now = datetime.datetime.now() matches = get_all_matches(app) clubs = get_club_names(app) stadiums = get_stadium_names(app) return render_template('fixture.html', matches=matches, clubs=clubs, stadiums=stadiums, current_time=now.ctime()) elif 'add' in request.form: match = Match(request.form['team1'], request.form['team2'], request.form['date'], request.form['time'], request.form['location']) add_match(app, request, match) return redirect(url_for('fixture_page')) elif 'delete' in request.form: for line in request.form: if 'checkbox' in line: delete_match(app, int(line[9:])) return redirect(url_for('fixture_page')) elif 'search' in request.form: matches = search_match(app, request.form['team_to_search']) return render_template('fixture_search_page.html', matches = matches)
def save_new(self): try: obj = Customer( no = _g('no'), name = _g('name'), display_name = _g('display_name'), province_id = _g('province_id'), city_id = _g('city_id'), address = _g('address'), contact_person = _g('contact_person'), mobile = _g('mobile'), phone = _g('phone'), email = _g('email'), remark = _g('remark'), note_id = _g('note_id'), # payment_id = _g('payment_id'), ) DBSession.add(obj) obj.attachment = multiupload() DBSession.commit() flash(MSG_SAVE_SUCC, MESSAGE_INFO) return redirect(url_for('.view', action = 'view', id = obj.id)) except: _error(traceback.print_exc()) DBSession.rollback() flash(MSG_SERVER_ERROR, MESSAGE_ERROR) return redirect(url_for('.view'))
def user_page(): uses = Users(app.config['dsn']) if request.method == 'GET' and ('users_to_new' not in request.form): now = datetime.datetime.now() uselist = uses.get_userlist() return render_template('users.html', UserList = uselist, current_time=now.ctime()) elif 'users_to_delete' in request.form: id_users = request.form.getlist('users_to_delete') for id_user in id_users: uses.delete_user(id_user) return redirect(url_for('user_page')) elif 'users_to_add' in request.form: uses.add_user(request.form['kuladi'],request.form['password']) return redirect(url_for('user_page')) elif 'users_to_update' in request.form: uses.update_user(request.form['id_user'], request.form['kuladi'],request.form['password']) return redirect(url_for('user_page')) elif 'users_to_search' in request.form: searchList = uses.search_user(request.form['name']); now = datetime.datetime.now() uselist = uses.get_userlist() return render_template('users.html', UserList = uselist, SearchList = searchList, current_time=now.ctime()) elif 'users_to_new' in request.form: uses.add_user(request.form['user'],request.form['password']) return redirect(url_for('home_page2'))
def basic_auth(): ''' Checks basic authentication by login/password ''' # Extracts data from the posted request container = request.get_json(False, True, False) if request.mimetype == "application/json" else request.form login = container["login"] password = container["password"] # Checks parameters are filled if (not login) or (not password): return jsonify(message = "Login, password and email are mandatory"), 400 # Checks if user with given login exists in db user = user_db_service.get_user_by_login(login) if user is None: return jsonify(message = "Wrong login and password combination."), 400 # Checks user password if not user.check_password(password): return jsonify(message = "Wrong login and password combination."), 400 # Registers user id in session session["uid"] = user.uid # Checks if 2fa is activated if user.tfa_activited(): # 2FA activated - Redirects to tfa_challenge page return jsonify(redirect_uri = url_for("tfa_challenge")) else: # Basic auth only # Let's increase the sign_in counter in user object (for demo purpose only) user.signin_count += 1 user_db_service.update_user(user) # Everything is ok, let's finalize the authentication session["auth"] = True # Redirects to user page return jsonify(redirect_uri = url_for("user"))
def coaching(): if request.method == 'GET': return render_template('coaching.html', coachlist=app.coaching.get_coaching(), team=app.teams.select_teams(), season=app.seasons.select_seasons(),coaches=app.coaches.select_coaches() ,coaching = app.coaching.select_coaching()) else: if 'Add' in request.form: team_id = request.form['team_id'] coach_id = request.form['coach_id'] season_id = request.form['season_id'] app.coaching.add_coaching(team_id,coach_id,season_id) return redirect(url_for('coaching')) elif 'Delete' in request.form: coaching_id = request.form['id'] app.coaching.delete_coaching(coaching_id) return redirect(url_for('coaching')) elif 'Update' in request.form: coaching_id = request.form['id'] team_id = request.form['team_idU'] coach_id = request.form['coach_idU'] season_id = request.form['season_idU'] app.coaching.update_coaching(coaching_id,team_id,coach_id,season_id) return redirect(url_for('coaching')) elif 'Search' in request.form: term = request.form['coachingSearch'] return render_template('coaching.html', coachlist = app.coaching.search_coaching(term)) else: return render_template('coaching.html', result = app.coaching.select_coaching())
def get_stadiums_page(app): if request.method == 'GET': now = datetime.datetime.now() stadiums = get_all_stadiums(app) clubs = get_club_names(app) countries = get_country_names(app) return render_template('stadiums.html', stadiums=stadiums, clubs=clubs, countries=countries, current_time=now.ctime()) elif 'add' in request.form: stadium = Stadium(request.form['name'], request.form['location'], request.form['capacity'], request.form['ticket_cost']) add_stadium(app, request, stadium) return redirect(url_for('stadiums_page')) elif 'delete' in request.form: for line in request.form: if 'checkbox' in line: delete_stadium(app, int(line[9:])) return redirect(url_for('stadiums_page')) elif 'search' in request.form: stadiums = search_stadium(app, request.form['line_to_search']) return render_template('stadiums_search_page.html', stadiums = stadiums)
def get_points_page(app): if(request.method=='GET'): now = datetime.datetime.now() clubs=get_all_clubs(app) championships=get_all_championships(app) data=get_all_points_data(app) return render_template('points.html', data=data, clubs=clubs, championships=championships, current_time=now.ctime()) elif('add' in request.form): add_points_data(app, request.form) return redirect(url_for('points_page')) elif('delete' in request.form): for line in request.form: if('checkbox' in line): delete_points_data(app, int(line[9:])) return redirect(url_for('points_page')) elif('search' in request.form): now = datetime.datetime.now() clubs=get_all_clubs(app) championships=get_all_championships(app) data=get_filtered_points_data(app, request.form['line_to_search']) return render_template('points.html', data=data, clubs=clubs, championships=championships, current_time=now.ctime())
def statistic_page(): stats = Statistics(app.config['dsn']) aths = Athletes(app.config['dsn']) if request.method == 'GET': now = datetime.datetime.now() statlist = stats.get_statisticlist() athlist = aths.get_athletlist() return render_template('statistics.html', StatisticList = statlist,AthletList = athlist, current_time=now.ctime()) elif 'statistics_to_delete' in request.form: id_statistics = request.form.getlist('statistics_to_delete') for id_statistic in id_statistics: stats.delete_statistic(id_statistic) return redirect(url_for('statistic_page')) elif 'statistics_to_add' in request.form: id_athletes = request.form.getlist('statistics_to_add') for id_athlete in id_athletes: stats.add_statistic(request.form['distance'], request.form['time'],id_athlete) return redirect(url_for('statistic_page')) elif 'statistics_to_update' in request.form: stats.update_statistic(request.form['distance'], request.form['time'],request.form['id_statistic']) return redirect(url_for('statistic_page')) elif 'statistics_to_search' in request.form: searchList = stats.search_statistic(request.form['name']); now = datetime.datetime.now() statlist = stats.get_statisticlist() athlist = aths.get_athletlist() return render_template('statistics.html', StatisticList = statlist, SearchList = searchList,AthletList = athlist, current_time=now.ctime())
def comment_page(): coms = Comments(app.config['dsn']) nes = News(app.config['dsn']) if request.method == 'GET': now = datetime.datetime.now() comlist = coms.get_commentlist() nelist = nes.get_newlist() return render_template('comments.html', CommentList = comlist, NewList = nelist, current_time=now.ctime()) elif 'comments_to_delete' in request.form: id_comments = request.form.getlist('comments_to_delete') for id_comment in id_comments: coms.delete_comment(id_comment) return redirect(url_for('comment_page')) elif 'comments_to_add' in request.form: id_comments = request.form.getlist('comments_to_add') for id_comment in id_comments: coms.add_comment(request.form['name'],request.form['article'],id_comment) return redirect(url_for('comment_page')) elif 'comments_to_update' in request.form: coms.update_comment(request.form['id_comment'], request.form['name'],request.form['article']) return redirect(url_for('comment_page')) elif 'comments_to_search' in request.form: searchList = coms.search_comment(request.form['name']); now = datetime.datetime.now() comlist = coms.get_commentlist() nelist = nes.get_newlist() return render_template('comments.html', CommentList = comlist, NewList = nelist, SearchList = searchList, current_time=now.ctime())
def get_equipments_page(app): if request.method == 'GET': now = datetime.datetime.now() equipments = get_all_equipments(app) countries = get_country_names(app) return render_template('equipments.html', equipments = equipments, countries=countries, current_time=now.ctime()) elif "add" in request.form: equipment = Equipments(request.form['name'], request.form['manufacturer'], request.form['price'], request.form['country']) add_equipment(app, request, equipment) return redirect(url_for('equipments_page')) elif "delete" in request.form: for line in request.form: if "checkbox" in line: delete_equipment(app, int(line[9:])) return redirect(url_for('equipments_page')) elif 'search' in request.form: equipments = search_equipment(app, request.form['equipment_to_search']) return render_template('equipments_search_page.html', equipments = equipments)
def before_request(): if users.get_current_user(): g.url_logout_text = 'Logout' g.url_logout = users.create_logout_url(url_for('admin.index')) else: g.url_logout_text = 'Login' g.url_logout = users.create_login_url(url_for('sign_in'))
def get_sponsors_page(app): if request.method == 'GET': now = datetime.datetime.now() sponsors = get_all_sponsors(app) clubs = get_club_names(app) return render_template('sponsors.html', sponsors = sponsors, clubs=clubs, current_time=now.ctime()) elif "add" in request.form: sponsor = Sponsors(request.form['name'], request.form['supportedteam'], request.form['budget']) add_sponsor(app, request, sponsor) return redirect(url_for('sponsors_page')) elif "delete" in request.form: for line in request.form: if "checkbox" in line: delete_sponsor(app, int(line[9:])) return redirect(url_for('sponsors_page')) elif 'search' in request.form: sponsors = search_sponsor(app, request.form['sponsor_to_search']) return render_template('sponsors_search_page.html', sponsors = sponsors)
def from_xmlrpc(obj): term = { 'id': obj.id, 'name': obj.name, 'slug': obj.slug, 'description': obj.description, 'count': obj.count, 'taxonomy': { '_meta': { 'links': { 'self': route_to_abs(helpers.url_for(TaxonomyApi.name, id=obj.taxonomy)), }, 'media_type': TaxonomyApi.media_type, 'supports': ['GET'] }, 'name': obj.taxonomy }, '_meta': { 'supports': ['GET', 'PUT', 'DELETE'], 'media_type': TaxonomyTermApi.media_type, 'links': { 'self': route_to_abs(helpers.url_for(TaxonomyTermApi.name, parent_id=obj.taxonomy, id=obj.id)) } } } if obj.parent and int(obj.parent) > 0: term['parent'] = { 'id': obj.parent, 'self': route_to_abs(helpers.url_for(TaxonomyTermApi.name, parent_id=obj.taxonomy, id=obj.parent)) } return term
def register(): ''' Registers the user. :return: ''' if g.user: return redirect(url_for('timeline')) error = None if request.method == 'POST': if not request.form['username']: error = 'You have to enter a username' elif not request.form['email'] or '@' not in request.form['email']: error = 'You have to enter a valid email address.' elif not request.form['password']: error = 'You have to enter a password' elif request.form['password'] != request.form['password2']: error = 'The two passwords do not match' elif get_user_id(request.form['username']) is not None: error = 'The username is alredy taken' else: g.db.execute('''insert into user (username, email, pw_hash) values (?, ?, ?)''', [request.form['username'], request.form['email'], generate_password_hash(request.form['password'])]) g.db.commit() flash('You were successfully registered and can login now') return redirect(url_for('login')) return render_template('register.html', error=error)
def champinfo_page(): cinfos = Champinfo(app.config['dsn']) if request.method == 'GET': now = datetime.datetime.now() clist = cinfos.get_champinfolist() drivers=cinfos.get_drivers() teams=cinfos.get_teams() return render_template('champinfo.html', ChampinfoList = clist, drivers=drivers,teams=teams, current_time = now.ctime()) elif 'champinfos_to_delete' in request.form: ids = request.form.getlist('champinfos_to_delete') for id in ids: cinfos.delete_champinfo(id) return redirect(url_for('champinfo_page')) elif 'champinfos_to_add' in request.form: nyear=request.form['nyear'] ndriv=request.form['ndriv'] nteam=request.form['nteam'] cinfos.add_champinfo(nyear,ndriv,nteam) elif 'champinfos_to_update' in request.form: oyear=request.form['oyear'] nyear=request.form['nyear'] ndriv=request.form['ndriv'] nteam=request.form['nteam'] cinfos.update_champinfo(oyear,nyear,ndriv,nteam) elif 'champinfos_to_search' in request.form: now = datetime.datetime.now() clist = cinfos.search_champinfolist(request.form['name']) return render_template('champinfo.html', ChampinfoList = clist, current_time = now.ctime()) return redirect(url_for('champinfo_page'))
def community_redirect(): return render_template('redirect.html', url=url_for('community_page'))
def coroutines_alias(): return render_template( 'redirect.html', url=url_for('page', page_path='docs/diagnostics/experimental-coroutines'))
def versioned_url_for(endpoint, **values): if 'BUILD_NUMBER' in os.environ and endpoint == 'static': values['build'] = os.environ['BUILD_NUMBER'] return url_for(endpoint, **values) return url_for(endpoint, **values)
def shared_LessonNotes_Announcement_Page(): if request.method == "POST": if 'userSearchButton' in request.form: # if the search button is submitted session['search_username'] = request.form['usernameSearch'] return redirect(url_for('site.SearchUserPage')) formtype = request.form['form-name'] username = current_user.get_username() email = current_user.get_email() if formtype == "SharedLessonNotesAnnouncement": NameOfLessonNote = request.form['InputNameOfSharedLessonNote'] TeacherName = request.form['InputTeacherNameofSharedLessonNote'] LessonName = request.form['InputLessonNameOfShareLessonNote'] LessonCode = request.form['InputLessonCodeOfShareLessonNote'] with dbapi2.connect(current_app.config['dsn']) as connection: cursor = connection.cursor() statement = """SELECT ID FROM USERS WHERE(USERS.USERNAME = %s) AND(USERS.EMAIL = %s)""" cursor.execute(statement, (username, email)) currentuser_id = cursor.fetchone() sharedLessonNotesAd = sharingLessonNotesAnnouncement( NameOfLessonNote, LessonName, LessonCode, TeacherName, currentuser_id) query = """INSERT INTO SHAREDLESSONNOTES(NAMEOFNOTES, LESSONNAME, LESSONCODE,TEACHERNAME,USERID) VALUES (%s,%s,%s,%s,%s)""" cursor.execute( query, (sharedLessonNotesAd.NameOFSharingLessonNote, sharedLessonNotesAd.LessonNameOfSharingLessonNote, sharedLessonNotesAd.LessonCodeOfSharingLessonNote, sharedLessonNotesAd.TeacherNameOFSharingLessonNote, sharedLessonNotesAd.id_ownerOfSharingLessonNote)) connection.commit() return redirect(url_for('site.SharedLessonNotesAnnouncementPage')) elif formtype == "SharedLessonNotesAnnouncementUpdate": with dbapi2.connect(current_app.config['dsn']) as connection: cursor = connection.cursor() # prevented sql injection statement = """SELECT ID FROM USERS WHERE (USERS.USERNAME = %s) AND (USERS.EMAIL = %s)""" cursor.execute(statement, (username, email)) sharingUser_id = cursor.fetchone() sharingLessonNotesid = request.form['sharingLessonNotes-id'] NameOfLessonNote = request.form['InputNameOfSharedLessonNote'] if not NameOfLessonNote: statement = """SELECT NAMEOFNOTES FROM SHAREDLESSONNOTES WHERE SHAREDLESSONNOTES.ID = %s""" cursor.execute(statement, sharingLessonNotesid) NameOfLessonNote = cursor.fetchone() TeacherName = request.form[ 'InputTeacherNameofSharedLessonNote'] if not TeacherName: statement = """SELECT TEACHERNAME FROM SHAREDLESSONNOTES WHERE SHAREDLESSONNOTES.ID = %s""" cursor.execute(statement, sharingLessonNotesid) TeacherName = cursor.fetchone() LessonName = request.form['InputLessonNameOfShareLessonNote'] if not LessonName: statement = """SELECT LESSONNAME FROM SHAREDLESSONNOTES WHERE SHAREDLESSONNOTES.ID = %s""" cursor.execute(statement, sharingLessonNotesid) LessonName = cursor.fetchone() LessonCode = request.form['InputLessonCodeOfShareLessonNote'] if not LessonCode: statement = """SELECT LESSONCODE FROM SHAREDLESSONNOTES WHERE SHAREDLESSONNOTES.ID = %s""" cursor.execute(statement, sharingLessonNotesid) LessonCode = cursor.fetchone() statement = """UPDATE SHAREDLESSONNOTES SET NAMEOFNOTES=%s, LESSONNAME=%s, LESSONCODE=%s, TEACHERNAME=%s, USERID=%s WHERE SHAREDLESSONNOTES.ID=%s""" cursor.execute( statement, (NameOfLessonNote, LessonName, LessonCode, TeacherName, sharingUser_id, sharingLessonNotesid)) connection.commit() return redirect( url_for('site.selected_sharingLessonNotes', id=sharingLessonNotesid)) else: with dbapi2.connect(current_app.config['dsn']) as connection: cursor = connection.cursor() query = """SELECT NAMEOFNOTES,LESSONNAME,LESSONCODE,TEACHERNAME,USERS.NAME,USERS.SURNAME,USERS.EMAIL,FACULTIES.FACULTYNAME,FACULTIES.FACULTYCODE,SHAREDLESSONNOTES.ID FROM SHAREDLESSONNOTES,USERS,FACULTIES WHERE(SHAREDLESSONNOTES.USERID = USERS.ID) AND(USERS.FACULTYID = FACULTIES.ID) """ cursor.execute(query) ALLSharingLessonNotes = cursor.fetchall() return render_template("sharedlessonnotes_announcement.html", ALLSharingLessonNotes=ALLSharingLessonNotes)
def logout(): session.clear() return redirect(url_for('index'))
def files(self): return [{'name': path.basename(filename[1]), 'href': url_for('getFile', connection_id=self.id, file_id=filename[0])} for filename in self.attachments()]
def events_redirect(): return render_template('redirect.html', url=url_for('page', page_path='community/talks'))
def collections_redirect(): return render_template( 'redirect.html', url=url_for('page', page_path='/docs/reference/collections-overview'))
def community_user_groups_redirect(): return render_template( 'redirect.html', url=url_for('page', page_path='user-groups/user-group-list'))
def coroutines_redirect(): return render_template('redirect.html', url=url_for( 'page', page_path='docs/reference/coroutines-overview'))
def page_not_found(error): index_url = url_for('web.index') url = getattr(request, 'path')[len(index_url):] return redirect(index_url + '#' + url)
def delete(id): product = Product.query.get_or_404(id) db.session.delete(product) db.session.commit() flash("Producto eliminado exitosamente.") return redirect(url_for('product.index'))
def href(self): return url_for('connectionsapi0.connectionsapi', instid=self.id)
def connect(connection_id): connection = findConnection(connection_id) return jsonify({'href': url_for('processesapi0.processesapi', instid=connection.connect())})
def disconnect(connection_id): connection = findConnection(connection_id) connection.disconnect() return jsonify({'href': url_for('connectionsapi0.connectionsapi', instid=connection_id)})
def processes(self): return [url_for('processesapi0.processesapi', instid=processUrl.pid) for processUrl in self.processesList]
def connection(self): return url_for('connectionsapi0.connectionsapi', instid=self.connectionId)
def logout(): logout_user() return redirect(url_for('index'))
def href(self): return url_for('processesapi0.processesapi', instid=self.pid)
def attachFile(connection_id): connection = findConnection(connection_id) filename = connection.attachFile(request.files['file']) return jsonify({'href': url_for('getFile', connection_id=connection_id, file_id=hashlib.md5(filename).hexdigest())})
def sign_out(): ''' Sign out ''' session.pop("auth", None) return redirect(url_for("home"))
def image_url(self, filename): with app.app_context(): self.assertRedirect( self.app.get(url_for('res.static', filename=filename)), url_for('static', filename=filename))
def game_friend_page(): if request.method == 'POST': if 'userSearchButton' in request.form: # if the search button is submitted session['search_username'] = request.form['usernameSearch'] return redirect(url_for('site.SearchUserPage')) formtype = request.form['form-name'] username = current_user.get_username() email = current_user.get_email() if formtype == "GameFriend": gameName = request.form['InputGameName'] gameType = request.form['InputGameType'] playerNum = int(request.form['GamePlayerNo']) gameDate = request.form['InputGameDate'] gameLoc = request.form['InputGameLocation'] gameDesc = request.form['GameDescription'] with dbapi2.connect(current_app.config['dsn']) as connection: # to take the current user's name and email cursor1 = connection.cursor() statement = """SELECT ID FROM USERS WHERE (USERS.USERNAME = %s) AND (USERS.EMAIL = %s)""" cursor1.execute(statement, (username, email)) UserId = cursor1.fetchone() UserId = UserId[0] gameAnnounce = GameAnnounce(gameName, gameType, playerNum, gameDate, gameLoc, gameDesc, UserId) # print(type(UserId)) # to insert the new announcement information cursor = connection.cursor() query = """INSERT INTO GAMEANNOUNCE (NAME, TYPE, GAMEDATE, LOCATION, PLAYERNUMBER, DESCRIPTION, USERID) VALUES(%s,%s,%s,%s,%s,%s,%s)""" cursor.execute(query, (gameAnnounce.gameName, gameAnnounce.gameType, gameAnnounce.gameDate, gameAnnounce.gameLoc, gameAnnounce.playerNum, gameAnnounce.gameDesc, gameAnnounce.user_id)) connection.commit() # return render_template('game_friends.html') return redirect(url_for('site.GameFriendPage')) elif formtype == "GameFriendUpdate": with dbapi2.connect(current_app.config['dsn']) as connection: cursor = connection.cursor() # prevented sql injection statement = """SELECT ID FROM USERS WHERE (USERS.USERNAME = %s) AND (USERS.EMAIL = %s)""" cursor.execute(statement, (username, email)) announce_user_id = cursor.fetchone() announceid = request.form['announce-id'] gameName = request.form['InputGameName'] if not gameName: statement = """SELECT NAME FROM GAMEANNOUNCE WHERE GAMEANNOUNCE.ID = %s""" cursor.execute(statement, announceid) gameName = cursor.fetchone() playerNum = request.form['GamePlayerNo'] if not playerNum: statement = """SELECT PLAYERNUMBER FROM GAMEANNOUNCE WHERE GAMEANNOUNCE.ID = %s""" cursor.execute(statement, announceid) playerNum = cursor.fetchone() gameDate = request.form['InputGameDate'] if not gameDate: statement = """SELECT GAMEDATE FROM GAMEANNOUNCE WHERE GAMEANNOUNCE.ID = %s""" cursor.execute(statement, announceid) gameDate = cursor.fetchone() gameLoc = request.form['InputGameLocation'] if not gameLoc: statement = """SELECT LOCATION FROM GAMEANNOUNCE WHERE GAMEANNOUNCE.ID = %s""" cursor.execute(statement, announceid) gameLoc = cursor.fetchone() gameDesc = request.form['GameDescription'] if not gameDesc: statement = """SELECT DESCRIPTION FROM GAMEANNOUNCE WHERE GAMEANNOUNCE.ID = %s""" cursor.execute(statement, announceid) gameDesc = cursor.fetchone() statement = """UPDATE GAMEANNOUNCE SET NAME = %s, PLAYERNUMBER = %s, GAMEDATE = %s, LOCATION = %s, DESCRIPTION = %s, USERID = %s WHERE GAMEANNOUNCE.ID = %s""" cursor.execute(statement, (gameName, playerNum, gameDate, gameLoc, gameDesc, announce_user_id, announceid)) connection.commit() return redirect( url_for('site.SelectedGameAnnounce', announceId=announceid)) else: with dbapi2.connect(current_app.config['dsn']) as connection: cursor = connection.cursor() query = """SELECT GAMEANNOUNCE.NAME, TYPE, GAMEDATE, LOCATION, PLAYERNUMBER, DESCRIPTION, USERS.NAME, USERS.SURNAME, USERS.EMAIL, FACULTIES.FACULTYNAME, FACULTIES.FACULTYCODE, USERS.USERNAME, GAMEANNOUNCE.ID FROM GAMEANNOUNCE, USERS, FACULTIES WHERE (GAMEANNOUNCE.USERID = USERS.ID) AND (USERS.FACULTYID = FACULTIES.ID)""" cursor.execute(query) gameFriendAnnounces = cursor.fetchall() return render_template('game_friends.html', gameFriendAnnounces=gameFriendAnnounces)
def sort(): return redirect(url_for('.home', filter_name=x))
def compatibility_redirect(): return render_template( 'redirect.html', url=url_for( 'page', page_path='/docs/reference/evolution/components-stability'))
def hello(name): if name is 'admin': return redirect(url_for('hello_admin')) else: return redirect(url_for('hello_guest', guest=name))
def login(): queryObj = {"Username": request.form['Username']} query = UserTable.find_one(queryObj) obj = json.loads(json_util.dumps(query)) return redirect(url_for('User', name=obj['Username']))
def delete(): task = request.args.get('task') query = TaskTable.delete_one({"Task": task}) print('Hello this is delete') return redirect(url_for('User', name=session['Username']))
def coroutines_tutor_redirect(): return render_template( 'redirect.html', url=url_for('page', page_path='docs/tutorials/coroutines/coroutines-basic' '-jvm'))
def test_build_media_path(client, app: Flask): with app.app_context(): assert url_for("world.media", path="avatar/default.png", _external=False) == "/media/avatar/default.png"