Пример #1
0
    def process_login():

        username = bottle.request.forms.get("username")
        password = bottle.request.forms.get("password")

        print "user submitted ", username, "pass ", password

        user_record = users.validate_login(username, password)
        if user_record:
            # username is stored in the user collection in the _id key
            session_id = sessions.start_session(user_record['_id'])

            if session_id is None:
                bottle.redirect("/internal_error")

            cookie = session_id

            # Warning, if you are running into a problem whereby the cookie being set here is
            # not getting set on the redirect, you are probably using the experimental version of bottle (.12).
            # revert to .11 to solve the problem.
            bottle.response.set_cookie("session", cookie)

            bottle.redirect("/welcome")

        else:
            return bottle.template("login",
                                   dict(username=cgi.escape(username), password="",
                                        login_error="Invalid Login"))
Пример #2
0
    def process_login():

        username = bottle.request.forms.get("username")
        password = bottle.request.forms.get("password")

        print "user submitted ", username, "pass ", password

        user_record = users.validate_login(username, password)
        if user_record:
            # username is stored in the user collection in the _id key
            session_id = sessions.start_session(user_record['_id'])

            if session_id is None:
                bottle.redirect("/internal_error")

            cookie = session_id

            # Warning, if you are running into a problem whereby the cookie being set here is
            # not getting set on the redirect, you are probably using the experimental version of bottle (.12).
            # revert to .11 to solve the problem.
            bottle.response.set_cookie("session", cookie)

            bottle.redirect("/welcome")

        else:
            return bottle.template(
                "login",
                dict(username=cgi.escape(username),
                     password="",
                     login_error="Invalid Login"))
Пример #3
0
def change_options():
    email = get_email_from_session()
    default_action = request.forms.get('default_action')
    logger.info("changing default action to: " + default_action)
    users[email].set_default_action(default_action)
    curr_page = request.forms.get('curr_page')
    redirect(curr_page)
Пример #4
0
def oauth_submit():
    # Get the oauth_key from the page form
    oauth_key = request.forms.get('oauth_key')
    try:
        credentials = oauth2_flow.step2_exchange(oauth_key)
    except Exception as e:
        return "Error with login: %s" % e
    else:
        # Get the user's email and add it to the session
        email = get_email(credentials.access_token)
        # Store the oauth credentials
        oauth_path = DirInfo.get_oauth_file_path(email)
        util.make_sure_path_exists(os.path.dirname(oauth_path))
        storage = oauth2client.file.Storage(oauth_path)
        storage.put(credentials)

        # Create the user instance and have it login/initialize
        user = User(email, DirInfo.BaseAppDataDir)
        users[email] = user
        if not user.init(credentials):
            return "Error with login, incorrect code?"
        else:
            global logged_in
            logged_in = True
            session = get_session()
            session["email"] = email
            redirect("/main")
Пример #5
0
    def post_new_comment():
        name = bottle.request.forms.get("commentName")
        email = bottle.request.forms.get("commentEmail")
        body = bottle.request.forms.get("commentBody")
        permalink = bottle.request.forms.get("permalink")

        post = posts.get_post_by_permalink(permalink)
        cookie = bottle.request.get_cookie("session")

        username = sessions.get_username(cookie)

        # if post not found, redirect to post not found error
        if post is None:
            bottle.redirect("/post_not_found")
            return

        # if values not good, redirect to view with errors

        if name == "" or body == "":
            # user did not fill in enough information

            # init comment for web form
            comment = {'name': name, 'email': email, 'body': body}

            errors = "Post must contain your name and an actual comment."
            return bottle.template("entry_template", dict(post=post, username=username, errors=errors, comment=comment))

        else:

            # it all looks good, insert the comment into the blog post and redirect back to the post viewer
            posts.add_comment(permalink, name, email, body)

            bottle.redirect("/post/" + permalink)
Пример #6
0
    def post_newpost():
        title = bottle.request.forms.get("subject")
        post = bottle.request.forms.get("body")
        tags = bottle.request.forms.get("tags")

        cookie = bottle.request.get_cookie("session")
        username = sessions.get_username(cookie)  # see if user is logged in
        if username is None:
            bottle.redirect("/login")

        if title == "" or post == "":
            errors = "Post must contain a title and blog entry"
            return bottle.template("newpost_template", dict(subject=cgi.escape(title, quote=True), username=username,
                                                            body=cgi.escape(post, quote=True), tags=tags, errors=errors))

        # extract tags
        tags = cgi.escape(tags)
        tags_array = extract_tags(tags)

        # looks like a good entry, insert it escaped
        escaped_post = cgi.escape(post, quote=True)

        # substitute some <p> for the paragraph breaks
        newline = re.compile('\r?\n')
        formatted_post = newline.sub("<p>", escaped_post)

        permalink = posts.insert_entry(title, formatted_post, tags_array, username)

        # now bottle.redirect to the blog permalink
        bottle.redirect("/post/" + permalink)
Пример #7
0
def remove_watch_path():
    email = get_email_from_session()
    user = users[email]
    curr_page = request.forms.get('curr_page')
    path_strs = ""
    for path in request.forms.getlist('watchpaths'):
        user.remove_watch_path(path)
    redirect(curr_page)
Пример #8
0
    def get_newpost():

        cookie = bottle.request.get_cookie("session")
        username = sessions.get_username(cookie)  # see if user is logged in
        if username is None:
            bottle.redirect("/login")

        return bottle.template("newpost_template", dict(subject="", body="", errors="", tags="", username=username))
Пример #9
0
    def process_logout():

        cookie = bottle.request.get_cookie("session")

        sessions.end_session(cookie)

        bottle.response.set_cookie("session", "")

        bottle.redirect("/signup")
Пример #10
0
    def process_logout():

        cookie = bottle.request.get_cookie("session")

        sessions.end_session(cookie)

        bottle.response.set_cookie("session", "")

        bottle.redirect("/signup")
Пример #11
0
    def get_newpost():

        cookie = bottle.request.get_cookie("session")
        username = sessions.get_username(cookie)  # see if user is logged in
        if username is None:
            bottle.redirect("/login")

        return bottle.template(
            "newpost_template",
            dict(subject="", body="", errors="", tags="", username=username))
Пример #12
0
    def present_welcome():
        # check for a cookie, if present, then extract value

        cookie = bottle.request.get_cookie("session")
        username = sessions.get_username(cookie)  # see if user is logged in
        if username is None:
            print "welcome: can't identify user...redirecting to signup"
            bottle.redirect("/signup")

        return bottle.template("welcome", {'username': username})
Пример #13
0
    def present_welcome():
        # check for a cookie, if present, then extract value

        cookie = bottle.request.get_cookie("session")
        username = sessions.get_username(cookie)  # see if user is logged in
        if username is None:
            print "welcome: can't identify user...redirecting to signup"
            bottle.redirect("/signup")

        return bottle.template("welcome", {'username': username})
Пример #14
0
def process_login():

    username = bottle.request.forms.get("username")
    password = bottle.request.forms.get("password")

    user = "******"
    passwrd = "mypassword"

    if username == user and password == passwrd:
        bottle.redirect("/welcome")
    else:
        print "Invalid username or password"
        return bottle.template("login", dict(username=cgi.escape(username), password="",
                                        login_error="Invalid Login"))
Пример #15
0
def login():
    session = get_session()
    # If we haven't checked yet (i.e. when first starting up), check for any users that we can log in
    #  and log them in automtically.  We'll pick one at random to be the starting 'active' user
    if not "tokens_checked" in session:
        logger.info("Checking for existing tokens")
        check_for_existing_tokens()
        session["tokens_checked"] = True
    # Check if we've got a user logged in already at this point.  If so, redirect to the main page
    if logged_in:
        logger.info("User %s already logged in" % get_email_from_session())
        redirect("/main")
    # If no one is logged in, present the change to log in
    logger.info("No users logged in, showing oauth screen")
    oauth_uri = oauth2_flow.step1_get_authorize_url()
    return template('login', session_status=get_session_data(), oauth_uri=oauth_uri)
Пример #16
0
def logout():
    email = get_email_from_session()
    logger.debug("logging out, email: %s" % email)
    users[email].logout()
    del users[email]

    try:
        os.remove(DirInfo.get_oauth_file_path(email))
    except OSError as e:
        logger.info("Error logging out: %s" % e)
    global logged_in
    logged_in = False
    # Prompt a re-scan for any other logged in users
    session = get_session()
    session.pop("tokens_checked", None)
    redirect("/")
Пример #17
0
def blog_home():
    
    return bottle.template('signup', dict(username="", password="",
                                    password_error="",
                                    email="", username_error="", email_error="",
                                    verify_error=""))
    
    email = bottle.request.forms.get("email")
    username = bottle.request.forms.get("username")
    password = bottle.request.forms.get("password")
    verify = bottle.request.forms.get("verify")

    if username is None and password is None:
        print "You need to fill the form"
    else:
        bottle.redirect('/welcome')
Пример #18
0
    def show_post(permalink="notfound"):

        cookie = bottle.request.get_cookie("session")

        username = sessions.get_username(cookie)
        permalink = cgi.escape(permalink)

        print "about to query on permalink = ", permalink
        post = posts.get_post_by_permalink(permalink)

        if post is None:
            bottle.redirect("/post_not_found")

        # init comment form fields for additional comment
        comment = {'name': "", 'body': "", 'email': ""}

        return bottle.template("entry_template", dict(post=post, username=username, errors="", comment=comment))
Пример #19
0
def process_login():

    username = bottle.request.forms.get("username")
    password = bottle.request.forms.get("password")

    user = "******"
    passwrd = "mypassword"

    if username == user and password == passwrd:
        bottle.redirect("/welcome")
    else:
        print "Invalid username or password"
        return bottle.template(
            "login",
            dict(username=cgi.escape(username),
                 password="",
                 login_error="Invalid Login"))
Пример #20
0
    def show_post(permalink="notfound"):

        cookie = bottle.request.get_cookie("session")

        username = sessions.get_username(cookie)
        permalink = cgi.escape(permalink)

        print "about to query on permalink = ", permalink
        post = posts.get_post_by_permalink(permalink)

        if post is None:
            bottle.redirect("/post_not_found")

        # init comment form fields for additional comment
        comment = {'name': "", 'body': "", 'email': ""}

        return bottle.template(
            "entry_template",
            dict(post=post, username=username, errors="", comment=comment))
Пример #21
0
def blog_home():

    return bottle.template(
        'signup',
        dict(username="",
             password="",
             password_error="",
             email="",
             username_error="",
             email_error="",
             verify_error=""))

    email = bottle.request.forms.get("email")
    username = bottle.request.forms.get("username")
    password = bottle.request.forms.get("password")
    verify = bottle.request.forms.get("verify")

    if username is None and password is None:
        print "You need to fill the form"
    else:
        bottle.redirect('/welcome')
Пример #22
0
def index(name=TITLE):
    ''' standard opening page (with settings from cookie or default) '''
    if 'REMOTE_ADDR' in bottle.request.environ:
        ip = bottle.request.environ.get('REMOTE_ADDR')
    else:
        ip = None
    tm = time.perf_counter()
    logger.info("===== index request:%s from %s=====" %
                (bottle.request.body.read(), ip))

    if bottle.request.query.title:
        bottle.redirect('/menu')

    srcs = list(dbStore.sources())
    src = srcs[0]
    quantIds = []
    cookie = bottle.request.get_cookie(COOKIE)
    if cookie:
        logger.info('using cookie :"%s"' % cookie)
        cookie = list(json.loads(cookie))
        cookie.extend([None, None, None])
        src, selqs, ndays = tuple(cookie[:3])
    else:
        selqs = typnames(dbStore.quantities(
            [src], prop=2))[:2]  # quantity typs that are in src
        ndays = 4
        bottle.response.set_cookie(COOKIE,
                                   json.dumps((src, selqs, ndays)),
                                   max_age=AN1)
    logger.info("src:%s,selqs:%s len:%d" % (src, selqs, len(selqs)))
    if len(selqs) == 0 or len(selqs) > 15:
        selqs = ['temperature']
    #page = dict(menitms=buildMenu(srcs,src,typnames(dbStore.quantities(prop=2)),selqs,ndays))
    #page = redraw(src,selqs,julianday())
    jdtill = julianday()
    page = redraw(src, selqs, jdtill, ndays)
    page.update(dict(title=name, footer=__copyright__)
                )  #jdtill=julianday(),ndays=ndays,grQuantIds=quantIds))
    logger.debug("index page:(t:%s)\n%s\n" % (time.perf_counter() - tm, page))
    return bottle.template(TPL, page)
Пример #23
0
    def post_new_comment():
        name = bottle.request.forms.get("commentName")
        email = bottle.request.forms.get("commentEmail")
        body = bottle.request.forms.get("commentBody")
        permalink = bottle.request.forms.get("permalink")

        post = posts.get_post_by_permalink(permalink)
        cookie = bottle.request.get_cookie("session")

        username = sessions.get_username(cookie)

        # if post not found, redirect to post not found error
        if post is None:
            bottle.redirect("/post_not_found")
            return

        # if values not good, redirect to view with errors

        if name == "" or body == "":
            # user did not fill in enough information

            # init comment for web form
            comment = {'name': name, 'email': email, 'body': body}

            errors = "Post must contain your name and an actual comment."
            return bottle.template(
                "entry_template",
                dict(post=post,
                     username=username,
                     errors=errors,
                     comment=comment))

        else:

            # it all looks good, insert the comment into the blog post and redirect back to the post viewer
            posts.add_comment(permalink, name, email, body)

            bottle.redirect("/post/" + permalink)
Пример #24
0
    def process_signup():

        email = bottle.request.forms.get("email")
        username = bottle.request.forms.get("username")
        password = bottle.request.forms.get("password")
        verify = bottle.request.forms.get("verify")

        # set these up in case we have an error case
        errors = {'username': cgi.escape(username), 'email': cgi.escape(email)}
        if validate_signup(username, password, verify, email, errors):

            if not users.add_user(username, password, email):
                # this was a duplicate
                errors['username_error'] = "Username already in use. Please choose another"
                return bottle.template("signup", errors)

            session_id = sessions.start_session(username)
            print session_id
            bottle.response.set_cookie("session", session_id)
            bottle.redirect("/welcome")
        else:
            print "user did not validate"
            return bottle.template("signup", errors)
Пример #25
0
    def process_signup():

        email = bottle.request.forms.get("email")
        username = bottle.request.forms.get("username")
        password = bottle.request.forms.get("password")
        verify = bottle.request.forms.get("verify")

        # set these up in case we have an error case
        errors = {'username': cgi.escape(username), 'email': cgi.escape(email)}
        if validate_signup(username, password, verify, email, errors):

            if not users.add_user(username, password, email):
                # this was a duplicate
                errors[
                    'username_error'] = "Username already in use. Please choose another"
                return bottle.template("signup", errors)

            session_id = sessions.start_session(username)
            print session_id
            bottle.response.set_cookie("session", session_id)
            bottle.redirect("/welcome")
        else:
            print "user did not validate"
            return bottle.template("signup", errors)
Пример #26
0
    def post_newpost():
        title = bottle.request.forms.get("subject")
        post = bottle.request.forms.get("body")
        tags = bottle.request.forms.get("tags")

        cookie = bottle.request.get_cookie("session")
        username = sessions.get_username(cookie)  # see if user is logged in
        if username is None:
            bottle.redirect("/login")

        if title == "" or post == "":
            errors = "Post must contain a title and blog entry"
            return bottle.template(
                "newpost_template",
                dict(subject=cgi.escape(title, quote=True),
                     username=username,
                     body=cgi.escape(post, quote=True),
                     tags=tags,
                     errors=errors))

        # extract tags
        tags = cgi.escape(tags)
        tags_array = extract_tags(tags)

        # looks like a good entry, insert it escaped
        escaped_post = cgi.escape(post, quote=True)

        # substitute some <p> for the paragraph breaks
        newline = re.compile('\r?\n')
        formatted_post = newline.sub("<p>", escaped_post)

        permalink = posts.insert_entry(title, formatted_post, tags_array,
                                       username)

        # now bottle.redirect to the blog permalink
        bottle.redirect("/post/" + permalink)
Пример #27
0
def root():
    redirect("/main")
Пример #28
0
def add_account():
    global logged_in
    logged_in = False
    redirect('/login')
Пример #29
0
def switch_account(new_account):
    logger.debug("Switching to account %s" % new_account)
    session = get_session()
    session["email"] = new_account
    redirect("/main")
Пример #30
0
def sync():
    email = get_email_from_session()
    user = users[email]
    user.sync_library()
    #thread.start_new_thread(user.scan_existing_files, ())
    redirect('/status')
Пример #31
0
def upload_scanned():
    email = get_email_from_session()
    user = users[email]
    thread.start_new_thread(user.upload_scanned, ())
    redirect('/status')
Пример #32
0
def add_watch_path():
    email = get_email_from_session()
    path = request.forms.get('path')
    curr_page = request.forms.get('curr_page')
    users[email].add_watch_path(path)
    redirect(curr_page)
Пример #33
0
 def check_logged_in(**kwargs):
     if not logged_in:
         redirect('/login')
     else:
         return fn(**kwargs)
Пример #34
0
def wrong():
    redirect("/student")