예제 #1
0
class KimchiRoot(Root):
    def __init__(self, model, dev_env):
        super(KimchiRoot, self).__init__(model, dev_env)
        self.default_page = 'kimchi-ui.html'
        for ident, node in sub_nodes.items():
            setattr(self, ident, node(model))
        self.api_schema = json.load(
            open(os.path.join(paths.src_dir, 'API.json')))
        self.paths = paths
        self.domain = 'kimchi'
        self.messages = messages

    @cherrypy.expose
    def login(self, *args):
        params = parse_request()
        try:
            username = params['username']
            password = params['password']
        except KeyError, item:
            e = MissingParameter('KCHAUTH0003E', {'item': str(item)})
            raise cherrypy.HTTPError(400, e.message)

        try:
            user_info = auth.login(username, password)
        except OperationFailed:
            raise cherrypy.HTTPError(401)

        return json.dumps(user_info)
예제 #2
0
파일: root.py 프로젝트: k0da/kimchi
 def login(self, *args, **kwargs):
     username = kwargs.get("username")
     password = kwargs.get("password")
     # forms base authentication
     if username is not None:
         next_url = cherrypy.request.cookie.get("lastPage")
         if next_url is None:
             # UI can parser the redirect url by "next" query parameter
             next_url = kwargs.get("next", "/")
             next_url = next_url[0] if (type(next_url) is list) else next_url
         else:
             next_url = next_url.value
         auth.login(username, password)
         raise cherrypy.HTTPRedirect(next_url, 303)
     else:
         try:
             params = parse_request()
             username = params["username"]
             password = params["password"]
         except KeyError, item:
             e = MissingParameter("KCHAUTH0003E", {"item": str(item)})
             raise cherrypy.HTTPError(400, e.message)