blob: cc440d264534e9553de9b38c4dafb2bb2c6da8db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
from .. import controller
from odoo import http
from odoo.http import request
from odoo.tools.config import config
class Cart(controller.Controller):
prefix = '/api/v1/'
@http.route(prefix + 'login', auth='public', methods=['POST'], csrf=False)
def login(self, **kw):
if not self.authenticate():
return self.response(code=401, description='Unauthorized')
email = kw.get('email')
password = kw.get('password')
if not email or not password:
return self.response(code=400, description='username and password is required')
try:
uid = request.session.authenticate(config.get('db_name'), email, password)
user = request.env['res.users'].browse(uid)
return self.response({
'is_auth': True,
'user': {
'id': user.id,
'name': user.name,
'email': user.login
}
})
except:
return self.response({'is_auth': False})
|