mirror of
				https://github.com/TeaOSLab/EdgeAPI.git
				synced 2025-11-04 16:00:24 +08:00 
			
		
		
		
	增加通过管理员用户名查找管理员信息的API
This commit is contained in:
		@@ -130,6 +130,19 @@ func (this *AdminDAO) FindAdminIdWithUsername(tx *dbs.Tx, username string) (int6
 | 
			
		||||
	return int64(one.(*Admin).Id), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindAdminWithUsername 根据用户名查询管理员信息
 | 
			
		||||
func (this *AdminDAO) FindAdminWithUsername(tx *dbs.Tx, username string) (*Admin, error) {
 | 
			
		||||
	one, err := this.Query(tx).
 | 
			
		||||
		Attr("username", username).
 | 
			
		||||
		State(AdminStateEnabled).
 | 
			
		||||
		ResultPk().
 | 
			
		||||
		Find()
 | 
			
		||||
	if err != nil || one == nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	return one.(*Admin), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// UpdateAdminPassword 更改管理员密码
 | 
			
		||||
func (this *AdminDAO) UpdateAdminPassword(tx *dbs.Tx, adminId int64, password string) error {
 | 
			
		||||
	if adminId <= 0 {
 | 
			
		||||
@@ -212,7 +225,7 @@ func (this *AdminDAO) UpdateAdmin(tx *dbs.Tx, adminId int64, username string, ca
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// CheckAdminUsername 检查用户名是否存在
 | 
			
		||||
// CheckAdminUsername 检查管理员用户名是否存在
 | 
			
		||||
func (this *AdminDAO) CheckAdminUsername(tx *dbs.Tx, adminId int64, username string) (bool, error) {
 | 
			
		||||
	query := this.Query(tx).
 | 
			
		||||
		State(AdminStateEnabled).
 | 
			
		||||
 
 | 
			
		||||
@@ -104,6 +104,39 @@ func (this *AdminService) CheckAdminUsername(ctx context.Context, req *pb.CheckA
 | 
			
		||||
	return &pb.CheckAdminUsernameResponse{Exists: exists}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindAdminWithUsername 使用用管理员户名查找管理员信息
 | 
			
		||||
func (this *AdminService) FindAdminWithUsername(ctx context.Context, req *pb.FindAdminWithUsernameRequest) (*pb.FindAdminWithUsernameResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
	_, err := this.ValidateAdmin(ctx)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var tx = this.NullTx()
 | 
			
		||||
 | 
			
		||||
	if len(req.Username) == 0 {
 | 
			
		||||
		return nil, errors.New("require 'username'")
 | 
			
		||||
	}
 | 
			
		||||
	admin, err := models.SharedAdminDAO.FindAdminWithUsername(tx, req.Username)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
	}
 | 
			
		||||
	if admin == nil {
 | 
			
		||||
		return &pb.FindAdminWithUsernameResponse{Admin: nil}, nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return &pb.FindAdminWithUsernameResponse{
 | 
			
		||||
		Admin: &pb.Admin{
 | 
			
		||||
			Id:       int64(admin.Id),
 | 
			
		||||
			Fullname: admin.Fullname,
 | 
			
		||||
			Username: admin.Username,
 | 
			
		||||
			IsOn:     admin.IsOn,
 | 
			
		||||
			IsSuper:  admin.IsSuper,
 | 
			
		||||
			CanLogin: admin.CanLogin,
 | 
			
		||||
		},
 | 
			
		||||
	}, nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// FindAdminFullname 获取管理员名称
 | 
			
		||||
func (this *AdminService) FindAdminFullname(ctx context.Context, req *pb.FindAdminFullnameRequest) (*pb.FindAdminFullnameResponse, error) {
 | 
			
		||||
	// 校验请求
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user