Skip to main content

The authentication module of SCUEC.

Project description

SCUEC信息门户认证模块

声明:写这个模块的初衷是学习Python的模块开发,开源是为了方便有需要的同学用作学习研究。使用者需自行承担因不正常使用此模块而产生的一切后果,本人不负任何责任!使用此模块则代表同意此声明。

安装

pip install SCUECAuth

简单使用

# -*- coding: utf-8 -*-
from scuec_auth import SCUECAuth

sa = SCUECAuth()
session = sa.login('工号/学号', '密码')

# 接下来就可以使用session访问有登录限制的地址了,例如session.get(url),具体方法参照requests.Session

详细使用

# -*- coding: utf-8 -*-
from scuec_auth import SCUECAuth, debug

# is_verify : 是否验证登录后的session,默认True
# is_debug  : 是否输出认证过程中的debug信息,默认为False
sa = SCUECAuth(is_verify=False, is_debug=False) # 关闭session验证

# 开启session缓存,登录成功后的session将被缓存,有效期默认为1800秒,即30分钟
sa.open_session_cache(max_age=1800)

# 使用用户信息登录,此session将被缓存
# 30分钟内当前用户多次使用login方法都将得到缓存的session,通过该session访问相关地址会更新其最近使用时间以维持会话
# 当缓存的session最近30分钟一直未被使用,则login方法将获取新的session并再次缓存
session = sa.login('工号/学号', '密码')

# 验证session
if sa.verify_session(session):
    debug(tag='验证', msg='session是有效的')
    # 使用session访问有登录限制的地址,例如session.get(url),具体方法参照requests.Session

sa.logout(username='') # 默认清理当前用户登录所产生session,可通过username参数清除指定用户session

# 关闭session缓存,所有用户登录缓存都将被清除
sa.close_session_cache()

简单应用

此模块基于Python,你可以在任何以Python为开发语言的程序或框架中使用,这里以flask为例

# -*- coding: utf-8 -*-
from flask import Flask, request, render_template
from scuec_auth import SCUECAuth

app  = Flask(__name__)
sa = SCUECAuth()
sa.open_session_cache()

@app.route('/', methods=['GET', 'POST'])
def index():
    if request.method == "GET":
        return render_template('index.html')
    uname = str(request.form.get('username')).strip()
    passwd = str(request.form.get('password')).strip()
    if SCUECAuth.is_username_valid(uname) and len(passwd)!=0:
        if sa.login(uname, passwd):
            return '1'
    return '0'

if __name__ == '__main__':
    app.run()

代码地址:/examples/flask

测试地址:https://scuec-auth.wengcx.top

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

SCUECAuth-1.1.4.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

SCUECAuth-1.1.4-py2.py3-none-any.whl (8.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file SCUECAuth-1.1.4.tar.gz.

File metadata

  • Download URL: SCUECAuth-1.1.4.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.1

File hashes

Hashes for SCUECAuth-1.1.4.tar.gz
Algorithm Hash digest
SHA256 f974ff7268b0708c369885c2eff3f4a0b312ae2c640781514db471666a0fe94e
MD5 404379457afda5dbbc9a5b22ae57ffe1
BLAKE2b-256 64769944152b6900eff8853ff134b4f4e63b6dd6cac85e8d31cf773d1e8ca0f2

See more details on using hashes here.

File details

Details for the file SCUECAuth-1.1.4-py2.py3-none-any.whl.

File metadata

  • Download URL: SCUECAuth-1.1.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.7.1

File hashes

Hashes for SCUECAuth-1.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 47b836622f9f57b5faa2da54f093d004c0de84d4ff043c22ecbf52746c69288d
MD5 0e1a03abf5e59adfa86fcb13bd7a896f
BLAKE2b-256 086460b004e7ff7e744e2f6d0630e06f0a3836b05259e88191b7474bf3163ace

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page