作者 yangfu

登录修改

... ... @@ -10,13 +10,17 @@ info(
// 通用接口
@server(
prefix: v1/common
prefix: v1
group: common
)
service Core {
@doc "短信验证码"
@handler commonSmsCode
post /sms/code (CommonSmsCodeRequest) returns (CommonSmsCodeResposne)
post /common/sms/code (CommonSmsCodeRequest) returns (CommonSmsCodeResposne)
@doc "日志查询"
@handler commonGetLog
get /log/:module
}
// 短信验证码
... ...
... ... @@ -98,7 +98,7 @@ type(
//MyStatisticsFlag bool `json:"myStatisticsFlag"` // true:返回统计信息 false;统计信息不返回
}
MiniUserInfoResponse {
User *UserItem `json:"user,omitempty"` // 用户信息
User *UserItem `json:"user,omitempty"` // 用户信息
Accounts []Account `json:"accounts"` // 公司账号
Auths []Auth `json:"auths"` // 权限列表
}
... ... @@ -108,7 +108,7 @@ type(
IsFromQr bool `json:"isFromQr,optional"` // true:扫码添加 false:手动查找添加
}
MiniUserApplyJoinCompanyResponse{
Token string `json:"token"` // x-token
}
MiniUserAuditRequest{
UserId int64 `json:"userId"` // 用户ID
... ... @@ -160,6 +160,7 @@ type(
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
CompanyName string `json:"companyName,omitempty"` // 公司名称
CompanyCode string `json:"companyCode,omitempty"` // 公司编码(邀请码)
CompanyLogo *string `json:"companyLogo,omitempty"` // 公司LOGO
//DepartmentId int64 `json:"departmentId,omitempty"` // 部门ID
//Roles []int64 `json:"roleId,omitempty"` // 角色
Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员)
... ...
... ... @@ -7,7 +7,7 @@ Timeout: 30000
# CertFile: ./key/fjmaimaimai.com_bundle.crt
# KeyFile: ./key/fjmaimaimai.com.key
Log:
#Mode: file
Mode: file
Encoding: plain
Level: debug # info
MaxSize: 1 # 2MB
... ...
package common
import (
"net/http"
"path/filepath"
"strings"
"github.com/zeromicro/go-zero/rest/httpx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
)
func CommonGetLogHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req struct {
Module string `path:"module"`
}
if err := httpx.Parse(r, &req); err != nil {
httpx.ErrorCtx(r.Context(), w, err)
return
}
path := svcCtx.Config.Log.Path
if svcCtx.Config.Log.Mode != "file" {
return
}
if path == "" {
path = "logs"
}
if !strings.HasSuffix(req.Module, ".log") {
req.Module += ".log"
}
handler := http.FileServer(http.Dir(path))
r.URL.Path = filepath.Join(req.Module)
handler.ServeHTTP(w, r)
}
}
... ...
... ... @@ -23,11 +23,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
[]rest.Route{
{
Method: http.MethodPost,
Path: "/sms/code",
Path: "/common/sms/code",
Handler: common.CommonSmsCodeHandler(serverCtx),
},
{
Method: http.MethodGet,
Path: "/log/:module",
Handler: common.CommonGetLogHandler(serverCtx),
},
},
rest.WithPrefix("/v1/common"),
rest.WithPrefix("/v1"),
)
server.AddRoutes(
... ...
package common
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
)
type CommonGetLogLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewCommonGetLogLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CommonGetLogLogic {
return &CommonGetLogLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *CommonGetLogLogic) CommonGetLog() error {
// todo: add your logic here and delete this line
return nil
}
... ...
package message
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniCommentLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniCommentLogic {
return &MiniCommentLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniCommentLogic) MiniComment(req *types.MessageRequest) (resp *types.MessageBusinessResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
package message
import (
"context"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type MiniLikeLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewMiniLikeLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniLikeLogic {
return &MiniLikeLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *MiniLikeLogic) MiniLike(req *types.MessageRequest) (resp *types.MessageBusinessResponse, err error) {
// todo: add your logic here and delete this line
return
}
... ...
... ... @@ -35,6 +35,7 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini
company *domain.Company
user *domain.User
name = fmt.Sprintf("用户%s", tool.Krand(6, tool.KC_RAND_KIND_NUM))
token string
)
if company, err = l.svcCtx.CompanyRepository.FindOneByCode(l.ctx, conn, req.Code); err != nil {
return nil, xerr.NewErrMsgErr("公司不存在", err)
... ... @@ -48,12 +49,14 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini
return nil, xerr.NewErrMsgErr("申请失败", err)
}
if user != nil {
if user.AuditStatus == domain.UserAuditStatusWait {
return nil, xerr.NewErrMsgErr("已申请,待审核中", err)
token, err = generateToken(l.svcCtx, user)
if err != nil {
return nil, xerr.NewErrMsgErr("登录失败", err)
}
if user.AuditStatus == domain.UserAuditStatusPassed {
return nil, xerr.NewErrMsgErr("公司已申请", err)
resp = &types.MiniUserApplyJoinCompanyResponse{
Token: token,
}
return
}
queryOptions := domain.NewQueryOptions().
WithOffsetLimit(1, 1).
... ... @@ -87,6 +90,12 @@ func (l *MiniUserApplyJoinCompanyLogic) MiniUserApplyJoinCompany(req *types.Mini
}, true); err != nil {
return nil, xerr.NewErrMsgErr("申请失败", err)
}
resp = &types.MiniUserApplyJoinCompanyResponse{}
token, err = generateToken(l.svcCtx, user)
if err != nil {
return nil, xerr.NewErrMsgErr("登录失败", err)
}
resp = &types.MiniUserApplyJoinCompanyResponse{
Token: token,
}
return
}
... ...
... ... @@ -2,6 +2,7 @@ package user
import (
"context"
"github.com/samber/lo"
"github.com/zeromicro/go-zero/core/collection"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain"
"gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata"
... ... @@ -45,10 +46,12 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp *
resp = &types.MiniUserInfoResponse{
User: &types.UserItem{
Id: user.Id,
Name: user.Name,
Avatar: user.Avatar,
Position: user.Position,
Id: user.Id,
Name: user.Name,
Avatar: user.Avatar,
Position: user.Position,
AuditStatus: lo.ToPtr(user.AuditStatus),
Enable: user.Enable,
},
Accounts: make([]types.Account, 0),
Auths: make([]types.Auth, 0),
... ... @@ -56,6 +59,7 @@ func (l *MiniUserInfoLogic) MiniUserInfo(req *types.MiniUserInfoRequest) (resp *
if company, _ := domain.LazyLoad(companyMap, l.ctx, conn, user.CompanyId, l.svcCtx.CompanyRepository.FindOne); company != nil {
resp.User.CompanyName = company.Name
resp.User.CompanyCode = company.Code
resp.User.CompanyLogo = lo.ToPtr(company.Logo)
}
_, accounts, err = l.svcCtx.UserRepository.Find(l.ctx, conn, domain.NewQueryOptions().MustWithKV("phone", user.Phone).MustWithKV("auditStatus", []int{domain.UserAuditStatusPassed}))
if err != nil {
... ...
... ... @@ -53,13 +53,7 @@ func (l *MiniUserLoginLogic) MiniUserLogin(req *types.MiniUserLoginRequest) (res
if loginInfo.User == nil {
return nil, xerr.NewErrMsgErr("用户不存在", err)
}
var userJwtToken = tool.UserToken{}
if loginInfo.User != nil {
userJwtToken.UserId = loginInfo.User.Id
userJwtToken.CompanyId = loginInfo.User.CompanyId
userJwtToken.ClientType = "mini"
}
token, err = userJwtToken.GenerateToken(l.svcCtx.Config.MiniAuth.AccessSecret, l.svcCtx.Config.MiniAuth.AccessExpire)
token, err = generateToken(l.svcCtx, loginInfo.User)
if err != nil {
return nil, xerr.NewErrMsgErr("登录失败", err)
}
... ... @@ -74,6 +68,20 @@ func (l *MiniUserLoginLogic) MiniUserLogin(req *types.MiniUserLoginRequest) (res
return
}
func generateToken(svcCtx *svc.ServiceContext, user *domain.User) (token string, err error) {
var userJwtToken = tool.UserToken{}
if user != nil {
userJwtToken.UserId = user.Id
userJwtToken.CompanyId = user.CompanyId
userJwtToken.ClientType = "mini"
}
token, err = userJwtToken.GenerateToken(svcCtx.Config.MiniAuth.AccessSecret, svcCtx.Config.MiniAuth.AccessExpire)
if err != nil {
return "", xerr.NewErrMsgErr("登录失败", err)
}
return
}
type WxClientLogin struct {
l *MiniUserLoginLogic
}
... ...
... ... @@ -439,6 +439,7 @@ type MiniUserApplyJoinCompanyRequest struct {
}
type MiniUserApplyJoinCompanyResponse struct {
Token string `json:"token"` // x-token
}
type MiniUserAuditRequest struct {
... ... @@ -498,6 +499,7 @@ type UserItem struct {
CompanyId int64 `json:"companyId,omitempty"` // 公司ID
CompanyName string `json:"companyName,omitempty"` // 公司名称
CompanyCode string `json:"companyCode,omitempty"` // 公司编码(邀请码)
CompanyLogo *string `json:"companyLogo,omitempty"` // 公司LOGO
Flag int `json:"flag,omitempty"` // 标识 1:管理员 2:普通用户 (有绑定角色是管理员)
Name string `json:"name,omitempty"` // 名称
Avatar string `json:"avatar,omitempty"` // 头像
... ...