Skip to main content

django-hfut-auth

https://img.shields.io/github/license/er1iang/django-hfut-auth.svg https://img.shields.io/pypi/v/django-hfut-auth.svg https://img.shields.io/travis/er1iang/django-hfut-auth.svg https://img.shields.io/coveralls/er1iang/django-hfut-auth.svg?maxAge=2592000

使用合工大教务接口进行用户身份认证, 支持合肥校区和宣城校区

django-hfut-auth 是一个合肥工业大学学生用户的统一身份认证的工具, 目的是简化使用 Django 开发合工大学生相关网站的用户认证过程.

功能特性

  • 多版本支持, 同时支持Python2和Python3

  • 使用简单, 只需配置好两个配置项就可以工作, 同时自带了登录表单

  • 灵活性高, 你可以自定义可用的校区, 认证成功或失败时所进行的操作

  • 侵入性小, 你几乎不需要怎么修改你的代码逻辑就能集成基于合工大教务信息的学生身份认证

  • 可用性强, 只有在其他认证方式失败同时提供的认证信息格式正确时才会向教务系统发送请求, 避免了错误的用户输入和高频操作导致的IP锁定问题

依赖

django-hfut-auth 依赖如下:

django>=1.9
hfut-stu-lib>=1.4.1

其中由于 django 1.9 版本支持 Python 2.7, 3.4, 3.5 版本 , 相应的, django-hfut-auth 也支持上述几个版本

安装

你只需要在命令行下输入一下代码便能安装好 django-hfut-auth:

$ pip install django-hfut-auth

如果你没有安装 pip , Python 安装包指南 能够指导你安装 PIP .

配置

settings.py:

INSTALLED_APPS = (
    ...
    # 必要的 APP
    'django.contrib.auth',
    'django.contrib.contenttypes',
    # 添加 APP
    'hfut_auth',
    ...
)
AUTHENTICATION_BACKENDS = (
    ...
    # 必要的认证后端
    'django.contrib.auth.backends.ModelBackend',
    # 将 HFUTBackend 放在 ModelBackend 后面, 确保先从本地数据库认证
    'hfut_auth.backends.HFUTBackend',
    ...
)

# 其他配置, 右侧为默认值
# 支持认证的校区, 宣城校区为'XC', 合肥校区为'HF', 所有校区为'ALL'
HFUT_AUTH_CAMPUS = 'ALL'

使用

配置完成后, 按照一般的认证方式认证即可. 注意当 HFUT_AUTH_CAMPUS = ‘ALL’ 时, 调用 django.contrib.auth.authenticate 需要提供 campus 参数指明是哪个校区.

相应的, 它提供了 hfut_auth.forms.AuthenticationForm , 它集成自 django.contrib.auth.forms.AuthenticationForm , 能够自动的根据配置添加 campus 表单字段, 其他的与父类没有任何区别.

信号

hfut_auth.signals.hfut_auth_succeeded:

当通过 hfut_auth.backends.HFUTBackend 认证成功时发送的信号, 提供了 user , session 两个参数.

user 是认证得到的用户,注意当数据库里没有对应认证资料的用户时, user 为 None , 你可以接收此信号并提供用户创建逻辑, 返回一个创建完成的用户, 这样就能省去用户的创建视图等等麻烦.

session 是一个 hfut_stu_lib.model.StudentSession 实例, 你可以使用它调用教务接口获取想要的数据.

hfut_auth.signals.hfut_auth_failed:

当通过 hfut_auth.backends.HFUTBackend 认证失败时发送的信号, 提供了 reason , credentials 两个参数

reason 是一个错误实例, 它告诉你认证失败的原因.

credentials 是调用 django.contrib.auth.authenticate 时提供的参数, 注意为了安全考虑, 诸如密码,Token等敏感信息都被替换了

授权协议

  • Free software: MIT license

开发日志

0.1.2 (2016-08-25)

  • 由于 django 1.9 版本只支持 Python 2.7, 3.4, 3.5 版本, 相应的移除了 Python 3.3 的支持

  • 更新了文档

Metadata

Release files for django-hfut-auth 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-hfut-auth 0.1.2
File Size Uploaded Provenance Actions
django-hfut-auth-0.1.2.win-amd64.zip 16.7 kB Without provenance Details for django-hfut-auth-0.1.2.win-amd64.zip

Built distribution (wheel)

Table of built distributions (wheels) for django-hfut-auth 0.1.2
File Interpreter ABI Platform Actions
django_hfut_auth-0.1.2-py2.py3-none-any.whl Python 3, Python 2 none any Details for django_hfut_auth-0.1.2-py2.py3-none-any.whl

Total release size: 27.9 kB

Release files / django-hfut-auth-0.1.2.win-amd64.zip

Download URL django-hfut-auth-0.1.2.win-amd64.zip
Size 16.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0f9458fbbe35c44f7a27cdb5a098a5d8cd89c0435a9c5aebc3df57b6058c4ff2
BLAKE2b-256 checksum
How to use checksums
d3a3aff821cae67cddda0d5fe83696dddd0a3cfb1058cef1c7fe950d17b5edf0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / django_hfut_auth-0.1.2-py2.py3-none-any.whl

Download URL django_hfut_auth-0.1.2-py2.py3-none-any.whl
Size 11.2 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7fffbdfa96f23149d2df3e3405f5218db332271aa78701d99ecdc4d1ce32ffbf
BLAKE2b-256 checksum
How to use checksums
8c87600181f6e3587a9ad779abb31f0a195c7c64cd50b5fe4a80996dafffa4dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-hfut-auth 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page