def sso_login(): # retrieves the various parameters provided by the # caller post operation to be used in the construction # of the response and security validations id = quorum.get_field("id") timestamp = quorum.get_field("timestamp") token = quorum.get_field("token") nav_data = quorum.get_field("nav-data") # runs the sso login for the provided arguments and retrieves # the account that has just been logged in account = models.Account.sso_login(id, timestamp, token, nav_data) # retrieves the contents to be use in the navigation bar for the # heroku session navbar_h = get_navbar_h() # updates the current user (name) in session with # the username that has just be accepted in the login flask.session["username"] = account.username flask.session["tokens"] = account.tokens flask.session["instance_id"] = account.instance_id flask.session["nav_data"] = navbar_h # makes the current session permanent this will allow # the session to persist along multiple browser initialization flask.session.permanent = True # creates a new redirect request and uses it to create # the response object that is set with the cookie value # to be used by heroku navigation bar redirect = flask.redirect(flask.url_for("list_servers")) response = flask.make_response(redirect) response.set_cookie("heroku-nav-data", value=nav_data) return response
def login(): username = quorum.get_field("username") password = quorum.get_field("password") try: account = models.Account.login(username, password) except quorum.OperationalError as error: return flask.render_template( "signin.html.tpl", username = username, error = error.message ) # updates the current user (name) in session with # the username that has just be accepted in the login flask.session["username"] = account.username flask.session["tokens"] = account.tokens flask.session["instance_id"] = account.instance_id flask.session["nav_data"] = None # makes the current session permanent this will allow # the session to persist along multiple browser initialization flask.session.permanent = True return flask.redirect( flask.url_for("index") )
def logout(): if "username" in flask.session: del flask.session["username"] if "tokens" in flask.session: del flask.session["tokens"] if "instance_id" in flask.session: del flask.session["instance_id"] if "nav_data" in flask.session: del flask.session["nav_data"] return flask.redirect( flask.url_for("signin") )
def create_server(): # creates the new server, using the provided arguments and # then saves it into the data source, all the validations # should be ran upon the save operation server = models.Server.new() try: server.save() except quorum.ValidationError as error: return flask.render_template( "server/new.html.tpl", link = "servers", sub_link = "create", server = error.model, errors = error.errors ) # redirects the user to the show page of the server that # was just created return flask.redirect( flask.url_for("show_server", name = server.name) )
def create_contact(): # creates the new contact, using the provided arguments and # then saves it into the data source, all the validations # should be ran upon the save operation contact = models.Contact.new() try: contact.save() except quorum.ValidationError as error: return flask.render_template( "contact/new.html.tpl", link = "contacts", sub_link = "create", contact = error.model, errors = error.errors ) # redirects the user to the show page of the contact that # was just created return flask.redirect( flask.url_for("show_contact", id = contact.id) )
def create_account(): # creates the new account, using the provided arguments and # then saves it into the data source, all the validations # should be ran upon the save operation account = models.Account.new() try: account.save() except quorum.ValidationError as error: return flask.render_template( "account/new.html.tpl", link = "accounts", sub_link = "create", account = error.model, errors = error.errors ) # redirects the user to the pending page, indicating that # the account is not yet activated and is pending the email # confirmation action return flask.redirect( flask.url_for("pending", username = account.username) )
def update_account(username): # finds the current account and applies the provided # arguments and then saves it into the data source, # all the validations should be ran upon the save operation account = models.Account.get(username = username) account.apply() try: account.save() except quorum.ValidationError as error: return flask.render_template( "account/edit.html.tpl", link = "accounts", sub_link = "edit", account = error.model, errors = error.errors ) # redirects the user to the show page of the account that # was just updated return flask.redirect( flask.url_for("show_account", username = username) )
def update_contact(id): # finds the current contact and applies the provided # arguments and then saves it into the data source, # all the validations should be ran upon the save operation contact = models.Contact.get_i(id = id) contact.apply() try: contact.save() except quorum.ValidationError as error: return flask.render_template( "contact/edit.html.tpl", link = "contacts", sub_link = "edit", server = error.model, errors = error.errors ) # redirects the user to the show page of the contact that # was just updated return flask.redirect( flask.url_for("show_contact", id = id) )
def update_server(name): # finds the current server and applies the provided # arguments and then saves it into the data source, # all the validations should be ran upon the save operation server = models.Server.get_i(name = name) server.apply() try: server.save() except quorum.ValidationError as error: return flask.render_template( "server/edit.html.tpl", link = "servers", sub_link = "edit", server = error.model, errors = error.errors ) # redirects the user to the show page of the server that # was just updated return flask.redirect( flask.url_for("show_server", name = name) )
def sso_login(): # retrieves the various parameters provided by the # caller post operation to be used in the construction # of the response and security validations id = quorum.get_field("id") timestamp = quorum.get_field("timestamp") token = quorum.get_field("token") nav_data = quorum.get_field("nav-data") # runs the sso login for the provided arguments and retrieves # the account that has just been logged in account = models.Account.sso_login(id, timestamp, token, nav_data) # retrieves the contents to be use in the navigation bar for the # heroku session navbar_h = get_navbar_h() # updates the current user (name) in session with # the username that has just be accepted in the login flask.session["username"] = account.username flask.session["tokens"] = account.tokens flask.session["instance_id"] = account.instance_id flask.session["nav_data"] = navbar_h # makes the current session permanent this will allow # the session to persist along multiple browser initialization flask.session.permanent = True # creates a new redirect request and uses it to create # the response object that is set with the cookie value # to be used by heroku navigation bar redirect = flask.redirect( flask.url_for("list_servers") ) response = flask.make_response(redirect) response.set_cookie("heroku-nav-data", value = nav_data) return response
def delete_account(username): account = models.Account.get_i(username = username) account.delete() return flask.redirect( flask.url_for("logout") )
def delete_contact(id): contact = models.Contact.get_i(id = id) contact.delete() return flask.redirect( flask.url_for("list_contacts") )
def delete_server(name): server = models.Server.get_i(name = name) server.delete() return flask.redirect( flask.url_for("list_servers") )