Mercurial > kallithea
comparison rhodecode/controllers/api/__init__.py @ 1693:60249224be04 beta
fix for api key lookup, reuse same function in user model
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 17 Nov 2011 18:52:48 +0200 |
parents | fe5575f95850 |
children | fee9895fa46e |
comparison
equal
deleted
inserted
replaced
1692:b76bb93db070 | 1693:60249224be04 |
---|---|
112 except ValueError, e: | 112 except ValueError, e: |
113 #catch JSON errors Here | 113 #catch JSON errors Here |
114 return jsonrpc_error(message="JSON parse error ERR:%s RAW:%r" \ | 114 return jsonrpc_error(message="JSON parse error ERR:%s RAW:%r" \ |
115 % (e, urllib.unquote_plus(raw_body))) | 115 % (e, urllib.unquote_plus(raw_body))) |
116 | 116 |
117 #check AUTH based on API KEY | 117 # check AUTH based on API KEY |
118 try: | 118 try: |
119 self._req_api_key = json_body['api_key'] | 119 self._req_api_key = json_body['api_key'] |
120 self._req_method = json_body['method'] | 120 self._req_method = json_body['method'] |
121 self._req_params = json_body['args'] | 121 self._req_params = json_body['args'] |
122 log.debug('method: %s, params: %s', | 122 log.debug('method: %s, params: %s', |
123 self._req_method, | 123 self._req_method, |
124 self._req_params) | 124 self._req_params) |
125 except KeyError, e: | 125 except KeyError, e: |
126 return jsonrpc_error(message='Incorrect JSON query missing %s' % e) | 126 return jsonrpc_error(message='Incorrect JSON query missing %s' % e) |
127 | 127 |
128 #check if we can find this session using api_key | 128 # check if we can find this session using api_key |
129 try: | 129 try: |
130 u = User.get_by_api_key(self._req_api_key) | 130 u = User.get_by_api_key(self._req_api_key) |
131 if u is None: | |
132 return jsonrpc_error(message='Invalid API KEY') | |
131 auth_u = AuthUser(u.user_id, self._req_api_key) | 133 auth_u = AuthUser(u.user_id, self._req_api_key) |
132 except Exception, e: | 134 except Exception, e: |
133 return jsonrpc_error(message='Invalid API KEY') | 135 return jsonrpc_error(message='Invalid API KEY') |
134 | 136 |
135 self._error = None | 137 self._error = None |