更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -1,18 +1,5 @@
|
||||
package controllers
|
||||
|
||||
// ==================== 小程序新用户引导 ====================
|
||||
//
|
||||
// 新的工作台口径:不再区分「登录 / 免登录」。
|
||||
// 1. 点任意模块卡片 → 微信手机号授权;
|
||||
// 2. 手机号已存在 → 前端走 /auth/wechat/miniapp/login 静默登录(自动绑定 openid);
|
||||
// 不存在 → 本文件 Phone 签发注册票据,Register 收 ≥6 位密码后建号并绑定微信,
|
||||
// 同时签发 tid=0 的正式令牌(注册即登录,可直接使用原免登录模块);
|
||||
// 3. 进入需企业模块前,Status 查企业绑定 / 申请状态;未通过则走创建企业或挂靠企业;
|
||||
// 4. 两类申请复用 services 层已有的审核闭环(platform / backend 审批端无需改动)。
|
||||
//
|
||||
// 本组路由均为公开路径(不在 middleware.protectedPrefixes 内):
|
||||
// phone / register 由微信凭证与一次性注册票据自证,其余端点自行校验 Bearer 令牌。
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
@@ -64,7 +51,6 @@ func (c *OnboardingController) readJSON(v interface{}) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// claims 当前登录态;允许 tid=0(刚注册、尚未加入企业)的正式令牌。
|
||||
func (c *OnboardingController) claims() (*jwtutil.Claims, error) {
|
||||
return identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndApp)
|
||||
}
|
||||
@@ -78,9 +64,6 @@ func (c *OnboardingController) mustClaims() *jwtutil.Claims {
|
||||
return cl
|
||||
}
|
||||
|
||||
// Phone POST /api/onboarding/phone
|
||||
// body: { code(wx.login), phone_code(getPhoneNumber), appid? }
|
||||
// 返回 exists / need_register;无账号时附带一次性 register_token(内含微信手机号与 openid)。
|
||||
func (c *OnboardingController) Phone() {
|
||||
var req struct {
|
||||
Code string `json:"code"`
|
||||
@@ -114,7 +97,6 @@ func (c *OnboardingController) Phone() {
|
||||
return
|
||||
}
|
||||
|
||||
// 已注册:交给前端用现有小程序一键登录静默登录(自动补绑 openid)
|
||||
if exist := identityByPhone(mobile); exist != nil {
|
||||
c.ok(map[string]interface{}{
|
||||
"exists": true,
|
||||
@@ -124,7 +106,6 @@ func (c *OnboardingController) Phone() {
|
||||
return
|
||||
}
|
||||
|
||||
// 注册必须同时绑定微信号:拿不到 openid 时不签发注册票据,避免留下「无绑定」账号
|
||||
session := guestMiniSession(cfg, req.Code)
|
||||
if session == nil || strings.TrimSpace(session.OpenID) == "" {
|
||||
c.fail(400, "微信身份获取失败,请重新进入小程序授权")
|
||||
@@ -148,9 +129,6 @@ func (c *OnboardingController) Phone() {
|
||||
})
|
||||
}
|
||||
|
||||
// Register POST /api/onboarding/register
|
||||
// body: { register_token, password, confirm_password }
|
||||
// 密码最少 6 位;复用 CompleteRegister 建号 + 绑定微信,随后签发 tid=0 正式令牌。
|
||||
func (c *OnboardingController) Register() {
|
||||
var req struct {
|
||||
Token string `json:"register_token"`
|
||||
@@ -206,7 +184,6 @@ func (c *OnboardingController) Register() {
|
||||
c.fail(400, err.Error())
|
||||
return
|
||||
}
|
||||
// 注册会话一次性使用:账号已建,后续申请凭 Bearer 令牌
|
||||
_, _ = models.Orm.QueryTable(new(models.AuthRegisterSession)).Filter("token", tk).Delete()
|
||||
|
||||
tokens, terr := c.issueNoTenantTokens(identityID, session.Mobile)
|
||||
@@ -222,8 +199,6 @@ func (c *OnboardingController) Register() {
|
||||
})
|
||||
}
|
||||
|
||||
// issueNoTenantTokens 注册即登录:签发 tid=0、userType=app 的正式令牌。
|
||||
// /api/home 对 tid=0 返回公开模块与公开菜单,因此原「免登录」功能可直接使用。
|
||||
func (c *OnboardingController) issueNoTenantTokens(identityID uint64, mobile string) (*authsvc.TokenPair, error) {
|
||||
sess, err := authsvc.CreateSession(authsvc.SessionInfo{
|
||||
IdentityID: identityID,
|
||||
@@ -248,10 +223,6 @@ func (c *OnboardingController) issueNoTenantTokens(identityID uint64, mobile str
|
||||
})
|
||||
}
|
||||
|
||||
// Status GET /api/onboarding/status
|
||||
// 返回已绑定企业列表、申请记录、微信手机号(前端只读展示)。
|
||||
// 「我的 → 企业绑定」用 tenants + applies 展示多租户与审核进度;
|
||||
// apply 保留最新一条,兼容首次加入企业的工作台分流逻辑。
|
||||
func (c *OnboardingController) Status() {
|
||||
cl := c.mustClaims()
|
||||
if cl == nil {
|
||||
@@ -266,7 +237,6 @@ func (c *OnboardingController) Status() {
|
||||
mobile = *ai.Mobile
|
||||
}
|
||||
|
||||
// 一人多企业:返回全部启用中的绑定,默认企业排在最前
|
||||
var binds []models.AuthTenantUser
|
||||
_, _ = models.Orm.QueryTable(new(models.AuthTenantUser)).
|
||||
Filter("identity_id", identityID).
|
||||
@@ -291,7 +261,6 @@ func (c *OnboardingController) Status() {
|
||||
tid = binds[0].Tid
|
||||
}
|
||||
|
||||
// 最近 20 条申请:可同时存在多家企业的待审绑定申请
|
||||
var rows []models.AuthTenantApply
|
||||
_, _ = models.Orm.QueryTable(new(models.AuthTenantApply)).
|
||||
Filter("identity_id", identityID).
|
||||
@@ -329,8 +298,6 @@ func (c *OnboardingController) Status() {
|
||||
})
|
||||
}
|
||||
|
||||
// Tenants GET /api/onboarding/tenants?keyword=xxx
|
||||
// 挂靠企业:按企业全称搜索启用中的企业(复用注册页的企业联想)。
|
||||
func (c *OnboardingController) Tenants() {
|
||||
items, err := services.SearchTenantsForRegister(c.GetString("keyword"))
|
||||
if err != nil {
|
||||
@@ -340,8 +307,6 @@ func (c *OnboardingController) Tenants() {
|
||||
c.ok(map[string]interface{}{"list": items})
|
||||
}
|
||||
|
||||
// Departments GET /api/onboarding/departments?tid=xxx
|
||||
// 公开下拉:按企业返回组织(部门)列表。挂靠时用户尚未加入该企业,故不走 /backend 鉴权接口。
|
||||
func (c *OnboardingController) Departments() {
|
||||
tid := c.uintParam("tid")
|
||||
if tid == 0 {
|
||||
@@ -368,7 +333,6 @@ func (c *OnboardingController) Departments() {
|
||||
c.ok(map[string]interface{}{"list": list})
|
||||
}
|
||||
|
||||
// Positions GET /api/onboarding/positions?tid=xxx&department_id=xxx
|
||||
func (c *OnboardingController) Positions() {
|
||||
tid := c.uintParam("tid")
|
||||
if tid == 0 {
|
||||
@@ -396,16 +360,11 @@ func (c *OnboardingController) Positions() {
|
||||
c.ok(map[string]interface{}{"list": list})
|
||||
}
|
||||
|
||||
// ApplyJoin POST /api/onboarding/apply-join
|
||||
// body: { tid, applicant_name, department_id, department_name, position_id, position_name }
|
||||
// 手机号不接受前端传值:由后端从微信验证过的身份手机号写入 wechat_mobile。
|
||||
func (c *OnboardingController) ApplyJoin() {
|
||||
cl := c.mustClaims()
|
||||
if cl == nil {
|
||||
return
|
||||
}
|
||||
// 一人可绑定多家企业:已加入企业也能继续申请绑定其他企业。
|
||||
// 「是否已绑定该企业 / 是否重复待审」由 CreateJoinApply 内部按 tid 判定。
|
||||
var req struct {
|
||||
Tid uint64 `json:"tid"`
|
||||
ApplicantName string `json:"applicant_name"`
|
||||
@@ -434,21 +393,17 @@ func (c *OnboardingController) ApplyJoin() {
|
||||
c.fail(400, err.Error())
|
||||
return
|
||||
}
|
||||
// 微信手机号单独落库,避免被表单联系人字段覆盖
|
||||
_, _ = models.Orm.QueryTable(new(models.AuthTenantApply)).
|
||||
Filter("id", apply.ID).
|
||||
Update(map[string]interface{}{"wechat_mobile": mobile})
|
||||
c.ok(map[string]interface{}{"apply_id": apply.ID, "status": apply.Status})
|
||||
}
|
||||
|
||||
// ApplyCreate POST /api/onboarding/apply-create
|
||||
// 沿用 PC 注册页的完整字段与校验(信用代码 18 位、营业执照、法人、联系人、电话、邮箱必填)。
|
||||
func (c *OnboardingController) ApplyCreate() {
|
||||
cl := c.mustClaims()
|
||||
if cl == nil {
|
||||
return
|
||||
}
|
||||
// 多租户:已有企业也允许再创建一家(同身份只允许一条待审创建申请,由 CreateTenantApply 校验)
|
||||
var req services.TenantCreateApplyInput
|
||||
if !c.readJSON(&req) {
|
||||
return
|
||||
|
||||
Reference in new issue
Block a user