From 7784ca272c78a6bd50c431032b643a7ad57b9492 Mon Sep 17 00:00:00 2001 From: capricornxl <40738379+capricornxl@users.noreply.github.com> Date: Mon, 15 Jul 2019 15:53:56 +0800 Subject: [PATCH 1/5] Update readme.md --- readme.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 4148548..2cbed3f 100644 --- a/readme.md +++ b/readme.md @@ -10,7 +10,8 @@ * 应用安全域名和IP一定要配置,否则无法返回接口数据。 #### 移动接入应用: -* 登录中开启扫码登录,配置回调域名:“https://pwd.abc.com/resetcheck”,其中pwd.abc.com请按自己实际域名来,并记录相关的appId、appSecret。 +* 登录中开启扫码登录,配置回调域名:“https://pwd.abc.com/resetcheck” + 其中pwd.abc.com请按自己实际域名来,并记录相关的appId、appSecret。 ## 按自己实际的配置修改项目配置参数: From 212ec9579cc457feb7602518269ba2c8c22ad574 Mon Sep 17 00:00:00 2001 From: capricornxl <40738379+capricornxl@users.noreply.github.com> Date: Mon, 15 Jul 2019 15:58:25 +0800 Subject: [PATCH 2/5] Update readme.md --- readme.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/readme.md b/readme.md index 2cbed3f..00de17a 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,8 @@ +# 初学Django时碰到的一个需求,因为公司中很多员工在修改密码之后,有一些关联的客户端或网页中的旧密码没有更新,导致密码在尝试多次之后账号被锁,为了减少这种让人头疼的重置解锁密码的操蛋工作,自己做了一个自助修改小平台。 + +## 代码写得很LOW,有需要的可以直接拿去用。 + + ## 需要的基础环境: * Python 3.6.x * Nginx(建议) From 6f700f3b7ab614626426856316f821b4aedf4a31 Mon Sep 17 00:00:00 2001 From: capricornxl <40738379+capricornxl@users.noreply.github.com> Date: Mon, 15 Jul 2019 19:58:15 +0800 Subject: [PATCH 3/5] Update form.py --- resetpwd/form.py | 1 + 1 file changed, 1 insertion(+) diff --git a/resetpwd/form.py b/resetpwd/form.py index dd02390..d168929 100644 --- a/resetpwd/form.py +++ b/resetpwd/form.py @@ -3,6 +3,7 @@ from django import forms as c_forms from django.core.exceptions import ValidationError +# 防止前端注释或去除JS文件进行修改简单密码,在后端再次验证。 class CheckForm(c_forms.Form): new_password = c_fields.RegexField( '(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}', From be4f677155790dfdc93a5660202a5a4cecdd834b Mon Sep 17 00:00:00 2001 From: capricornxl <40738379+capricornxl@users.noreply.github.com> Date: Mon, 15 Jul 2019 20:11:13 +0800 Subject: [PATCH 4/5] Delete readme.md --- readme.md | 123 ------------------------------------------------------ 1 file changed, 123 deletions(-) delete mode 100644 readme.md diff --git a/readme.md b/readme.md deleted file mode 100644 index 00de17a..0000000 --- a/readme.md +++ /dev/null @@ -1,123 +0,0 @@ -# 初学Django时碰到的一个需求,因为公司中很多员工在修改密码之后,有一些关联的客户端或网页中的旧密码没有更新,导致密码在尝试多次之后账号被锁,为了减少这种让人头疼的重置解锁密码的操蛋工作,自己做了一个自助修改小平台。 - -## 代码写得很LOW,有需要的可以直接拿去用。 - - -## 需要的基础环境: -* Python 3.6.x -* Nginx(建议) -* Uwsgi(建议) - -## 钉钉必要条件: -#### E应用配置 -* 在钉钉工作台中通过“自建应用”创建应用,选择“企业内部自主开发”,在应用首页中获取应用的AgentId、AppKey、AppSecret。 -* 应用需要权限:身份验证、消息通知、通讯录只读权限、手机号码信息、邮箱等个人信息、智能人事,范围是全部员工或自行选择 -* 应用安全域名和IP一定要配置,否则无法返回接口数据。 - -#### 移动接入应用: -* 登录中开启扫码登录,配置回调域名:“https://pwd.abc.com/resetcheck” - 其中pwd.abc.com请按自己实际域名来,并记录相关的appId、appSecret。 - - -## 按自己实际的配置修改项目配置参数: -修改pwdselfservice/local_settings.py中的参数,按自己的实际参数修改 - -``` python -# AD配置 -AD_HOST = 'abc.com' -AD_LOGIN_USER = 'abc\pwdadmin' -AD_LOGIN_USER_PWD = 'gVykWgNNF0oBQzwmwPp8' -BASE_DN = 'OU=rd,DC=abc,DC=com' - -# 钉钉配置 -# 钉钉统一接口地址,不可修改 -DING_URL = "https://oapi.dingtalk.com/sns" - -# 钉钉企业ID -DING_CORP_ID = 'ding01769028f06d321' - -# 钉钉E应用 -DING_AGENT_ID = '25304321' -DING_APP_KEY = 'dingqdzmn611l5321321' -DING_APP_SECRET = 'rnGRJhhw5kVmzykG9mrTDxewmI4e0myP1123333221jzeKv3amQYWcInLV3x' - -# 钉钉移动应用接入 -DING_SELF_APP_ID = 'dingoabr112233xts' -DING_SELF_APP_SECRET = 'IrH2MedSgesguFjGvFCTjXYBRZD3322112233332211222 - -# Crypty key 通过Crypty.generate_key生成 -CRYPTO_KEY = b'dp8U9y7NAhCD3MoNwPzPBhBtTZ1uI_WWSdpNs6wUDgs=' - -# COOKIE 超时 -TMPID_COOKIE_AGE = 300 - -# 主页域名 -HOME_URL = 'https://pwd.abc.com' - -``` - - -### 自行安装完python3之后,使用python3目录下的pip3进行安装依赖: -### 我自行安装的Python路径为/usr/local/python3 -项目目录下的requestment文件里记录了所依赖的相关python模块,安装方法: -* /usr/local/python3/bin/pip3 install -r requestment - -等待所有模块安装完成之后进行下一步。 - -安装完依赖后,直接执行 -/usr/local/python3/bin/python3 manager.py runserver x.x.x.x:8000 -即可访问正常访问项目 - -## 通过uwsgi启动: -/usr/local/python3/bin/uwsgi -d --ini /usr/loca/wwwroot/pwdselfservice/uwsgi.ini - -其中/xxx/xxx/pwdselfservice/uwsgi.ini是你自己的服务器中此文件的真实地址 - -启动之后也可以通过IP+端口访问了。 - -提供2个脚本,让uwsgi在修改文件时能自动重载: - -uwsgi-start.sh: -```shell -#!/bin/sh -/usr/local/python3/bin/uwsgi -d --ini /usr/loca/wwwroot/pwdselfservice/uwsgi.ini --touch-reload "/usr/loca/wwwroot/pwdselfservice/reload.set" -``` - -uwsgi-autoreload.sh: -```shell -#!/bin/sh -objectdir="/usr/loca/wwwroot/pwdselfservice" - -/usr/bin/inotifywait -mrq --exclude "(logs|\.swp|\.swx|\.log|\.pyc|\.sqlite3)" --timefmt '%d/%m/%y %H:%M' --format '%T %wf' --event modify,delete,move,create,attrib ${objectdir} | while read files -do -/bin/touch /usr/loca/wwwroot/pwdselfservice/reload.set -continue -done & -``` -脚本内的路径按自己实际情况修改 - -## Nginx配置: - -Nginx Server配置: -* proxy_pass的IP地址改成自己的服务器IP -* 配置可自己写一个vhost或直接加在nginx.conf中 -``` nginx -server { - listen 80; - server_name pwd.abc.com; - - location / { - proxy_pass http://192.168.x.x:8000; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - - } - access_log /var/log/nginx/vhost/pwd.log access; - error_log /var/log/nginx/vhost/pwd.err error; -} -``` - -- 执行Nginx reload操作,重新加载配置 - - From 02db301b74c588d91478fdb506ad11f764ab8dab Mon Sep 17 00:00:00 2001 From: capricornxl <40738379+capricornxl@users.noreply.github.com> Date: Mon, 15 Jul 2019 20:11:55 +0800 Subject: [PATCH 5/5] Delete form.py --- resetpwd/form.py | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 resetpwd/form.py diff --git a/resetpwd/form.py b/resetpwd/form.py deleted file mode 100644 index d168929..0000000 --- a/resetpwd/form.py +++ /dev/null @@ -1,35 +0,0 @@ -from django.forms import fields as c_fields -from django import forms as c_forms -from django.core.exceptions import ValidationError - - -# 防止前端注释或去除JS文件进行修改简单密码,在后端再次验证。 -class CheckForm(c_forms.Form): - new_password = c_fields.RegexField( - '(?=.*[0-9])(?=.*[a-zA-Z])(?=.*[^a-zA-Z0-9]).{8,30}', - # 密码必须同时包含大写、小写、数字和特殊字符其中三项且至少8位 - strip=True, - min_length=8, - max_length=30, - error_messages={'required': '新密码不能为空.', - 'invalid': '密码必须包含数字,字母、特殊字符', - 'min_length': "密码长度不能小于8个字符", - 'max_length': "密码长度不能大于30个字符"} - ) - old_password = c_fields.CharField(error_messages={'required': '确认密码不能为空'}) - ensure_password = c_fields.CharField(error_messages={'required': '确认密码不能为空'}) - user_email = c_fields.CharField(error_messages={'required': '邮箱不能为空', 'invalid': '邮箱格式错误'}) - - def clean(self): - pwd0 = self.cleaned_data.get('old_password') - pwd1 = self.cleaned_data.get('new_password') - pwd2 = self.cleaned_data.get('ensure_password') - if pwd1 == pwd2: - pass - elif pwd0 == pwd1: - # 这里异常模块导入要放在函数里面,放到文件开头有时会报错,找不到 - from django.core.exceptions import ValidationError - raise ValidationError('新旧密码不能一样') - else: - from django.core.exceptions import ValidationError - raise ValidationError('新密码和确认密码输入不一致')