修复若干问题 (#229)
* 优化图标和LOGO * 修改登录页面动画的速度为3 * 增加对websocket的异常处理 * 修复了用户组和用户名唯一判断错误的问题 * 提示版本号
This commit is contained in:
@ -62,9 +62,8 @@ func (userApi UserApi) UserUpdateEndpoint(c echo.Context) error {
|
|||||||
if err := c.Bind(&item); err != nil {
|
if err := c.Bind(&item); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
item.ID = id
|
|
||||||
|
|
||||||
if err := repository.UserRepository.Update(context.TODO(), &item); err != nil {
|
if err := service.UserService.UpdateUser(id, item); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Version = "v1.2.4"
|
Version = "v1.2.5"
|
||||||
Banner = `
|
Banner = `
|
||||||
_______ __ ___________ .__ .__
|
_______ __ ___________ .__ .__
|
||||||
\ \ ____ ___ ____/ |_ \__ ___/__________ _____ |__| ____ _____ | |
|
\ \ ____ ___ ____/ |_ \__ ___/__________ _____ |__| ____ _____ | |
|
||||||
|
@ -78,14 +78,17 @@ func (r userRepository) FindByUsername(c context.Context, username string) (o mo
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r userRepository) ExistByUsername(c context.Context, username string) (exist bool) {
|
func (r userRepository) ExistByUsername(c context.Context, username string) (exist bool, err error) {
|
||||||
count := int64(0)
|
user := model.User{}
|
||||||
err := r.GetDB(c).Table("users").Where("username = ?", username).Count(&count).Error
|
var count uint64
|
||||||
|
err = r.GetDB(c).Table(user.TableName()).Select("count(*)").
|
||||||
|
Where("username = ?", username).
|
||||||
|
Find(&count).
|
||||||
|
Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false
|
return false, err
|
||||||
}
|
}
|
||||||
|
return count > 0, nil
|
||||||
return count > 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r userRepository) FindOnlineUsers(c context.Context) (o []model.User, err error) {
|
func (r userRepository) FindOnlineUsers(c context.Context) (o []model.User, err error) {
|
||||||
|
@ -57,6 +57,19 @@ func (r userGroupRepository) FindByName(c context.Context, name string) (o model
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r userGroupRepository) ExistByName(ctx context.Context, name string) (exists bool, err error) {
|
||||||
|
userGroup := model.UserGroup{}
|
||||||
|
var count uint64
|
||||||
|
err = r.GetDB(ctx).Table(userGroup.TableName()).Select("count(*)").
|
||||||
|
Where("name = ?", name).
|
||||||
|
Find(&count).
|
||||||
|
Error
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return count > 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r userGroupRepository) Create(c context.Context, o *model.UserGroup) (err error) {
|
func (r userGroupRepository) Create(c context.Context, o *model.UserGroup) (err error) {
|
||||||
return r.GetDB(c).Create(o).Error
|
return r.GetDB(c).Create(o).Error
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,11 @@ func (service backupService) Import(backup *dto.Backup) error {
|
|||||||
if len(backup.Users) > 0 {
|
if len(backup.Users) > 0 {
|
||||||
for _, item := range backup.Users {
|
for _, item := range backup.Users {
|
||||||
oldId := item.ID
|
oldId := item.ID
|
||||||
if repository.UserRepository.ExistByUsername(c, item.Username) {
|
exist, err := repository.UserRepository.ExistByUsername(c, item.Username)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if exist {
|
||||||
delete(userIdMapping, oldId)
|
delete(userIdMapping, oldId)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,11 @@ func (service userService) ReloadToken() error {
|
|||||||
func (service userService) CreateUser(user model.User) (err error) {
|
func (service userService) CreateUser(user model.User) (err error) {
|
||||||
return env.GetDB().Transaction(func(tx *gorm.DB) error {
|
return env.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||||
c := service.Context(tx)
|
c := service.Context(tx)
|
||||||
if repository.UserRepository.ExistByUsername(c, user.Username) {
|
exist, err := repository.UserRepository.ExistByUsername(c, user.Username)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if exist {
|
||||||
return fmt.Errorf("username %s is already used", user.Username)
|
return fmt.Errorf("username %s is already used", user.Username)
|
||||||
}
|
}
|
||||||
password := user.Password
|
password := user.Password
|
||||||
@ -307,3 +311,29 @@ func (service userService) SaveLoginLog(clientIP, clientUserAgent string, userna
|
|||||||
func (service userService) DeleteALlLdapUser(ctx context.Context) error {
|
func (service userService) DeleteALlLdapUser(ctx context.Context) error {
|
||||||
return repository.UserRepository.DeleteBySource(ctx, constant.SourceLdap)
|
return repository.UserRepository.DeleteBySource(ctx, constant.SourceLdap)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (service userService) UpdateUser(id string, user model.User) error {
|
||||||
|
|
||||||
|
return env.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||||
|
ctx := service.Context(tx)
|
||||||
|
|
||||||
|
dbUser, err := repository.UserRepository.FindById(ctx, id)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if dbUser.Username != user.Username {
|
||||||
|
// 修改了登录账号
|
||||||
|
exist, err := repository.UserRepository.ExistByUsername(ctx, user.Username)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if exist {
|
||||||
|
return fmt.Errorf("username %s is already used", user.Username)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return repository.UserRepository.Update(ctx, &user)
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
@ -2,7 +2,6 @@ package service
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
|
|
||||||
"next-terminal/server/constant"
|
"next-terminal/server/constant"
|
||||||
"next-terminal/server/env"
|
"next-terminal/server/env"
|
||||||
@ -36,14 +35,13 @@ func (service userGroupService) DeleteById(userGroupId string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (service userGroupService) Create(name string, members []string) (model.UserGroup, error) {
|
func (service userGroupService) Create(name string, members []string) (model.UserGroup, error) {
|
||||||
var err error
|
exist, err := repository.UserGroupRepository.ExistByName(context.TODO(), name)
|
||||||
_, err = repository.UserGroupRepository.FindByName(context.TODO(), name)
|
if err != nil {
|
||||||
if err == nil {
|
return model.UserGroup{}, err
|
||||||
return model.UserGroup{}, constant.ErrNameAlreadyUsed
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !errors.Is(gorm.ErrRecordNotFound, err) {
|
if exist {
|
||||||
return model.UserGroup{}, err
|
return model.UserGroup{}, constant.ErrNameAlreadyUsed
|
||||||
}
|
}
|
||||||
|
|
||||||
userGroupId := utils.UUID()
|
userGroupId := utils.UUID()
|
||||||
@ -76,15 +74,21 @@ func (service userGroupService) Create(name string, members []string) (model.Use
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (service userGroupService) Update(userGroupId string, name string, members []string) (err error) {
|
func (service userGroupService) Update(userGroupId string, name string, members []string) (err error) {
|
||||||
var userGroup model.UserGroup
|
dbUserGroup, err := repository.UserGroupRepository.FindById(context.TODO(), userGroupId)
|
||||||
userGroup, err = repository.UserGroupRepository.FindByName(context.TODO(), name)
|
if err != nil {
|
||||||
if err == nil && userGroup.ID != userGroupId {
|
|
||||||
return constant.ErrNameAlreadyUsed
|
|
||||||
}
|
|
||||||
|
|
||||||
if errors.Is(gorm.ErrRecordNotFound, err) {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if dbUserGroup.Name != name {
|
||||||
|
// 修改了名称
|
||||||
|
exist, err := repository.UserGroupRepository.ExistByName(context.TODO(), name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if exist {
|
||||||
|
return constant.ErrNameAlreadyUsed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return env.GetDB().Transaction(func(tx *gorm.DB) error {
|
return env.GetDB().Transaction(func(tx *gorm.DB) error {
|
||||||
c := context.WithValue(context.TODO(), constant.DB, tx)
|
c := context.WithValue(context.TODO(), constant.DB, tx)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "next-terminal",
|
"name": "next-terminal",
|
||||||
"version": "1.2.4",
|
"version": "1.2.5",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ant-design/charts": "^1.2.13",
|
"@ant-design/charts": "^1.2.13",
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 134 KiB After Width: | Height: | Size: 175 KiB |
@ -169,7 +169,7 @@ class LoginForm extends Component {
|
|||||||
enable: true,
|
enable: true,
|
||||||
outMode: "bounce",
|
outMode: "bounce",
|
||||||
random: false,
|
random: false,
|
||||||
speed: 6,
|
speed: 3,
|
||||||
straight: false,
|
straight: false,
|
||||||
},
|
},
|
||||||
number: {
|
number: {
|
||||||
|
@ -444,6 +444,7 @@ class Access extends Component {
|
|||||||
client.onstatechange = this.onClientStateChange;
|
client.onstatechange = this.onClientStateChange;
|
||||||
|
|
||||||
client.onerror = this.onError;
|
client.onerror = this.onError;
|
||||||
|
tunnel.onerror = this.onError;
|
||||||
|
|
||||||
// Get display div from document
|
// Get display div from document
|
||||||
const display = document.getElementById("display");
|
const display = document.getElementById("display");
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
<svg width="130" height="140" xmlns="http://www.w3.org/2000/svg">
|
<svg width="128" height="128" xmlns="http://www.w3.org/2000/svg">
|
||||||
<g fill="none">
|
<g fill="none">
|
||||||
<path fill="#40a9ff" d="M 10 10 V 110 L 65 135 L 120 110 V 10 Z"/>
|
|
||||||
<g fill="none">
|
<g fill="none">
|
||||||
<path fill="#40a9ff" d="M 10 10 V 110 L 65 135 L 120 110 V 10 Z"/>
|
<path fill="#40a9ff" d="M 9 0 v 95 l 55 30 l 55 -30 v -95 h -90 z"/>
|
||||||
<path fill="white" d="M 65 50 l -55 20 v 20 l 55 -20 l 55 20 v -20 l -55 -20 Z"/>
|
<path fill="white" d="M 64 35 l -55 25 v 20 l 55 -25 l 55 25 v -20 l -55 -25 z"/>
|
||||||
<path fill="#0050b3" d="M 65 70 l -55 20 v 20 l 55 25 l 55 -25 v -20 l -55 -20 Z"/>
|
<path fill="#0050b3" d="M 64 55 l -55 25 v 15 l 55 30 l 55 -30 v -15 l -55 -25 z"/>
|
||||||
</g>
|
</g>
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
Before Width: | Height: | Size: 482 B After Width: | Height: | Size: 409 B |
Reference in New Issue
Block a user