Browse Source

[ADD] Initial Commit

pull/29/head
SHEREEF PT 8 years ago
parent
commit
b336656caf
  1. 26
      user_login_alert/README.rst
  2. 25
      user_login_alert/__init__.py
  3. 49
      user_login_alert/__manifest__.py
  4. 18
      user_login_alert/__manifest__.py~
  5. 23
      user_login_alert/controllers/__init__.py
  6. 109
      user_login_alert/controllers/main.py
  7. 23
      user_login_alert/models/__init__.py
  8. 31
      user_login_alert/models/logged_details.py
  9. 8
      user_login_alert/security/notification_group.xml
  10. BIN
      user_login_alert/static/description/banner.jpg
  11. BIN
      user_login_alert/static/description/cybro_logo.png
  12. BIN
      user_login_alert/static/description/icon.png
  13. 86
      user_login_alert/static/description/index.html
  14. 82
      user_login_alert/static/description/index.html~
  15. BIN
      user_login_alert/static/description/notified_email.png
  16. BIN
      user_login_alert/static/description/tick_to_receive.png
  17. 25
      user_login_alert/views/logged_details_view.xml

26
user_login_alert/README.rst

@ -0,0 +1,26 @@
User Login Alert v10
====================
This module will help to send the notification to users on successful login to his account.
Working
=======
if user is continuously using the same system the user will be notified only once. If he changes
the browser or the OS from same system he will receive the mail.
If user logged from another system and if he come back to his original system, for the first time
he will receive the email
Configuration
=============
For the working of this module, the outgoing mail configuration has to be configured . The Email will be send
to Users related partners Email ID. If the Email ID for the related partner of the user is not given,
then the notification mail will not send.
Also install the "httpagentparser" python package, sudo pip install httpagentparser
Credits
=======
Cybrosys Techno Solutions
Author
------
* Cybrosys Techno Solutions <http://www.cybrosys.com>

25
user_login_alert/__init__.py

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2017-TODAY Cybrosys Technologies(<http://www.cybrosys.com>).
# Author: Niyas Raphy(<http://www.cybrosys.com>)
# you can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# It is forbidden to publish, distribute, sublicense, or sell copies
# of the Software or modified copies of the Software.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# GENERAL PUBLIC LICENSE (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import controllers
import models

49
user_login_alert/__manifest__.py

@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2017-TODAY Cybrosys Technologies(<http://www.cybrosys.com>).
# Author: Niyas Raphy(<http://www.cybrosys.com>)
# you can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# It is forbidden to publish, distribute, sublicense, or sell copies
# of the Software or modified copies of the Software.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# GENERAL PUBLIC LICENSE (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'User Login Alert',
'summary': """Secure your Odoo account by alerts at right time. If any successful login to your
account happens, an alert mail will be send to you with the browser and IP details.""",
'version': '10.0.1.0',
'description': """Secure your Odoo account by alerts at right time. If any successful login to your
account happens, an alert mail will be send to you with the browser and IP details.""",
'author': 'Cybrosys Techno Solutions',
'company': 'Cybrosys Techno Solutions',
'website': 'http://www.cybrosys.com',
'category': 'Tools',
'depends': ['base', 'mail'],
'license': 'AGPL-3',
'data': [
'security/notification_group.xml',
'views/logged_details_view.xml',
],
'images': ['static/description/banner.jpg'],
'demo': [],
'installable': True,
'auto_install': False,
'external_dependencies': {
'python': ['httpagentparser'],
},
}

18
user_login_alert/__manifest__.py~

@ -0,0 +1,18 @@
{
'name': 'Login Notification',
'summary': """Send login notification E-mail to user""",
'version': '10.0.1.0.0',
'description': """Send login notification E-mail to user""",
'author': 'Cybrosys Techno Solutions',
'company': 'Cybrosys Techno Solutions',
'website': 'http://www.cybrosys.com',
'category': 'Tools',
'depends': ['base', 'web'],
'license': 'AGPL-3',
'data': [
],
'demo': [],
'installable': True,
'auto_install': False,
}

23
user_login_alert/controllers/__init__.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2017-TODAY Cybrosys Technologies(<http://www.cybrosys.com>).
# Author: Niyas Raphy(<http://www.cybrosys.com>)
# you can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# It is forbidden to publish, distribute, sublicense, or sell copies
# of the Software or modified copies of the Software.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# GENERAL PUBLIC LICENSE (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import main

109
user_login_alert/controllers/main.py

@ -0,0 +1,109 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2017-TODAY Cybrosys Technologies(<http://www.cybrosys.com>).
# Author: Niyas Raphy(<http://www.cybrosys.com>)
# you can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# It is forbidden to publish, distribute, sublicense, or sell copies
# of the Software or modified copies of the Software.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# GENERAL PUBLIC LICENSE (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import httpagentparser
from time import gmtime, strftime
from odoo.addons.web.controllers import main
from odoo.http import request
from odoo.exceptions import Warning
import odoo
import odoo.modules.registry
from odoo.tools.translate import _
from odoo import http
class Home(main.Home):
@http.route('/web/login', type='http', auth="public")
def web_login(self, redirect=None, **kw):
main.ensure_db()
request.params['login_success'] = False
if request.httprequest.method == 'GET' and redirect and request.session.uid:
return http.redirect_with_hash(redirect)
if not request.uid:
request.uid = odoo.SUPERUSER_ID
values = request.params.copy()
try:
values['databases'] = http.db_list()
except odoo.exceptions.AccessDenied:
values['databases'] = None
if request.httprequest.method == 'POST':
old_uid = request.uid
uid = request.session.authenticate(request.session.db, request.params['login'], request.params['password'])
if uid is not False:
user_rec = request.env['res.users'].sudo().search([('id', '=', uid)])
if user_rec.partner_id.email and user_rec.has_group('user_login_alert.receive_login_notification'):
send_mail = 0
agent = request.httprequest.environ.get('HTTP_USER_AGENT')
agent_details = httpagentparser.detect(agent)
user_os = agent_details['os']['name']
browser_name = agent_details['browser']['name']
ip_address = request.httprequest.environ['REMOTE_ADDR']
if user_rec.last_logged_ip and user_rec.last_logged_browser and user_rec.last_logged_os:
if user_rec.last_logged_ip != ip_address or user_rec.last_logged_browser != browser_name or user_rec.last_logged_os != user_os:
send_mail = 1
user_rec.last_logged_ip = ip_address
user_rec.last_logged_browser = browser_name
user_rec.last_logged_os = user_os
else:
send_mail = 0
else:
send_mail = 1
user_rec.last_logged_ip = ip_address
user_rec.last_logged_browser = browser_name
user_rec.last_logged_os = user_os
if send_mail == 1:
email_to = user_rec.partner_id.email
current_date_time = strftime("%Y-%m-%d %H:%M:%S", gmtime())
message_body = 'Hi ' + user_rec.name + ' , Your account has been ' \
'accessed successfully. The details of the ' \
'system from which the account is accessed ...,'
message_body += '<table border="1" width="100%" cellpadding="0" bgcolor="#ededed">'
message_body += '<tr><td>' + 'OS' + '</td>' \
'<td>' + user_os + '</td>' \
'</tr>'\
'<tr><td>' + 'Browser' + '</td>' \
'<td>' + browser_name + '</td>' \
'</tr>'\
'<tr><td>' + 'IP Address' + '</td>' \
'<td>' + ip_address + '</td>' \
'</tr>'
message_body += '</table>'
message_body += 'Thank you'
template_obj = request.env['mail.mail']
template_data = {
'subject': 'Login Alert : ' + current_date_time,
'body_html': message_body,
'email_from': request.env.user.company_id.email,
'email_to': email_to
}
template_id = template_obj.create(template_data)
template_obj.send(template_id)
request.params['login_success'] = True
if not redirect:
redirect = '/web'
return http.redirect_with_hash(redirect)
request.uid = old_uid
values['error'] = _("Wrong login/password")
return request.render('web.login', values)

23
user_login_alert/models/__init__.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2017-TODAY Cybrosys Technologies(<http://www.cybrosys.com>).
# Author: Niyas Raphy(<http://www.cybrosys.com>)
# you can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# It is forbidden to publish, distribute, sublicense, or sell copies
# of the Software or modified copies of the Software.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# GENERAL PUBLIC LICENSE (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import logged_details

31
user_login_alert/models/logged_details.py

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2017-TODAY Cybrosys Technologies(<http://www.cybrosys.com>).
# Author: Niyas Raphy(<http://www.cybrosys.com>)
# you can modify it under the terms of the GNU LESSER
# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
#
# It is forbidden to publish, distribute, sublicense, or sell copies
# of the Software or modified copies of the Software.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
#
# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
# GENERAL PUBLIC LICENSE (LGPL v3) along with this program.
# If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from odoo import models, fields
class ResUsersInherit(models.Model):
_inherit = 'res.users'
last_logged_ip = fields.Char(string='IP')
last_logged_browser = fields.Char(string='Browser')
last_logged_os = fields.Char(string='OS')

8
user_login_alert/security/notification_group.xml

@ -0,0 +1,8 @@
<?xml version="1.0"?>
<odoo>
<data>
<record id="receive_login_notification" model="res.groups">
<field name="name">Receive Login Notification</field>
</record>
</data>
</odoo>

BIN
user_login_alert/static/description/banner.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 121 KiB

BIN
user_login_alert/static/description/cybro_logo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
user_login_alert/static/description/icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

86
user_login_alert/static/description/index.html

@ -0,0 +1,86 @@
<section class="oe_container">
<div class="oe_row oe_spaced">
<h2 class="oe_slogan">User Login Alert</h2>
<h3 class="oe_slogan">User will be notified on Successful login</h3>
<h4 class="oe_slogan"><a href="https://www.cybrosys.com">Cybrosys Technologies</a> </h4>
<div>
<p>This module will send a notification email to the users email. The notification email contains the IP
of the system, browser name and OS from which the account is accessed.</p>
</div>
<div>
<h4><p>Features:</p></h4>
<ul>
<li style="list-style:none !important;"><span style="color:green;"> &#9745;</span>&nbsp;&nbsp; Email notification on Log in</li>
<li style="list-style:none !important;"><span style="color:green;"> &#9745;</span>&nbsp;&nbsp; Details of the system that accessed the account</li>
<li style="list-style:none !important;"><span style="color:green;"> &#9745;</span>&nbsp;&nbsp; IP, OS and browser as well as log in time will be there in the notification email</li>
<li style="list-style:none !important;"><span style="color:green;"> &#9745;</span>&nbsp;&nbsp; User will receive notification only if user exist in group receive login notification</li>
</ul>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<div class="oe_row oe_spaced">
<h4 class="oe_slogan">Notification E-Mail</h4>
<div class="oe_span12">
<p>Adding user to the login notification group</p>
<p>user will receive notification only if he is added in this group</p>
<div class="oe_row_img oe_centered">
<img style="border:10px solid white;" class="oe_picture oe_screenshot" src="tick_to_receive.png">
</div>
</div>
<div class="oe_span12">
<p>User received e-mail on successful login</p>
<div class="oe_row_img oe_centered">
<img style="border:10px solid white;" class="oe_picture oe_screenshot" src="notified_email.png">
</div>
</div>
</div>
</section>
<section class="oe_container ">
<div class="oe_row oe_spaced">
<h4 class="oe_slogan">Working</h4>
<div>
<ul>
<li style="list-style:none !important;"><span style="color:green;"> &#9745;</span>&nbsp;&nbsp; If the user is logging in from the same system, user will be only notified for the first time</li>
<li style="list-style:none !important;"><span style="color:green;"> &#9745;</span>&nbsp;&nbsp; If the user changes the browser or OS from the same system, the notification email will be received</li>
<li style="list-style:none !important;"><span style="color:green;"> &#9745;</span>&nbsp;&nbsp; if user logged in from a new system , notification mail will send.</li>
<li style="list-style:none !important;"><span style="color:green;"> &#9745;</span>&nbsp;&nbsp; Users IP, OS ad browser details will be stored in User form.</li>
<li style="list-style:none !important;"><span style="color:green;"> &#9745;</span>&nbsp;&nbsp; Logging in from above IP ,browser and OS user wont be notified</li>
<li style="list-style:none !important;"><span style="color:green;"> &#9745;</span>&nbsp;&nbsp; This will get updated based on users latest login</li>
<li style="list-style:none !important;"><span style="color:green;"> &#9745;</span>&nbsp;&nbsp; This will details be visible only in developer mode</li>
</ul>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<h2 class="oe_slogan" style="margin-top:20px;" >Need Any Help?</h2>
<div class="oe_slogan" style="margin-top:10px !important;">
<div>
<a class="btn btn-primary btn-lg mt8"
style="color: #FFFFFF !important;border-radius: 0;" href="https://www.cybrosys.com"><i
class="fa fa-envelope"></i> Email </a> <a
class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;border-radius: 0;"
href="https://www.cybrosys.com/contact/"><i
class="fa fa-phone"></i> Contact Us </a> <a
class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;border-radius: 0;"
href="https://www.cybrosys.com/odoo-customization-and-installation/"><i
class="fa fa-check-square"></i> Request Customization </a>
</div>
<br>
<img src="cybro_logo.png" style="width: 190px; margin-bottom: 20px;" class="center-block">
<div>
<a href="https://twitter.com/cybrosys" target="_blank"><i class="fa fa-2x fa-twitter" style="color:white;background: #00a0d1;width:35px;"></i></a></td>
<a href="https://www.linkedin.com/company/cybrosys-technologies-pvt-ltd" target="_blank"><i class="fa fa-2x fa-linkedin" style="color:white;background: #31a3d6;width:35px;padding-left: 3px;"></i></a></td>
<a href="https://www.facebook.com/cybrosystechnologies" target="_blank"><i class="fa fa-2x fa-facebook" style="color:white;background: #3b5998;width:35px;padding-left: 8px;"></i></a></td>
<a href="https://plus.google.com/106641282743045431892/about" target="_blank"><i class="fa fa-2x fa-google-plus" style="color:white;background: #c53c2c;width:35px;padding-left: 3px;"></i></a></td>
<a href="https://in.pinterest.com/cybrosys" target="_blank"><i class="fa fa-2x fa-pinterest" style="color:white;background: #ac0f18;width:35px;padding-left: 3px;"></i></a></td>
</div>
</div>
</section>

82
user_login_alert/static/description/index.html~

@ -0,0 +1,82 @@
<section class="oe_container">
<div class="oe_spaced">
<h2 class="oe_slogan">Birthday Notification By E-mail</h2>
<h3 class="oe_slogan">This module will wish the employees on their birthday</h3>
<h4 class="oe_slogan">Author : Cybrosys Techno Solutions , www.cybrosys.com</h4>
<div style="padding-left:66px;">
<h4>Features:</h4>
<ul>
<li style="list-style:none !important;"><span style="color:green;"> &#8594;</span>&nbsp;&nbsp; Adds a cron job to invoke email</li>
<li style="list-style:none !important;"><span style="color:green;"> &#8594;</span>&nbsp;&nbsp; Adds an email template</li>
</ul>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<div class="oe_spaced">
<div class="oe_picture">
<h3 class="oe_slogan">Overview</h3>
<p class="oe_mt32">
HR departments need not worry to wish their employees for their Birthday. In this module we have included the feature to send an email Birthday notification to the employee.
</p>
</div>
</div>
</section>
<section class="oe_container">
<div class="oe_row oe_spaced">
<h4 class="oe_slogan">Employee Form</h4>
<div class="oe_span12">
<p class='oe_mt32'>
&#x261B; Give Date of Birth for employee.<br>
&#x261B; Give work email.<br>
</p>
<div class="oe_row_img oe_centered">
<img class="oe_picture oe_screenshot" src="birthday_1.png">
</div>
</div>
</div>
</section>
<section class="oe_container">
<div class="oe_row oe_spaced">
<h4 class="oe_slogan">Email Template</h4>
<div class="oe_span12">
<p class='oe_mt32'>
&#x261B; The cron job will invoke the email<br>
&#x261B; Email template is very simple<br>
</p>
<div class="oe_row_img oe_centered">
<img class="oe_picture oe_screenshot" src="temp.png">
</div>
</div>
</div>
</section>
<section class="oe_container">
<h2 class="oe_slogan" style="margin-top:20px;" >Need Any Help?</h2>
<div class="oe_slogan" style="margin-top:10px !important;">
<div>
<a class="btn btn-primary btn-lg mt8"
style="color: #FFFFFF !important;border-radius: 0;" href="http://www.cybrosys.com"><i
class="fa fa-envelope"></i> Email </a> <a
class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;border-radius: 0;"
href="http://www.cybrosys.com/contact/"><i
class="fa fa-phone"></i> Contact Us </a> <a
class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;border-radius: 0;"
href="http://www.cybrosys.com/odoo-customization-and-installation/"><i
class="fa fa-check-square"></i> Request Customization </a>
</div>
<br>
<img src="cybro_logo.png" style="width: 190px; margin-bottom: 20px;" class="center-block">
<div>
<a href="https://twitter.com/cybrosys" target="_blank"><i class="fa fa-2x fa-twitter" style="color:white;background: #00a0d1;width:35px;"></i></a></td>
<a href="https://www.linkedin.com/company/cybrosys-technologies-pvt-ltd" target="_blank"><i class="fa fa-2x fa-linkedin" style="color:white;background: #31a3d6;width:35px;padding-left: 3px;"></i></a></td>
<a href="https://www.facebook.com/cybrosystechnologies" target="_blank"><i class="fa fa-2x fa-facebook" style="color:white;background: #3b5998;width:35px;padding-left: 8px;"></i></a></td>
<a href="https://plus.google.com/106641282743045431892/about" target="_blank"><i class="fa fa-2x fa-google-plus" style="color:white;background: #c53c2c;width:35px;padding-left: 3px;"></i></a></td>
<a href="https://in.pinterest.com/cybrosys" target="_blank"><i class="fa fa-2x fa-pinterest" style="color:white;background: #ac0f18;width:35px;padding-left: 3px;"></i></a></td>
</div>
</div>
</section>

BIN
user_login_alert/static/description/notified_email.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
user_login_alert/static/description/tick_to_receive.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

25
user_login_alert/views/logged_details_view.xml

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<data>
<record model="ir.ui.view" id="res_users_logged_details">
<field name="name">res.users</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<xpath expr="//page[1]" position='after'>
<page string="Logged In details" groups="base.group_no_one">
<group>
<group>
<field name="last_logged_ip"/>
</group>
<group>
<field name="last_logged_browser"/>
<field name="last_logged_os"/>
</group>
</group>
</page>
</xpath>
</field>
</record>
</data>
</odoo>
Loading…
Cancel
Save