当前位置: 首页 > news >正文

宁波那家公司做网站好wordpress企业中文主题

宁波那家公司做网站好,wordpress企业中文主题,网站模板下载地址,wordpress安装点提交无法访问odoo 17 后端路由接口认证自定义 在接口中, 我们都知道有3中常用的认证方式 user 用户级认证public 访问时赋予公共用户none 不做任何用户级处理 一般不做数据库重要数据校验, 仅做访问处理 以上是源码提供的三种方式 接下来我们自定义一个认证方式 首先找到的这认证是在…

odoo 17 后端路由接口认证自定义

在接口中, 我们都知道有3中常用的认证方式

  • user 用户级认证
  • public 访问时赋予公共用户
  • none 不做任何用户级处理 一般不做数据库重要数据校验, 仅做访问处理

以上是源码提供的三种方式

接下来我们自定义一个认证方式

首先找到的这认证是在 ir.http 模型内完成的, 认真源码如下

@classmethod
def _authenticate(cls, endpoint):auth = 'none' if http.is_cors_preflight(request, endpoint) else endpoint.routing['auth']try:if request.session.uid is not None:if not security.check_session(request.session, request.env):request.session.logout(keep_db=True)request.env = api.Environment(request.env.cr, None, request.session.context)getattr(cls, f'_auth_method_{auth}')()except (AccessDenied, http.SessionExpiredException, werkzeug.exceptions.HTTPException):raiseexcept Exception:_logger.info("Exception during request Authentication.", exc_info=True)raise AccessDenied()

源码中可以看到 getattr(cls, f'_auth_method_{auth}')() 这里匹配并执行, 很明显可以看到调用了这个类的方法 _auth_method_user, _auth_method_public, _auth_method_none 往后继续操作

@classmethod
def _get_public_users(cls):return [request.env['ir.model.data']._xmlid_to_res_model_res_id('base.public_user')[1]]@classmethod
def _auth_method_user(cls):if request.env.uid in [None] + cls._get_public_users():raise http.SessionExpiredException("Session expired")@classmethod
def _auth_method_none(cls):request.env = api.Environment(request.env.cr, None, request.env.context)

这时候我们只需继承 ir.http 模型进行操作, 下面是例子

from odoo import models
from odoo.http import requestclass IrHttp(models.AbstractModel):_inherit = 'ir.http'@classmethoddef _auth_method_wechat(cls):user = request.env.ref('xxx.user_wxapp_user_manager')  # 给后端用户作为认证request.uid = user.idrequest.user = user

这里以通过添加微信认证wechat为例, 将模块安装后,系统会增加一个微信认证功能, 更多操作请在方法中编写逻辑

main.py 文件

普通接口访问如下

@http.route('/demo/auth/reload', type='http', auth='user', methods=['GET'], cors='*', csrf=False)
def auth_reload(self):"""认证接口, 需要通过用户级认证"""return Response(json.dumps({}), status=200, content_type='application/json')

自定义认证访问, 只需修改 auth='wechat' 即可

@http.route('/demo/auth/reload', type='http', auth='wechat', methods=['GET'], cors='*', csrf=False)
def auth_reload(self):"""自定义认证接口, 通过 _auth_method_wechat 方法处理用户需求"""return Response(json.dumps({}), status=200, content_type='application/json')

最后是模块的目录结构

└─demo│  __init__.py│  __manifest__.py│├─controllers│      main.py│      __init__.py│├─models│      ir_http.py│      __init__.py

注意, 别忘了将 controllers 和 models 导出到包外

http://www.yayakq.cn/news/137862/

相关文章:

  • 临沂网站建设报价网站收录 作用
  • 黄骅港站网络营销的基本流程
  • 珍爱网建设网站的目的抚顺网站开发
  • 做网站和app报价有内涵大气的公司名字
  • WordPress网站积分系统长沙定制网站开发
  • 做的网站访问速度慢创建网页需要多少钱
  • 太原网站专业制作html手机模板
  • 网站建设咨询服务合同做门窗生意进哪个网站
  • 在手机上做网站是什么软件网站怎么做前台跟后台的接口
  • 如何做网站二级域名做童车外贸上哪个网站
  • 修改网站描述用百度云服务器做网站
  • 阿里云建站流程wordpress登录网站
  • 莱阳有网站建设推广的吗南山网站建设设计
  • cdr做网站流程2023房地产新闻
  • 平面设计师的网站产品网络推广方案设计
  • 网站建设价格标准方案制作网站的app
  • 东莞市公司网站建设怎么样一个网站需要多少钱
  • 商务网站建设工程师是营销型定制网站
  • 外链网站分类中文域名网站标识
  • 怎么推广一个网站广州游戏开发公司
  • 商务网站规划与建设心得建设电子商务网站的目的和意义
  • 邯郸现代建设集团网站海口市龙华区核酸检测
  • 服务器主机 网站吗windows2012iis网站默认设置
  • 建站公司兴田德润做网站天津
  • 高质量的南昌网站建设电子商务网站建设臧良运课后答案
  • 西青做网站的公司采购需求发布平台
  • 销售网站内容设计方案yahoo网站提交入口
  • 网络推广网站排名网站优化内链怎么做
  • 网站建设汇报会如何做ppt的模板下载网站
  • 网站开发高级工程师专业做网站报价