Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- import xmlrpc.client as xmlrpclib
- from odoo import http
- from openerp.http import Response
- class resUserController(http.Controller):
- url = '<my url>'
- db = '<name of my database>'
- @http.route('/user/login', type='json', method='GET', auth='public')
- def get_login(self, **kwargs):
- username = kwargs.get('email')
- password = kwargs.get('password')
- common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(self.url), allow_none=True)
- uid = common.authenticate(self.db, username, password, {})
- if uid:
- Response.status = '200 Succesful operation'
- json_result = {'token': uid}
- return json.dumps(json_result)
- Response.status = '400 Invalid credentials'
- return
- @http.route('/user/getInfo', type='json', method='GET', auth='user')
- def get_info(self, **kwargs):
- uid = 1
- password = '<my admin password>'
- models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(self.url), allow_none=True)
- info = models.execute_kw(self.db, uid, password, 'res.users',
- 'search_read', [[['id', '=', kwargs.get('token')]]],
- {'fields': ['info']})[0]['invite_code']
- if info:
- Response.status = '200 Succesful operation'
- json_result = {'info': info}
- return json.dumps(json_result)
- Response.status = '404 User not found'
- return
- import requests
- import json
- url_connect = "<my url>/user/login"
- url = "<my url>/user/getInfo"
- headers = {'Content-Type': 'application/json'}
- data_connect = {
- "params": {
- "email": "<my test account email>",
- "password": "<my test account password>",
- }
- }
- data = {
- "params": {
- "token": <my test account id>,
- }
- }
- data_json = json.dumps(data)
- r = requests.get(url=url_connect, data=json.dumps(data_connect), headers=headers)
- print(r)
- print(r.json())
- r = requests.get(url=url, data=data_json, headers=headers)
- print(r)
- print(r.json())
Add Comment
Please, Sign In to add comment