def login(request, **kwargs): page = Page() try: user = request.form['username'] pwd = request.form['password'] print "*****%s******" % auth(user, pwd) authorized = auth(user, pwd) except KeyError: return respond(page.render(Login('You must be logged in to do that'))) if authorized: user_login(authorized) return questions(request, **kwargs) else: content = Login('Please try again') return respond(page.render(content))
def test_main_page_with_cookies(): """Make get request to API service main URL after getting auth cookies""" cookie_data = auth() response = main_page(cookie_data) assert response.status_code == 200, "Starting page crashes if user has auth cookie" assert 'Hello World' in response.text
def test_auth_positive_scenario(): """Check getting auth cookie after entering valid username and password""" cookie_data = auth() assert len(cookie_data) > 0, "Auth cookies are missing!" assert len(cookie_data['my_cookie']) != 0, 'Value of cookie is missing in the dictionary!' assert 'my_cookie' in cookie_data.keys(), 'Key is missing in the dictionary!'
def remove_from_group(self, email): mail = email scope = 'https://www.googleapis.com/auth/admin.directory.members' credentials = utils.auth(scope) http_auth = credentials.authorize(httplib2.Http()) service = build('admin', 'directory_v1', http=http_auth) create = service.members().delete(groupKey=mail, memberKey=self.email) return create.execute()
def _make_mailing_list(self): scope = 'https://www.googleapis.com/auth/admin.directory.group' post_data = { 'email': self.email, 'name': self.name } credentials = utils.auth(scope) http_auth = credentials.authorize(httplib2.Http()) service = build('admin', 'directory_v1', http=http_auth) create = service.groups().insert(body=post_data) return create.exexute()
def test_validate_uuid4(): """Check format of auth cookies. """ cookie_data = auth() uuid_string = cookie_data['my_cookie'] response = validate_uuid4(uuid_string) assert response, "Service uses incorrect format of auth cookie !" assert cookie_data['my_cookie'].count('-') == 4,"Service uses incorrect format of auth cookie !" assert len(cookie_data['my_cookie']) > 0, "Service uses incorrect format of auth cookie ! "
def add_to_group(self, email): mail = email scope = 'https://www.googleapis.com/auth/admin.directory.members' post_data = { 'email': self.email, 'role': 'MEMBER' } credentials = utils.auth(scope) http_auth = credentials.authorize(httplib2.Http()) service = build('admin', 'directory_v1', http=http_auth) create = service.members().insert(groupKey=mail, body=post_data) return create.execute()
def register(): if request.method=="GET": return render_template("register.html") else: button = request.form['button'] if button == "Submit": username = request.form['username'].encode ('ascii',"ignore") password = request.form['password'].encode ('ascii',"ignore") if not utils.auth(username,password,db.login): utils.addUser(username,password,db.login) return redirect("/login") else: return "You already have an account"
def login(r=None): if request.method == "GET": # What people see when they click "Login" if 'user' in session and session['user']: return redirect("/home") return render_template("login.html", r=r) else: form = request.form username = form['username'] or "" password = form['password'] or "" if utils.auth(username, password): session['user'] = username return 'success' return 'fail'
def login(): if request.method == "POST": username = request.form["username"] password = request.form["password"] userid = utils.auth(username, password) if userid != -1: session['logged_in'] = True session['userid'] = userid return redirect(url_for('home')) else: return render_template("login.html", err="Incorrect password or username") else: return render_template("login.html")
def login(): if request.method=="GET": return render_template("login.html") else: button = request.form['button'] if button == 'Submit': username = request.form['username'].encode ('ascii',"ignore") password = request.form['password'].encode ('ascii',"ignore") if utils.auth(username,password,db.login): print "logged in!" session['username'] = username if 'oldPage' in session: return redirect (session['oldPage']) else: return "You have logged in" else: return redirect ("/login") print 'login attempt failed. Try again.'
def login(): # already authenticated user if session.get('login'): return redirect('/') # user which tries to login if request.method == 'POST': login = request.values.get('login') password = request.values.get('password') user = utils.auth(bcrypt, login, password) if user: session['login'] = user.login session['is_admin'] = user.is_admin return redirect('/') else: flash('Wrong login or password') return render_template('login.html') elif request.method == 'GET': return render_template('login.html')
def main(): """ This file should not be modified. This should be executed without throwing any exceptions. To do this, you must complement the DogHouse class found in the models.py file """ # get credentials email = input('What\'s is your email? ') password = getpass('What\'s is your password? ') credentials = { 'email': email, 'password': password, } # get token token = auth(**credentials) # create dog house and pull data from api dog_house = DogHouse() dog_house.get_data(token=token) # results total_breeds = dog_house.get_total_breeds() total_dogs = dog_house.get_total_dogs() common_breed = dog_house.get_common_breed() common_dog_name = dog_house.get_common_dog_name() # print requested data print('Total breeds: {}'.format(total_breeds)) print('Total dogs: {}'.format(total_dogs)) print('Most common breed name: {}'.format(common_breed)) print('Most common dog name: {}'.format(common_dog_name)) data = { 'total_breeds': total_breeds, 'total_dogs': total_dogs, 'common_breed': common_breed.name, 'common_dog_name': common_dog_name, } dog_house.send_data(data=data, token=token)
def authorize(): client_id, _ = auth() config_content = config() authorize_url = "https://accounts.spotify.com/authorize/" params = { "client_id": client_id, "response_type": "code", "redirect_uri": config_content["callback_url"], "state": hashlib.sha256( config_content["state_msg"].encode('utf-8')).hexdigest(), "scope": config_content["scope"] } response = requests.get(authorize_url, params=params) return redirect(response.url)
def get_loanlisting(self, email, password): login_url = 'https://www.lendingclub.com/account/login.action' opener = auth(login_url, email, password) print opener.get(self.consolidation())
#!/usr/bin/env python import utils import json endpoint = 'https://ord.autoscale.api.rackspacecloud.com/v1.0/%s/%s' auth_data = utils.auth('samsonite', '07f2ad0df034b776570fe77853159920', servicename='cloudServersOpenStack', region='ord') def findservers(serv): '''Returns a server name when given a server uuid.''' resp = utils.get('%s/servers/%s' % (auth_data['uri'], serv), auth_data['token']) if resp.status_code != 404: return resp.json['server']['name'] else: return None def get_groups(): '''List out current scaling groups.''' resp = utils.get(endpoint % (auth_data['id'], 'groups'), auth_data['token']).json groups = resp['groups'] for group in groups: utils.printvtable([('Group ID', group['id']), ('Desired Capacity', group['desiredCapacity']), ('Pending Capacity', group['pendingCapacity']), ('Active Capacity', group['activeCapacity']), ('Active Nodes', utils.string_a_list( [findservers(i) for i in