Help us shape the future of Go! Take the 2026 Go Developer Survey

mlearning

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package mlearning implements the mlearning.sjtu.edu.cn attendance endpoints: the SSO chain that plants the domain's Access_Token cookie, the two read projections behind /courses/<id>/attendance, and the scan-submit write of `sjtu attendance submit`.

Token model: a JAAuthCookie-authenticated visit to any forscan URL rides the SSO chain and ends with the callback planting a `token` cookie in the mlearning domain. That cookie is the student client's Access_Token and authenticates API requests as a bare Authorization header value, without a Bearer prefix (verified against the live service on 2026-10-01).

A dead Access_Token is rejected in the business layer, never as 401: the API answers HTTP 200 carrying {"resultCode":"10001"} ("token不存在,请 重新登录!"). Reads detect that shape, clear the planted token, re-run the SSO chain, and retry once; a persistent rejection passes through verbatim for the caller to judge.

Index

Constants

This section is empty.

Variables

View Source
var ErrAuth = errors.New("jaccount authentication required; run `sjtu auth jaccount login`")

ErrAuth reports an expired or missing jAccount session: the SSO chain bounced back to the login host instead of reaching mlearning.

View Source
var ErrInvalidURL = errors.New("not an mlearning forscan URL")

ErrInvalidURL rejects a scanned QR URL that is not a well-formed forscan link; the CLI maps it to a usage error.

Functions

func ValidateForscanURL

func ValidateForscanURL(rawURL string) (rollCallToken, signHistoryID string, err error)

ValidateForscanURL checks a scanned QR URL and extracts its roll-call parameters: https scheme, mlearning host, the forscan path prefix, and non-empty rollCallToken/signHistoryId query parameters.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client talks to mlearning over a cookie session holding a valid JAAuthCookie.

func New

func New(sess *session.Session) *Client

New builds a Client over the given cookie session; the session must carry a JAAuthCookie for the jAccount domain family.

func (*Client) Records

func (c *Client) Records(ctx context.Context, courseID int64) (json.RawMessage, error)

Records lists the caller's sign-in records of the course, as the raw sign/records response with the UI's own paging parameters.

func (*Client) Self added in v0.5.0

func (c *Client) Self(ctx context.Context) (json.RawMessage, error)

Self fetches the caller's identity as the raw users/self response. It is the mlearning domain's lightweight health probe: a live token answers 200 with the identity body, a dead one the 10001 rejection.

func (*Client) Status

func (c *Client) Status(ctx context.Context, courseID int64) (json.RawMessage, error)

Status reports whether the course has a roll call in progress, as the raw existentB response (idle state: {"resultCode":"200","body":{}}).

func (*Client) Submit

func (c *Client) Submit(ctx context.Context, rawURL string) (json.RawMessage, error)

Submit signs one roll call given its scanned QR URL: the URL itself rides the SSO chain, then the scan endpoint is called. The upstream response (resultCode/body.status/message) passes through verbatim; business outcomes, including SIGNED, are the caller's to judge.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL