Browse Source

Jul 15 [UPDT] Updated 'access_restriction_by_ip'

pull/254/merge
AjmalCybro 10 months ago
parent
commit
c699cdb6ee
  1. 6
      access_restriction_by_ip/models/allowed_ips.py
  2. 31
      access_restriction_by_ip/static/src/js/widget.js
  3. 1
      access_restriction_by_ip/views/allowed_ips_view.xml

6
access_restriction_by_ip/models/allowed_ips.py

@ -18,13 +18,17 @@
#
##############################################################################
from odoo import api, models, fields
from odoo.http import request
class ResUsersInherit(models.Model):
_inherit = 'res.users'
allowed_ips = fields.One2many('allowed.ips', 'users_ip', string='IP')
def action_logout(self):
session = self.env['ir.http'].session_info()
class AllowedIPs(models.Model):
_name = 'allowed.ips'

31
access_restriction_by_ip/static/src/js/widget.js

@ -1,13 +1,13 @@
/** @odoo-module **/
import SystrayMenu from 'web.SystrayMenu';
import Widget from 'web.Widget';
var ajax = require('web.ajax');
var core = require('web.core');
import ajax from 'web.ajax';
import core from 'web.core';
var qweb = core.qweb;
var GetUser = Widget.extend({
/**
function run before loading the page to call methode "get_idle_time"
function run before loading the page to call method "get_user"
*/
willStart: function() {
var self = this;
@ -19,15 +19,30 @@ var GetUser = Widget.extend({
Getting minutes through python for the corresponding user in the backend
*/
get_user: function() {
var self = this
var now = new Date().getTime();
var self = this;
ajax.rpc('/get_ip').then(function(data) {
console.log(data)
if (data == false){
location.replace("/web/session/logout")
}
})
});
},
/**
Binding mouseup event
*/
start: function() {
var self = this;
this._super.apply(this, arguments).then(function() {
$(document).on('mouseup', self.onMouseUp.bind(self));
});
},
/**
Function to be called on mouseup event
*/
onMouseUp: function(event) {
this.get_user();
},
});
// Ensure the widget is added to the Systray menu
SystrayMenu.Items.push(GetUser);
export default GetUser;
export default GetUser;

1
access_restriction_by_ip/views/allowed_ips_view.xml

@ -8,6 +8,7 @@
<field name="arch" type="xml">
<xpath expr="//page[1]" position='after'>
<page string="Allowed IP">
<button name="action_logout" type="object" string="Logout"/>
<field name="allowed_ips">
<tree editable="bottom" delete="1">
<field name="ip_address"/>

Loading…
Cancel
Save