def login(): error = None if request.method == 'POST': nickname = request.form.get('nickname') password = request.form.get('password') if nickname != '' and password != '': userId = loginUser(db, nickname, password) if userId: session['id'] = userId session['name'] = nickname return redirect(url_for("index")) else: flash('Nickname or password were wrong!') else: flash('No nickname or password!') return redirect(url_for('login')) else: return render_template("login.html")
def auth_login(): ''' Validate username and password and go to next url. If invalid, go back to login form with error(s). ''' username = request.form.get('username', False) password = request.form.get('password', False) next = request.form.get('next', False) # validate entered email and password userCased = helpers.loginUser(username, password) if userCased: # create session and redirect to next URL next = helpers.makeRelativeUrl(next) helpers.makeSession(g.session, userCased) return redirect(next) # invalid, so show errors return redirect(url_for('login', u=username, n=next, r=1))
import requests import json from helpers import getBids, loginUser, getItem mary = {'username': '******', 'password': '******'} maryToken = loginUser(mary) nick = {'username': '******', 'password': '******'} nickToken = loginUser(nick) # Mary can view her own historical bids response = getBids(30, maryToken) myJson = response.text parsed = json.loads(myJson) print(json.dumps(parsed, indent=4, sort_keys=True)) # Nick can not view mary's historical bids response = getBids(30, nickToken) myJson = response.text parsed = json.loads(myJson) print(json.dumps(parsed, indent=4, sort_keys=True))
import json from helpers import getItem, loginUser, getItem nick = {'username': '******', 'password': '******'} nickToken = loginUser(nick) olga = {'username': '******', 'password': '******'} olgaToken = loginUser(olga) itemId = 48 responseNick = getItem(itemId, nickToken) responseOlga = getItem(itemId, olgaToken) nickJson = responseNick.text nickParsed = json.loads(nickJson) print(json.dumps(nickParsed, indent=4, sort_keys=True)) olgaJson = responseOlga.text olgaParsed = json.loads(olgaJson) print(json.dumps(olgaParsed, indent=4, sort_keys=True))
import requests import json from helpers import loginUser, addBid, addAuctionItem # get tokens mary = {'username': '******', 'password': '******'} maryToken = loginUser(mary) olga = {'username': '******', 'password': '******'} olgaToken = loginUser(olga) nick = {'username': '******', 'password': '******'} nickToken = loginUser(nick) # mary creates item minutesToEnd = 3 maryAddItemResponse = addAuctionItem('new item', 'item description', minutesToEnd, maryToken) maryAddItemId = maryAddItemResponse.json()['id'] # olga bids on item olgaResponse1 = addBid(maryAddItemId, 70, olgaToken) print('olgaResponse1: ') print(olgaResponse1.json()) # nick bids on item nickResponse1 = addBid(maryAddItemId, 71, nickToken) print('nickResponse1: ') print(nickResponse1.json()) # olga bids on item
import requests import json from helpers import loginUser, addAuthor, addAuthorBulk, getAuthorSet serverUrl = 'http://127.0.0.1:8000/' # serverUrl = 'https://blooming-mountain-86004.herokuapp.com/' email = '*****@*****.**' password = '******' json_file = '/home/neil/Code/library/locallibrary/data/Karmelako_liburutegia.json' authorSet = getAuthorSet(json_file) authList = list() for authTup in authorSet: authDict = dict() authDict['first_name'] = authTup[0] authDict['last_name'] = authTup[1] authList.append(authDict) token = loginUser({'email': email, 'password': password}, serverUrl) response = addAuthorBulk(authList, serverUrl, token) print(response.json())
from helpers import loginUser, addAuctionItem olga = {'username': '******', 'password': '******'} olgaToken = loginUser(olga) minutesToEnd = 1 response = addAuctionItem('Olgas Item', 'olga adds an item', minutesToEnd, olgaToken) print(response.json())
import requests import json from helpers import addBid, loginUser user = {'username': '******', 'password': '******'} token = loginUser(user) maryAuctionId = 48 amount = 56 response = addBid(maryAuctionId, amount, token) print(response.json())
import json from helpers import getAllAvailableItems, loginUser, getItem nick = {'username': '******', 'password': '******'} nickToken = loginUser(nick) response = getAllAvailableItems(nickToken) myJson = response.text parsed = json.loads(myJson) print(json.dumps(parsed, indent=4, sort_keys=True))
import requests import json from helpers import loginUser, addAuctionItem from datetime import datetime, timedelta mary = {'username': '******', 'password': '******'} maryToken = loginUser(mary) minutesToEnd = 10 response = addAuctionItem('Marys Item', 'mary adds an item', minutesToEnd, maryToken) print(response.json())