コード例 #1
0
ファイル: app.py プロジェクト: stuycs-softdev-2012-2013/folio
def login():
    if request.method=='GET':
        if "user" in session:
            username = session["user"]
            return redirect(url_for("home",username=username))
        return render_template("login.html")
    else: 
        if "user" in session:
                return "we have issues right now." #aka this is not a thing

        button = request.form["button"]
        if button == "Login":
            password = request.form["password"]
            username = request.form["login"]
            
            #check pass
            res = db.checkPass(username,password)
            if res != True: #res is false or user does not exist
                error = res
                if res == False: 
                    error = "Incorrect Password"
                return render_template("login.html",anerror=error)
            
            #if all goes well
            session["user"] = username
            info = db.getUserInfo(username)
            #print "RESULT IN LOGIN: "******"folios"]
            except: #fails if info is a string error
                print "ERROR IN LOGIN/DB"
                return render_template("login.html",anerror=info)
            
            return redirect(url_for("home",username=username,pages=pages)) 
        
        else: #if button == "Create my Folio!"
            name = request.form['first_name'] + " " + request.form['last_name']
            email = request.form['new_email']
            password = request.form['new_password']
            #res will be true or "user already exists"
            res = db.addUser(email,password,name)

            if res != True:
                return render_template("login.html",anerror=res)

            username = email
            pages = ["about"] #what all new users have
            projects = []
            return redirect(url_for("home",username=username,pages=pages
                                    ,projects=projects))
コード例 #2
0
def login():
    if request.method == "GET":
        if "user" in session:
            return redirect(url_for("search"))
        return render_template("login.html")
    else:
        button = request.form["button"]
        if button == "login":
            username = request.form["usernameLogin"]
            password = request.form["passwordLogin"]
            res = 0
            if username and password:
                 res = db.checkPass(username,password)
            if res == 1:
                session["user"] = username
                return redirect(url_for("search"))
            else:
                error = ""
                if res == 0:
                    error = "user does not exist"
                elif res == 2:
                    error = "incorrect password"
                return render_template("login.html",error=error)
        elif button == "register":
            username = request.form["usernameReg"]
            password = request.form["passwordReg"]
            res = 0
            if username and password:
                res = db.addUser(username,password)
            if res == 1:
                session["user"] = username
                return redirect(url_for("search"))
            else:
                error = ""
                if res == 0:
                    error = "user already exists"
                return render_template("login.html",error=error)