diff --git a/bio_login/__init__.py b/bio_login/__init__.py new file mode 100644 index 0000000..8067b8f --- /dev/null +++ b/bio_login/__init__.py @@ -0,0 +1,4 @@ +# coding: utf-8 +# Copyright 2017, Jarsa Sistemas, S.A. de C.V. + +from . import models diff --git a/bio_login/__openerp__.py b/bio_login/__openerp__.py new file mode 100644 index 0000000..7f537ce --- /dev/null +++ b/bio_login/__openerp__.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Copyright 2017, Jarsa Sistemas, S.A. de C.V. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Bio Login', + 'version': '9.0.0.1.0', + 'category': 'biometric', + 'author': 'Jarsa Sistemas', + 'description': 'Bio Login', + 'depends': ['base'], + 'data': [ + 'data/config_parameter_data.xml', + 'views/res_user_view.xml', + ], + 'installable': True, +} diff --git a/bio_login/data/config_parameter_data.xml b/bio_login/data/config_parameter_data.xml new file mode 100644 index 0000000..4d7b2bf --- /dev/null +++ b/bio_login/data/config_parameter_data.xml @@ -0,0 +1,7 @@ + + + + ngrok_url + http://0d0b113c.ngrok.io/BioEngineClientWS/BioEngineClient.asmx?WSDL + + \ No newline at end of file diff --git a/bio_login/models/__init__.py b/bio_login/models/__init__.py new file mode 100644 index 0000000..9adda9f --- /dev/null +++ b/bio_login/models/__init__.py @@ -0,0 +1,4 @@ +# coding: utf-8 +# Copyright 2017, Jarsa Sistemas, S.A. de C.V. + +from . import res_users diff --git a/bio_login/models/res_users.py b/bio_login/models/res_users.py new file mode 100644 index 0000000..55b037e --- /dev/null +++ b/bio_login/models/res_users.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- +# Copyright 2017, Jarsa Sistemas, S.A. de C.V. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from zeep import Client +from openerp import _, api, fields, models, registry, SUPERUSER_ID +from openerp.exceptions import ValidationError +from openerp.http import request + + +class ResUsers(models.Model): + _inherit = 'res.users' + + biokey = fields.Char( + string='Biokey', + ) + + def enrollment(self, biokey): + ngrok_url = self.pool.get('ir.config_parameter').get_param( + 'ngrok_url_parameter') + client = Client(ngrok_url) + token = client.service.GetToken()['outToken'] + transaction = client.service.GetTmpTransNum(token)['outTmpTransNum'] + client.service.CaptureFinger( + inToken=token, + inTmpTransNum=transaction, + inFlat=True, + inRoll=False, + inThumbR=False, + inIndexR=True, + inMiddleR=False, + inRingR=False, + inLittleR=False, + inThumbL=False, + inIndexL=False, + inMiddleL=False, + inRingL=False, + inLittleL=False, + ) + client.service.SendToServer(token, transaction) + biokey = client.service.ServerFind(transaction, biokey)['outBioKey'] + return client, token, transaction, biokey + + @api.multi + def fingerprint(self): + self.ensure_one() + client, token, transaction, biokey = self.enrollment(biokey='') + if biokey: + appkey = client.service.GetAppKey(biokey, 'Odoo')['outAppKey'] + if appkey: + res_user = self.browse(int(appkey)) + if self.id != res_user.id: + raise ValidationError( + _('This exits for user %s', res_user.name)) + else: + client.service.ServerSave(transaction, 'Odoo', appkey) + else: + biokey = client.service.ServerSave( + transaction, 'Odoo', self.id)['outBioKey'] + self.biokey = biokey + + def _login(self, db, login, password): + user_id = super(ResUsers, self)._login(db, login, password) + if not user_id: + return user_id + if user_id == SUPERUSER_ID: + return user_id + with registry(db).cursor() as cr: + cr.execute("SELECT biokey FROM res_users WHERE id = %s" % ( + user_id,)) + user_biokey = cr.fetchone() + if request.session.login: + return user_id + client, token, transaction, biokey = self.enrollment( + biokey=user_biokey[0]) + if not biokey: + user_id = False + return user_id diff --git a/bio_login/views/res_user_view.xml b/bio_login/views/res_user_view.xml new file mode 100644 index 0000000..437c43b --- /dev/null +++ b/bio_login/views/res_user_view.xml @@ -0,0 +1,13 @@ + + + + res_users_bio_login + res.users + + + +