审批
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
from . import update
|
||||
from . import ir_http
|
||||
@@ -0,0 +1,30 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import json
|
||||
|
||||
from odoo import models
|
||||
from odoo.http import request
|
||||
|
||||
|
||||
class Http(models.AbstractModel):
|
||||
_inherit = "ir.http"
|
||||
|
||||
def session_info(self):
|
||||
ICP = self.env["ir.config_parameter"].sudo()
|
||||
User = self.env["res.users"]
|
||||
|
||||
if User.has_group("base.group_system"):
|
||||
warn_enterprise = "admin"
|
||||
elif User.has_group("base.group_user"):
|
||||
warn_enterprise = "user"
|
||||
else:
|
||||
warn_enterprise = False
|
||||
|
||||
result = super(Http, self).session_info()
|
||||
result["support_url"] = "https://www.pengyuthon.com//help"
|
||||
if warn_enterprise:
|
||||
result["warning"] = warn_enterprise
|
||||
result["expiration_date"] = ICP.get_param("database.expiration_date")
|
||||
result["expiration_reason"] = ICP.get_param("database.expiration_reason")
|
||||
return result
|
||||
@@ -0,0 +1,74 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
import datetime
|
||||
import logging
|
||||
import rsa
|
||||
import base64
|
||||
from os.path import join as opj
|
||||
from odoo.modules import get_module_path
|
||||
|
||||
from odoo import api, release, SUPERUSER_ID
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.models import AbstractModel
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PublisherWarrantyContract(AbstractModel):
|
||||
_inherit = "publisher_warranty.contract"
|
||||
|
||||
# rsa解密
|
||||
def rsaDecrypt(self, str1):
|
||||
modpath = get_module_path("database_activation_code")
|
||||
file_path = opj(modpath, "static", "privkey.pem")
|
||||
with open(file_path) as privatefile:
|
||||
p = privatefile.read()
|
||||
# 验证密钥
|
||||
try:
|
||||
privkey = rsa.PrivateKey.load_pkcs1(p)
|
||||
except:
|
||||
raise UserError("请联系管理员!")
|
||||
|
||||
try:
|
||||
str1 = base64.b16decode(str1)
|
||||
# 私钥解密
|
||||
content = rsa.decrypt(str1, privkey)
|
||||
con = content.decode("utf-8").split("#")
|
||||
if len(con) != 2:
|
||||
raise
|
||||
database_partner = con[0]
|
||||
old_database_partner = (
|
||||
self.sudo().env["ir.config_parameter"].get_param("database.partner")
|
||||
)
|
||||
if database_partner != old_database_partner:
|
||||
raise
|
||||
|
||||
expiration_date = con[1]
|
||||
old_enterprise_code = (
|
||||
self.sudo()
|
||||
.env["ir.config_parameter"]
|
||||
.get_param("database.expiration_date")
|
||||
)
|
||||
except:
|
||||
raise UserError("激活码错误")
|
||||
|
||||
if expiration_date <= old_enterprise_code:
|
||||
raise UserError("激活码已过期")
|
||||
# 设置过期时间
|
||||
set_param = self.env["ir.config_parameter"].sudo().set_param
|
||||
set_param("database.expiration_date", expiration_date)
|
||||
|
||||
def update_notification(self, cron_mode=True):
|
||||
# 获取激活码
|
||||
enterprise_code = (
|
||||
self.sudo().env["ir.config_parameter"].get_param("database.enterprise_code")
|
||||
)
|
||||
if enterprise_code:
|
||||
try:
|
||||
enterprise_code = str.encode(enterprise_code)
|
||||
except:
|
||||
raise UserError("激活码错误")
|
||||
# 验证激活码
|
||||
self.rsaDecrypt(enterprise_code)
|
||||
return True
|
||||
Reference in New Issue
Block a user