更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -14,17 +14,6 @@ import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// =============================================================
|
||||
// 移动端免登录票据(把移动端登录态桥接到 Web 端)
|
||||
//
|
||||
// POST /auth/app-ticket 移动端带 Bearer 令牌 → 签发一次性票据
|
||||
// POST /auth/app-ticket/exchange Web 端带票据 → 核销并换发 Web 端令牌
|
||||
//
|
||||
// 仅用于「移动端已登录 → 打开 Web 端功能页」这一条链路,
|
||||
// 票据一次性 + 60 秒有效,泄露也无法二次使用。
|
||||
// =============================================================
|
||||
|
||||
// AuthAppTicketController 移动端免登录票据
|
||||
type AuthAppTicketController struct {
|
||||
beego.Controller
|
||||
}
|
||||
@@ -39,7 +28,6 @@ func (c *AuthAppTicketController) fail(msg string) {
|
||||
c.serveJSON(map[string]interface{}{"code": 400, "msg": msg})
|
||||
}
|
||||
|
||||
// ticketClaims 解析 Bearer 令牌;移动端是 user_type=app,Web 端是 backend
|
||||
func (c *AuthAppTicketController) ticketClaims() (*jwtutil.Claims, error) {
|
||||
header := c.Ctx.Request.Header.Get("Authorization")
|
||||
if header == "" {
|
||||
@@ -59,8 +47,6 @@ func (c *AuthAppTicketController) ticketClaims() (*jwtutil.Claims, error) {
|
||||
return claims, nil
|
||||
}
|
||||
|
||||
// Create POST /auth/app-ticket
|
||||
// 移动端用当前登录态换取一次性票据,Web 端拿票据换自己的令牌。
|
||||
func (c *AuthAppTicketController) Create() {
|
||||
claims, err := c.ticketClaims()
|
||||
if err != nil {
|
||||
@@ -75,7 +61,6 @@ func (c *AuthAppTicketController) Create() {
|
||||
if body := c.Ctx.Input.RequestBody; len(body) > 0 {
|
||||
_ = json.Unmarshal(body, &req)
|
||||
}
|
||||
// 票据是给 Web 端兑换用的,默认按 Web 端应用签发
|
||||
clientID := strings.TrimSpace(req.ClientID)
|
||||
if clientID == "" {
|
||||
clientID = "yz-backend"
|
||||
@@ -102,8 +87,6 @@ func (c *AuthAppTicketController) Create() {
|
||||
})
|
||||
}
|
||||
|
||||
// Exchange POST /auth/app-ticket/exchange
|
||||
// Web 端核销票据并换发本端令牌(无鉴权:票据本身即凭证,一次性 + 短时效)。
|
||||
func (c *AuthAppTicketController) Exchange() {
|
||||
body := c.Ctx.Input.RequestBody
|
||||
if len(body) == 0 {
|
||||
@@ -111,7 +94,7 @@ func (c *AuthAppTicketController) Exchange() {
|
||||
}
|
||||
var req struct {
|
||||
Ticket string `json:"ticket"`
|
||||
Token string `json:"token"` // 兼容 mp-login 的命名
|
||||
Token string `json:"token"`
|
||||
ClientID string `json:"client_id"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &req); err != nil {
|
||||
@@ -129,7 +112,6 @@ func (c *AuthAppTicketController) Exchange() {
|
||||
return
|
||||
}
|
||||
|
||||
// 身份校验:禁用/锁定的账号不签发
|
||||
var identity models.AuthIdentity
|
||||
if err := models.Orm.QueryTable(new(models.AuthIdentity)).
|
||||
Filter("id", row.IdentityID).
|
||||
@@ -156,7 +138,6 @@ func (c *AuthAppTicketController) Exchange() {
|
||||
clientID = "yz-backend"
|
||||
}
|
||||
|
||||
// 未确定企业(多企业)时签发待选令牌,由 Web 端展示企业选择
|
||||
tid := row.Tid
|
||||
needChoose := false
|
||||
if tid == 0 {
|
||||
@@ -192,11 +173,10 @@ func (c *AuthAppTicketController) Exchange() {
|
||||
c.serveJSON(map[string]interface{}{"code": 200, "msg": "登录成功", "data": data})
|
||||
}
|
||||
|
||||
// issueTicketTokens 建会话 + 签发令牌 + 登录日志(失败不影响主流程)
|
||||
func (c *AuthAppTicketController) issueTicketTokens(identityID, tid uint64, clientID, username string, needChoose bool) (*authsvc.TokenPair, error) {
|
||||
accessTTL := 0
|
||||
if needChoose {
|
||||
accessTTL = 600 // 待选状态令牌只够用户完成企业选择
|
||||
accessTTL = 600
|
||||
}
|
||||
sess, serr := authsvc.CreateSession(authsvc.SessionInfo{
|
||||
IdentityID: identityID,
|
||||
@@ -216,7 +196,7 @@ func (c *AuthAppTicketController) issueTicketTokens(identityID, tid uint64, clie
|
||||
ClientID: clientID,
|
||||
Sid: sess.Sid,
|
||||
Username: username,
|
||||
UserType: "backend", // Web 端业务接口普遍要求 backend
|
||||
UserType: "backend",
|
||||
Amr: "app_ticket",
|
||||
AccessTTL: accessTTL,
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user