切换导航条
此项目
正在载入...
登录
mmm-go
/
partnermg
·
提交
转到一个项目
GitLab
转到群组
项目
活动
文件
提交
管道
0
构建
0
图表
里程碑
问题
0
合并请求
0
成员
标记
维基
派生
网络
创建新的问题
下载为
邮件补丁
差异文件
浏览文件
作者
唐旭辉
5 years ago
提交
4258661630fce9d18d29c3d3a62db1b8fe83ff3d
1 个父辈
20ff4c6f
日常提交保存
隐藏空白字符变更
内嵌
并排对比
正在显示
11 个修改的文件
包含
200 行增加
和
36 行删除
pkg/application/adminUser/command/admin_user_login.go
pkg/application/adminUser/service/admin_user.go
pkg/application/unifiedUserCenter/service/employee.go
pkg/application/users/command/admin_user_login.go
pkg/application/users/service/service.go
pkg/infrastructure/repository/pg_users_repository.go
pkg/infrastructure/service_gateway/httplib_usercenter_service.go → pkg/infrastructure/serviceGateway/httplib_usercenter_service.go
pkg/infrastructure/service_gateway/httplib_service_gateway.go
pkg/port/beego/controllers/admin_login_controller.go
pkg/port/beego/controllers/base_controller.go
pkg/port/beego/routers/router.go
pkg/application/adminUser/command/admin_user_login.go
0 → 100644
查看文件 @
4258661
package
command
import
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
type
LoginBySecretKeyCommand
struct
{
Secret
string
`json:"secret"`
}
func
(
login
LoginBySecretKeyCommand
)
ValidateCommand
()
error
{
if
len
(
login
.
Secret
)
==
0
{
return
lib
.
ThrowError
(
lib
.
ARG_ERROR
,
"登录参数错误"
)
}
return
nil
}
...
...
pkg/application/adminUser/service/admin_user.go
查看文件 @
4258661
...
...
@@ -257,13 +257,13 @@ func (adminUserSrv AdminUserService) UpdateAdminIsUsable(uid int64, isUsable boo
adminuserDao
=
v
}
if
ok
,
err
:=
adminuserDao
.
AdminUserIsDefault
(
uid
);
err
!=
nil
{
return
lib
.
ThrowError
(
lib
.
TRANSACTION
_ERROR
,
err
.
Error
())
return
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER
_ERROR
,
err
.
Error
())
}
else
if
ok
{
return
lib
.
ThrowError
(
lib
.
BUSINESS_ERROR
,
"请勿禁用超级管理员"
)
}
err
=
adminuserDao
.
UpdateIsUsable
(
uid
,
isUsable
)
if
err
!=
nil
{
return
lib
.
ThrowError
(
lib
.
TRANSACTION
_ERROR
,
err
.
Error
())
return
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER
_ERROR
,
err
.
Error
())
}
transactionContext
.
CommitTransaction
()
return
nil
...
...
pkg/application/unifiedUserCenter/service/employee.go
查看文件 @
4258661
...
...
@@ -362,7 +362,6 @@ func (service SyncEmployeeService) ChangeSuperAdmin(cmd command.ChanceSuperAdmin
if
err
!=
nil
{
return
lib
.
ThrowError
(
lib
.
BUSINESS_ERROR
,
err
.
Error
())
}
//提取到domain???
err
=
newSuperUser
.
Update
(
map
[
string
]
interface
{}{
"AdminType"
:
domain
.
UserIsAdmin
,
})
...
...
pkg/application/users/command/admin_user_login.go
0 → 100644
查看文件 @
4258661
package
command
import
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
type
LoginBySecretKeyCommand
struct
{
Secret
string
`json:"secret"`
}
func
(
login
LoginBySecretKeyCommand
)
ValidateCommand
()
error
{
if
len
(
login
.
Secret
)
==
0
{
return
lib
.
ThrowError
(
lib
.
ARG_ERROR
,
"登录参数错误"
)
}
return
nil
}
...
...
pkg/application/users/service/service.go
0 → 100644
查看文件 @
4258661
package
service
import
(
"fmt"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/factory"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/users/command"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/infrastructure/serviceGateway"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
type
UsersService
struct
{
}
func
NewUsersService
(
option
map
[
string
]
interface
{})
*
UsersService
{
newUsersService
:=
new
(
UsersService
)
return
newUsersService
}
func
(
service
UsersService
)
UserLoginBySecretKey
(
cmd
command
.
LoginBySecretKeyCommand
)
(
interface
{},
error
)
{
var
err
error
if
err
=
cmd
.
ValidateCommand
();
err
!=
nil
{
return
nil
,
err
}
//向统一用户中心确认密钥信息并获取用户数据
ucenterService
:=
serviceGateway
.
NewMmmUserCenterServiceGateway
()
loginResp
,
err
:=
ucenterService
.
RequestUCenterLoginBySecret
(
cmd
.
Secret
)
if
err
!=
nil
{
e
:=
fmt
.
Sprintf
(
"通过密钥(secret=%s)从统一用户中心获取数据失败:%s"
,
cmd
.
Secret
,
err
.
Error
())
return
nil
,
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
e
)
}
var
(
transactionContext
,
_
=
factory
.
CreateTransactionContext
(
nil
)
)
if
err
=
transactionContext
.
StartTransaction
();
err
!=
nil
{
return
nil
,
lib
.
ThrowError
(
lib
.
TRANSACTION_ERROR
,
err
.
Error
())
}
defer
func
()
{
transactionContext
.
RollbackTransaction
()
}()
var
(
companyRespository
domain
.
CompanyRepository
userRespository
domain
.
UsersRepository
companyData
domain
.
Company
usersData
domain
.
Users
)
if
companyRespository
,
err
=
factory
.
CreateCompanyRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
,
});
err
!=
nil
{
return
nil
,
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
if
userRespository
,
err
=
factory
.
CreateUsersRepository
(
map
[
string
]
interface
{}{
"transactionContext"
:
transactionContext
,
});
err
!=
nil
{
return
nil
,
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
err
.
Error
())
}
//检索本系统的公司数据判断公司权限
companyData
,
err
=
companyRespository
.
FindOne
(
map
[
string
]
interface
{}{
"Id"
:
loginResp
.
Data
.
Muid
,
})
if
err
!=
nil
{
e
:=
fmt
.
Sprintf
(
"获取公司(id=%d)数据失败:%s"
,
loginResp
.
Data
.
Muid
,
err
.
Error
())
return
nil
,
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
e
)
}
if
!
companyData
.
EnableIsOk
()
{
return
nil
,
lib
.
ThrowError
(
lib
.
BUSINESS_ERROR
,
"该公司没有操作权限"
)
}
//检索本系统的用户数据
usersData
,
err
=
userRespository
.
FindOne
(
map
[
string
]
interface
{}{
"OpenId"
:
loginResp
.
Data
.
Id
,
"CompanyId"
:
companyData
.
Id
,
})
if
err
!=
nil
{
e
:=
fmt
.
Sprintf
(
"获取用户(OpenId=%d;CompanyId=%d)数据失败:%s"
,
loginResp
.
Data
.
Id
,
companyData
.
Id
,
err
.
Error
())
return
nil
,
lib
.
ThrowError
(
lib
.
INTERNAL_SERVER_ERROR
,
e
)
}
//确认用户权限
if
!
usersData
.
IsUsable
()
{
return
nil
,
lib
.
ThrowError
(
lib
.
BUSINESS_ERROR
,
"用户被禁用"
)
}
err
=
transactionContext
.
CommitTransaction
()
//生成token
return
nil
,
nil
}
//GetAdminpPofile 登录后获取用户的权限配置数据
func
(
service
UsersService
)
GetAdminpPofile
()
(
interface
{},
error
)
{
return
nil
,
nil
}
//ValidateAdminpPermission 校验用户的操作权限
func
(
service
UsersService
)
ValidateAdminpPermission
()
(
interface
{},
error
)
{
return
nil
,
nil
}
...
...
pkg/infrastructure/repository/pg_users_repository.go
查看文件 @
4258661
...
...
@@ -125,9 +125,15 @@ func (reponsitory UsersRepository) FindOne(queryOptions map[string]interface{})
if
v
,
ok
:=
queryOptions
[
"Id"
];
ok
{
query
=
query
.
Where
(
"id=?"
,
v
)
}
if
v
,
ok
:=
queryOptions
[
"
p
hone"
];
ok
{
if
v
,
ok
:=
queryOptions
[
"
P
hone"
];
ok
{
query
=
query
.
Where
(
"phone=?"
,
v
)
}
if
v
,
ok
:=
queryOptions
[
"CompanyId"
];
ok
{
query
=
query
.
Where
(
"company_id=?"
,
v
)
}
if
v
,
ok
:=
queryOptions
[
"OpenId"
];
ok
{
query
=
query
.
Where
(
"open_id=?"
,
v
)
}
err
=
query
.
First
()
if
err
!=
nil
{
return
domain
.
Users
{},
err
...
...
pkg/infrastructure/service
_g
ateway/httplib_usercenter_service.go → pkg/infrastructure/service
G
ateway/httplib_usercenter_service.go
查看文件 @
4258661
package
service
_g
ateway
package
service
G
ateway
import
(
"bytes"
...
...
@@ -79,8 +79,8 @@ func (gateway MmmUserCenterServiceGateway) httpDo(reqURL string, mathod string,
type
ResponseLogin
struct
{
UCenterCommonMsg
Data
struct
{
Id
int64
`json:"id"`
//统一用户中心的id,对应本系统中users表的open_id
Phone
string
`json:"phone"`
Id
int64
`json:"id"`
//统一用户中心的id,对应本系统中users表的open_id
Phone
string
`json:"phone"`
//手机号 ,账号
NickName
string
`json:"nickname"`
//昵称
Avatar
string
`json:"avatar"`
//头像
Imtoken
string
`json:"imtoken"`
//网易云imtoken
...
...
pkg/infrastructure/service_gateway/httplib_service_gateway.go
已删除
100644 → 0
查看文件 @
20ff4c6
package
service_gateway
import
(
"time"
)
type
httplibBaseServiceGateway
struct
{
baseURL
string
connectTimeout
time
.
Duration
readWriteTimeout
time
.
Duration
}
pkg/port/beego/controllers/admin_login_controller.go
查看文件 @
4258661
...
...
@@ -6,8 +6,6 @@ import (
"fmt"
"time"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
"github.com/GeeTeam/gt3-golang-sdk/geetest"
"github.com/astaxie/beego/logs"
adminPermissionquery
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminPermission/query"
...
...
@@ -15,6 +13,7 @@ import (
adminuserCmd
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/command"
adminuserquery
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/query"
adminuserservice
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/application/adminUser/service"
"gitlab.fjmaimaimai.com/mmm-go/partnermg/pkg/lib"
)
type
AdminLoginController
struct
{
...
...
@@ -40,6 +39,52 @@ func (c *AdminLoginController) Prepare() {
}
//Login 用户登录
// func (c *AdminLoginController) Login() {
// type Paramter struct {
// Username string `json:"username"`
// Password string `json:"password"`
// }
// var (
// param Paramter
// err error
// )
// if err = c.BindJsonData(¶m); err != nil {
// c.ResponseError(fmt.Errorf("json解析失败:%s", err))
// return
// }
// newAdminuserquery := adminuserquery.GetAdminUserQuery{AdminAccount: param.Username}
// newAdminUserService := adminuserservice.NewAdminUserService(nil)
// adminuser, err := newAdminUserService.GetAdminUser(&newAdminuserquery)
// if err != nil {
// logs.Error("获取用户数据失败:%s", err)
// c.ResponseError(errors.New("用户不存在"))
// return
// }
// if adminuser.Password != param.Password {
// c.ResponseError(errors.New("账号或密码错误"))
// return
// }
// if !adminuser.IsUsable {
// c.ResponseError(errors.New("用户被禁用"))
// }
// //TODO
// newJwt := lib.NewMyToken(adminuser.Id, 0)
// newToken, err := newJwt.CreateJWTToken()
// if err != nil {
// logs.Error("生成jwt数据失败:%s", err)
// c.ResponseError(errors.New("服务异常"))
// return
// }
// rspdata := map[string]interface{}{
// "access": map[string]interface{}{
// "accessToken": newToken,
// "expiresIn": lib.JWtExpiresSecond,
// },
// }
// c.ResponseData(rspdata)
// return
// }
func
(
c
*
AdminLoginController
)
Login
()
{
type
Paramter
struct
{
Username
string
`json:"username"`
...
...
@@ -55,21 +100,9 @@ func (c *AdminLoginController) Login() {
}
newAdminuserquery
:=
adminuserquery
.
GetAdminUserQuery
{
AdminAccount
:
param
.
Username
}
newAdminUserService
:=
adminuserservice
.
NewAdminUserService
(
nil
)
adminuser
,
err
:=
newAdminUserService
.
GetAdminUser
(
&
newAdminuserquery
)
if
err
!=
nil
{
logs
.
Error
(
"获取用户数据失败:%s"
,
err
)
c
.
ResponseError
(
errors
.
New
(
"用户不存在"
))
return
}
if
adminuser
.
Password
!=
param
.
Password
{
c
.
ResponseError
(
errors
.
New
(
"账号或密码错误"
))
return
}
if
!
adminuser
.
IsUsable
{
c
.
ResponseError
(
errors
.
New
(
"用户被禁用"
))
}
//TODO
newJwt
:=
lib
.
NewMyToken
(
adminuser
.
Id
,
0
)
_
=
newAdminuserquery
_
=
newAdminUserService
newJwt
:=
lib
.
NewMyToken
(
0
,
0
)
newToken
,
err
:=
newJwt
.
CreateJWTToken
()
if
err
!=
nil
{
logs
.
Error
(
"生成jwt数据失败:%s"
,
err
)
...
...
pkg/port/beego/controllers/base_controller.go
查看文件 @
4258661
...
...
@@ -144,6 +144,7 @@ func (controller *BaseController) ValidJWTToken() bool {
return
false
}
controller
.
setUserId
(
tokenData
.
UID
)
controller
.
setUserCompanyId
(
tokenData
.
CompanyId
)
return
true
}
...
...
@@ -196,3 +197,14 @@ func (controller *BaseController) setUserId(id int64) {
logs
.
Info
(
"token:admin_user_id = "
,
id
)
controller
.
Ctx
.
Input
.
SetData
(
"token:admin_user_id"
,
id
)
}
func
(
controller
*
BaseController
)
setUserCompanyId
(
id
int64
)
{
logs
.
Info
(
"token:company_id = "
,
id
)
controller
.
Ctx
.
Input
.
SetData
(
"token:company_id"
,
id
)
}
func
(
controller
*
BaseController
)
GetUserCompany
()
int64
{
idV
:=
controller
.
Ctx
.
Input
.
GetData
(
"token:company_id"
)
uid
,
_
:=
strconv
.
ParseInt
(
fmt
.
Sprint
(
idV
),
10
,
64
)
return
uid
}
...
...
pkg/port/beego/routers/router.go
查看文件 @
4258661
...
...
@@ -11,7 +11,7 @@ func init() {
beego
.
NSRouter
(
"/login"
,
&
controllers
.
AdminLoginController
{},
"POST:Login"
),
beego
.
NSRouter
(
"/captcha-init"
,
&
controllers
.
AdminLoginController
{},
"POST:CaptchaInit"
),
beego
.
NSRouter
(
"/profile"
,
&
controllers
.
AdminLoginController
{},
"POST:AdminpPofile"
),
beego
.
NSRouter
(
"/pwd-update"
,
&
controllers
.
AdminLoginController
{},
"POST:PwdUpdate"
),
//
beego.NSRouter("/pwd-update", &controllers.AdminLoginController{}, "POST:PwdUpdate"),
),
beego
.
NSNamespace
(
"/admin"
,
beego
.
NSRouter
(
"/update"
,
&
controllers
.
AdminUserController
{},
"POST:SaveAdminUser"
),
...
...
请
注册
或
登录
后发表评论