コード例 #1
0
ファイル: app.py プロジェクト: grace-mao23/Project1_RedDacks
def home():
    if not checkAuth():
        return redirect(url_for('login'))
    # loading dog API
    url = "https://random.dog/woof.json"
    response = urllib.request.urlopen(url)
    response = response.read()
    data = json.loads(response)
    while (data['url'][-1] == '4'):  # mp4s are not displayable
        response = urllib.request.urlopen(url)
        response = response.read()
        data = json.loads(response)
    username = session["currentID"]
    userID = get("users", "userid", "WHERE username = '******'" % username)[0][0]
    r1 = get("searches", "search",
             "WHERE searchNum = 1 AND userid = '%s'" % userID)[0][0]
    r2 = get("searches", "search",
             "WHERE searchNum = 2 AND userid = '%s'" % userID)[0][0]
    r3 = get("searches", "search",
             "WHERE searchNum = 3 AND userid = '%s'" % userID)[0][0]
    r4 = get("searches", "search",
             "WHERE searchNum = 4 AND userid = '%s'" % userID)[0][0]
    r5 = get("searches", "search",
             "WHERE searchNum = 5 AND userid = '%s'" % userID)[0][0]
    return render_template('home.html',
                           dog=data['url'],
                           recent1=r1,
                           recent2=r2,
                           recent3=r3,
                           recent4=r4,
                           recent5=r5)
コード例 #2
0
ファイル: app.py プロジェクト: grace-mao23/Project1_RedDacks
def login():
    #print(session['userID'])
    if checkAuth():
        return redirect(url_for('home'))
    return render_template('login.html',
                           error=session["error"],
                           message=session['message'])
コード例 #3
0
ファイル: app.py プロジェクト: grace-mao23/Project1_RedDacks
def settings():
    #print(session["e1"], session["e2"], session["message"])
    if not checkAuth():
        return redirect(url_for('login'))
    return render_template('settings.html',
                           e1=session["e1"],
                           e2=session["e2"],
                           message=session["message"])
コード例 #4
0
ファイル: app.py プロジェクト: grace-mao23/Project1_RedDacks
def root():
    session["error"] = False
    session["message"] = ""
    session["e1"] = False
    session["e2"] = False
    #print(countries)
    if checkAuth():  #if you've already logged in
        return redirect(url_for('home'))
    return redirect(url_for('login'))
コード例 #5
0
ファイル: app.py プロジェクト: grace-mao23/Project1_RedDacks
def changing():
    session["e1"] = False
    session["e2"] = False
    #print(get("users", "*", ""))
    if not checkAuth():
        return redirect(url_for('login'))
    # no password stuff entered --> change Username
    if (request.args['check_password'] == ''):
        if (request.args['new_password'] != ''
                or request.args['confirm_password'] !=
                ''):  #if other password fields filled out, something's wrong
            session["e2"] = True
            session["message"] = "Necessary Fields Not Filled Out"
            return redirect(url_for('settings'))
        # change Username
        if (request.args['newusername'] == ''
            ):  #if username fields not filled out, something's wrong
            session["e1"] = True
            session["message"] = "Necessary Fields Not Filled Out"
            return redirect(url_for('settings'))
        if (get("users", "username",
                "WHERE username = '******'" % request.args['newusername']) !=
            []):  #username is in database already
            session["e1"] = True
            session["message"] = "Username Already Taken"
            return redirect(url_for('settings'))
        update_user(
            session['currentID'], "username",
            request.args['newusername'])  #updating the database imported
        session["currentID"] = request.args['newusername']
        return render_template('settings.html', changed1=True)
    else:  # password being changed
        if (request.args['new_password'] == ''
                or request.args['confirm_password']
                == ''):  #if password fields not filled out, something's wrong
            session["e2"] = True
            session["message"] = "Necessary Fields Not Filled Out"
            return redirect(url_for('settings'))
        if (request.args['check_password'] != get(
                "users", "hashpassword", "WHERE username = '******'" %
                session['currentID'])[0][0]):  #old password not correct
            session["e2"] = True
            session["message"] = "Incorrect Password"
            return redirect(url_for('settings'))
        if (request.args['new_password'] !=
                request.args['confirm_password']):  #passwords don't match
            session["e2"] = True
            session["message"] = "Passwords Don't Match"
            return redirect(url_for('settings'))
        update_user(session['currentID'], "hashpassword",
                    request.args['new_password'])  #updating the database
        return render_template('settings.html', changed2=True)
コード例 #6
0
ファイル: app.py プロジェクト: grace-mao23/Project1_RedDacks
def fullsearch(category):
    if not checkAuth():
        return redirect(url_for('login'))
    articles = newsapi(session['countrycode'], category)
    newarticles = newyorktimesapi(session['country'], category)
    guardian = guardianapi(session['country'], category)
    #print(guardian)
    #print(newarticles)
    return render_template('results.html',
                           category=category,
                           country=session['country'].capitalize(),
                           articles=articles,
                           newarticles=newarticles,
                           guardian=guardian)
コード例 #7
0
ファイル: app.py プロジェクト: grace-mao23/Project1_RedDacks
def search():
    if not checkAuth():
        return redirect(url_for('login'))
    #blah = get("countries", "code", "WHERE name == '%s'" % request.args['query'])[0][0]
    #print(blah)
    #return "poo"
    #session['countrycode'] = countries[request.args['query']]
    #session['country'] = request.args['query']
    country = comparecountry(request.args['query'].lower(), countries)
    if country == "BOO":
        session["error"] = True
        return redirect(url_for('home'))
    session["error"] = False
    username = session["currentID"]
    #print(username)
    userID = get("users", "userid", "WHERE username = '******'" % username)[0][0]
    #print(userID)
    update_searches(userID, country)
    session['countrycode'] = countries[country]
    session['country'] = country
    return render_template('searchedcountry.html', country=country)
コード例 #8
0
ファイル: app.py プロジェクト: grace-mao23/Project1_RedDacks
def signup():
    if checkAuth():
        return redirect(url_for('home'))
    return render_template('signup.html',
                           error=session["error"],
                           message=session["message"])