Browse Source

Jun 21 [UPDT] Updated 'access_restriction_by_ip'

pull/195/merge
AjmalCybro 1 year ago
parent
commit
743618efd9
  1. 6
      access_restriction_by_ip/__manifest__.py
  2. 14
      access_restriction_by_ip/controllers/main.py
  3. 3
      access_restriction_by_ip/models/allowed_ips.py
  4. 23
      access_restriction_by_ip/static/description/index.html
  5. 33
      access_restriction_by_ip/static/src/js/widget.js

6
access_restriction_by_ip/__manifest__.py

@ -31,8 +31,12 @@
'security/ir.model.access.csv', 'security/ir.model.access.csv',
'views/allowed_ips_view.xml', 'views/allowed_ips_view.xml',
], ],
'assets': {
'web.assets_backend': [
'/access_restriction_by_ip/static/src/js/widget.js',
],
},
'images': ['static/description/banner.png'], 'images': ['static/description/banner.png'],
'installable': True, 'installable': True,
'auto_install': False, 'auto_install': False,
} }

14
access_restriction_by_ip/controllers/main.py

@ -34,10 +34,8 @@ class Home(main.Home):
request.params['login_success'] = False request.params['login_success'] = False
if request.httprequest.method == 'GET' and redirect and request.session.uid: if request.httprequest.method == 'GET' and redirect and request.session.uid:
return request.redirect(redirect) return request.redirect(redirect)
if not request.uid: if not request.uid:
request.uid = odoo.SUPERUSER_ID request.uid = odoo.SUPERUSER_ID
values = request.params.copy() values = request.params.copy()
try: try:
values['databases'] = http.db_list() values['databases'] = http.db_list()
@ -85,5 +83,15 @@ class Home(main.Home):
request.uid = old_uid request.uid = old_uid
if e.args == odoo.exceptions.AccessDenied().args: if e.args == odoo.exceptions.AccessDenied().args:
values['error'] = _("Wrong login/password") values['error'] = _("Wrong login/password")
return request.render('web.login', values) return request.render('web.login', values)
@http.route('/get_ip', auth='user', type='json')
def get_ip(self):
ip_address = request.httprequest.environ['REMOTE_ADDR']
ip_addresses = []
for ips in request.env.user.allowed_ips:
ip_addresses.append(ips.ip_address)
if ip_addresses:
if ip_address not in ip_addresses:
return False
return True

3
access_restriction_by_ip/models/allowed_ips.py

@ -17,7 +17,7 @@
# If not, see <http://www.gnu.org/licenses/>. # If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from odoo import models, fields from odoo import api, models, fields
class ResUsersInherit(models.Model): class ResUsersInherit(models.Model):
@ -31,3 +31,4 @@ class AllowedIPs(models.Model):
users_ip = fields.Many2one('res.users', string='IP') users_ip = fields.Many2one('res.users', string='IP')
ip_address = fields.Char(string='Allowed IP') ip_address = fields.Char(string='Allowed IP')

23
access_restriction_by_ip/static/description/index.html

@ -1,4 +1,3 @@
<div class="container" style="padding: 1rem !important; margin-bottom: 1rem !important;"> <div class="container" style="padding: 1rem !important; margin-bottom: 1rem !important;">
<div class="row"> <div class="row">
<div class="col-sm-12 col-md-12 col-lg-12 d-flex justify-content-between" <div class="col-sm-12 col-md-12 col-lg-12 d-flex justify-content-between"
@ -32,7 +31,7 @@
style="font-family: 'Montserrat', sans-serif !important; font-weight: 300 !important; color: #FFFFFF !important; font-size: 1.4rem !important; text-align: center !important;"> style="font-family: 'Montserrat', sans-serif !important; font-weight: 300 !important; color: #FFFFFF !important; font-size: 1.4rem !important; text-align: center !important;">
User can access his account only from specified IP's User can access his account only from specified IP's
</p> </p>
<img src="./assets/screenshots/hero.png" class="img-responsive" width="100%" height="auto" /> <img src="./assets/screenshots/hero.png" class="img-responsive" width="100%" height="auto"/>
</div> </div>
</div> </div>
@ -210,7 +209,8 @@
Userwise IP</h4> Userwise IP</h4>
<p <p
style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;"> style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;">
If no IP is set to user means there is not any restriction by IP. IP Address for each users can be set from users form view</p> If no IP is set to user means there is not any restriction by IP. IP Address for each users can be
set from users form view</p>
</div> </div>
</div> </div>
@ -234,7 +234,7 @@
style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;"> style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;">
User will be able to access his account only from this IP's</p> User will be able to access his account only from this IP's</p>
<img src="assets/screenshots/access_restriction_by_ip_1.png" class="img-responsive img-thumbnail border" <img src="assets/screenshots/access_restriction_by_ip_1.png" class="img-responsive img-thumbnail border"
width="100%" height="auto" /> width="100%" height="auto"/>
</div> </div>
<div class="col-lg-12 my-3"> <div class="col-lg-12 my-3">
@ -243,10 +243,11 @@
User accessing his account</h4> User accessing his account</h4>
<p <p
style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;"> style="font-family: 'Roboto', sans-serif !important; font-weight: 400 !important; color: #282F33 !important; font-size: 1rem !important;">
On accessing account from a non specified IP. On accessing account from a non specified IP.(If the user is already logged in he/she will be logged out
after the first reload)
</p> </p>
<img src="assets/screenshots/access_restriction_by_ip_2.png" class="img-responsive img-thumbnail border" <img src="assets/screenshots/access_restriction_by_ip_2.png" class="img-responsive img-thumbnail border"
width="100%" height="auto" /> width="100%" height="auto"/>
</div> </div>
</div> </div>
@ -273,7 +274,7 @@
style="text-align: center; padding: 2.5rem 1rem !important;"> style="text-align: center; padding: 2.5rem 1rem !important;">
<h2 style="color: #212529 !important;">Suggested Products</h2> <h2 style="color: #212529 !important;">Suggested Products</h2>
<hr <hr
style="border: 3px solid #714B67 !important; background-color: #714B67 !important; width: 80px !important; margin-bottom: 2rem !important;" /> style="border: 3px solid #714B67 !important; background-color: #714B67 !important; width: 80px !important; margin-bottom: 2rem !important;"/>
<div id="demo1" class="row carousel slide" data-ride="carousel"> <div id="demo1" class="row carousel slide" data-ride="carousel">
<!-- The slideshow --> <!-- The slideshow -->
@ -358,7 +359,7 @@
<div class="col-lg-12 d-flex flex-column justify-content-center align-items-center"> <div class="col-lg-12 d-flex flex-column justify-content-center align-items-center">
<h2 style="color: #212529 !important;">Our Services</h2> <h2 style="color: #212529 !important;">Our Services</h2>
<hr <hr
style="border: 3px solid #714B67 !important; background-color: #714B67 !important; width: 80px !important; margin-bottom: 2rem !important;" /> style="border: 3px solid #714B67 !important; background-color: #714B67 !important; width: 80px !important; margin-bottom: 2rem !important;"/>
</div> </div>
<div class="col-lg-4 d-flex flex-column justify-content-center align-items-center my-4"> <div class="col-lg-4 d-flex flex-column justify-content-center align-items-center my-4">
@ -463,7 +464,7 @@
<div class="col-lg-12 d-flex flex-column justify-content-center align-items-center"> <div class="col-lg-12 d-flex flex-column justify-content-center align-items-center">
<h2 style="color: #212529 !important;">Our Industries</h2> <h2 style="color: #212529 !important;">Our Industries</h2>
<hr <hr
style="border: 3px solid #714B67 !important; background-color: #714B67 !important; width: 80px !important; margin-bottom: 2rem !important;" /> style="border: 3px solid #714B67 !important; background-color: #714B67 !important; width: 80px !important; margin-bottom: 2rem !important;"/>
</div> </div>
<div class="col-lg-3"> <div class="col-lg-3">
@ -597,7 +598,7 @@
<div class="col-lg-12 d-flex flex-column justify-content-center align-items-center"> <div class="col-lg-12 d-flex flex-column justify-content-center align-items-center">
<h2 style="color: #212529 !important;">Need Help?</h2> <h2 style="color: #212529 !important;">Need Help?</h2>
<hr <hr
style="border: 3px solid #714B67 !important; background-color: #714B67 !important; width: 80px !important; margin-bottom: 2rem !important;" /> style="border: 3px solid #714B67 !important; background-color: #714B67 !important; width: 80px !important; margin-bottom: 2rem !important;"/>
</div> </div>
</div> </div>
@ -630,7 +631,7 @@
<div class="row" style="max-width:1540px; margin: 0 auto; margin-right: 3rem; "> <div class="row" style="max-width:1540px; margin: 0 auto; margin-right: 3rem; ">
<!-- Logo --> <!-- Logo -->
<div class="col-lg-12 d-flex justify-content-center align-items-center" style="margin-top: 3rem;"> <div class="col-lg-12 d-flex justify-content-center align-items-center" style="margin-top: 3rem;">
<img src="https://www.cybrosys.com/images/logo.png" width="200px" height="auto" /> <img src="https://www.cybrosys.com/images/logo.png" width="200px" height="auto"/>
</div> </div>
<!-- End of Logo --> <!-- End of Logo -->
<div class="col-lg-12"> <div class="col-lg-12">

33
access_restriction_by_ip/static/src/js/widget.js

@ -0,0 +1,33 @@
/** @odoo-module **/
import SystrayMenu from 'web.SystrayMenu';
import Widget from 'web.Widget';
var ajax = require('web.ajax');
var core = require('web.core');
var qweb = core.qweb;
var GetUser = Widget.extend({
/**
function run before loading the page to call methode "get_idle_time"
*/
willStart: function() {
var self = this;
return this._super().then(function() {
self.get_user();
});
},
/**
Getting minutes through python for the corresponding user in the backend
*/
get_user: function() {
var self = this
var now = new Date().getTime();
ajax.rpc('/get_ip').then(function(data) {
console.log(data)
if (data == false){
location.replace("/web/session/logout")
}
})
},
});
SystrayMenu.Items.push(GetUser);
export default GetUser;
Loading…
Cancel
Save