示例#1
0
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 home(username=""):
    if not username and "user" not in session:
        return redirect(url_for("login"))
    if "user" in session and not username:
        username = session["user"]        
        
    if request.method == "GET":
        os.system("mkdir ./static/uploads/"+username)
        print os.path.exists("./static/uploads/"+username+"/new.png") 
        print "username is ",username
        if os.path.isfile("./static/uploads/"+username+"/new.png") != True:
            os.system("cp ./static/new.png ./static/uploads/"+username+"/")
        #print "USERNAME: "******"GOT INFO FROM DB IN HOME: ", info
        try:
            pages = info["folios"]
            projects = info["projects"]
        except: #fails if info is a string error
            #print "USER DOES NOT EXIST ERROR"
            return redirect(url_for("login",anerror=info))
        return render_template("setup.html",username=username,pages=pages
                               ,projects=projects)

    elif request.method == "POST":
        username = str(request.form['uzernaem'])
        uploaded_files = request.files.getlist('file[]')
        os.system("mkdir ./static/uploads/" + username)
        os.system("rm ./static/new.png")
        for fiel in uploaded_files:
            if fiel and allowed_file(fiel.filename):
                filename = secure_filename(fiel.filename)
                print "file name about to be made"
                fiel.save(os.path.join(app.config['UPLOAD_FOLDER']+'/'+username+'/'+ filename))        
                q = "mv ./static/uploads/"+username+"/"+filename+" ./static/uploads/"+username+"/new.png"
                
                print "command that isn't working: " + q
                os.system(q)
                """
        info = db.getUserInfo(username)
        try: 
            pages = info['folios']
            projects = info['projects']
        except:
            return redirect(url_for("login", anerror=info))
        return render_template("setup.html", username=username, pages=pages, projects=projects) 
        """
        
        return redirect("/"+username+"/")
示例#3
0
def getUserInfo():
    username = request.args.get("username","")
    if not username:
        username = session["user"]
    return json.dumps(db.getUserInfo(username))
示例#4
0
def getUserInfo():
    userIdHash = hash(str(request.remote_addr))
    userInfo = db.getUserInfo(userIdHash)
    if (userInfo is None):
        userInfo = db.createUser(userIdHash)
    return jsonify(userInfo)