Changeset 7116 for cows_wps


Ignore:
Timestamp:
28/06/10 16:17:58 (9 years ago)
Author:
astephen
Message:

fixed admin interface

Location:
cows_wps/trunk/cows_wps
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cows_wps/trunk/cows_wps/controllers/admin.py

    r7115 r7116  
    33from pylons import request, response, session, tmpl_context as c 
    44from pylons.controllers.util import abort, redirect_to 
     5from routes import url_for 
    56 
    67from cows_wps.model.managers import requestManager 
     
    1011from cows_wps.controllers import * 
    1112from cows_wps.lib.ui.proc_config import * 
     13from cows_wps.utils.common import * 
    1214 
    1315log = logging.getLogger(__name__) 
     
    1719 
    1820    def index(self): 
     21        # Check cookie first 
     22        if isAdminLoggedIn(request): 
     23            return self._successfulLogin()  
     24      
    1925        sess = requestManager.getSession() 
    2026        res = sess.query(tables.admin)[0] 
     
    4854    def _successfulLogin(self): 
    4955        response.set_cookie('wps_ui_admin', request.environ["REMOTE_ADDR"], expires = 3600) 
    50         html = """<p>You have successfully logged in.</p><p>Please try using the <a href="/jobs">jobs page</a> to view and manage everyone's jobs.</p>""" 
     56        html = """      <p>You are logged in as the administrator.</p> 
     57        <p>Please try using the <a href="%s">jobs page</a> to view and manage everyone's jobs.</p> 
     58        <p>Click <a href="%s">logout</a> to log out.</p>""" % (url_for(controller = 'jobs'), url_for(controller = 'admin', action = 'logout')) 
    5159        renderer = UIPageRenderer() 
    5260        resp = renderer.render("Administrator page", 
     
    6573            login_form = """<center><div id="bad_login" style="width: 600px; border-width: 0px; background: orange; color: white; font-weight: bold; padding: 3px;">%s</div></center>""" % err_msg 
    6674 
    67         login_form += """<form action="/admin" onSubmit="return validateTextInput(document.getElementById('admin_name').value, /^[a-zz0-9A-Z]{4,20}$/, 'The user name must be between 4 and 20 letters and/or numbers.');" >  
    68                 <p>Please enter your details</p> 
     75        login_form += """<form action="/admin" onSubmit="return validateTextInput(document.getElementById('admin_name').value, /^[a-zz0-9A-Z]{4,20}$/, 'The user name must be between 4 and 20 letters and/or numbers.');" method="POST">  
     76                <p>Please enter the WPS UI Administrator account details below.</p> 
    6977                <label class="text_width_150"><b>Username: </b></label> 
    70                 <input type="text" name="admin_name" id="username" value="" size="20" /><br /> 
     78                <input type="text" name="admin_name" value="" size="20" /><br /> 
    7179                <label class="text_width_150"><b>Password: </b></label> 
    7280                <input type="password" name="admin_password" value="" size="20" />&nbsp;&nbsp; 
     
    7886                               [("Login", login_form)]) 
    7987        return resp 
     88 
    8089        
    8190    def logout(self): 
    82         return str(dir(request.params["wps_ui_admin"])) 
     91        del request.cookies["wps_ui_admin"] 
    8392        return self.login(err_msg = "You have successfully logged out.") 
  • cows_wps/trunk/cows_wps/controllers/jobs.py

    r7115 r7116  
    1212from cows_wps.process_handler.context.process_status import STATUS 
    1313from cows_wps.process_handler.validate_arguments import parseDateTime 
     14from cows_wps.utils.common import * 
    1415 
    1516log = logging.getLogger(__name__) 
     
    100101    def index(self): 
    101102        # Check if admin is True 
    102         admin = False 
    103         admin_cookie = request.cookies.get("wps_ui_admin", None) 
    104 #        return str(admin_cookie) 
    105  
    106         if admin_cookie and admin_cookie == request.environ["REMOTE_ADDR"]: 
    107             admin = True 
     103        admin = isAdminLoggedIn(request) 
    108104 
    109105        (args, bad_args) = self._parseArgs(admin = admin) 
  • cows_wps/trunk/cows_wps/utils/common.py

    r7082 r7116  
    280280 
    281281 
     282def isAdminLoggedIn(request):  
     283    "Returns boolean." 
     284    admin = False 
     285    admin_cookie = request.cookies.get("wps_ui_admin", None) 
     286 
     287    if admin_cookie and admin_cookie == request.environ["REMOTE_ADDR"]: 
     288        admin = True 
     289 
     290    return admin 
     291 
     292 
    282293if __name__ == "__main__": 
    283294 
Note: See TracChangeset for help on using the changeset viewer.