Opt: room must need pwd setting

pull/31/head
zijiren233 2 years ago
parent 0c6a5958ae
commit cb7c98adb8

@ -16,10 +16,17 @@ func (u *User) CreateRoom(name, password string, conf ...db.CreateRoomConfig) (*
if u.IsBanned() {
return nil, errors.New("user banned")
}
if !u.IsAdmin() && settings.CreateRoomNeedReview.Get() {
conf = append(conf, db.WithStatus(model.RoomStatusPending))
} else {
if u.IsAdmin() {
conf = append(conf, db.WithStatus(model.RoomStatusActive))
} else {
if password == "" && settings.RoomMustNeedPwd.Get() {
return nil, errors.New("room must need password")
}
if settings.CreateRoomNeedReview.Get() {
conf = append(conf, db.WithStatus(model.RoomStatusPending))
} else {
conf = append(conf, db.WithStatus(model.RoomStatusActive))
}
}
return db.CreateRoom(name, password, append(conf, db.WithCreator(&u.User))...)
}
@ -87,6 +94,9 @@ func (u *User) SetRoomPassword(room *Room, password string) error {
if !u.HasRoomPermission(room, model.PermissionEditRoom) {
return model.ErrNoPermission
}
if !u.IsAdmin() && password == "" && settings.RoomMustNeedPwd.Get() {
return errors.New("room must need password")
}
return room.SetPassword(password)
}

@ -8,7 +8,7 @@ import (
var (
DisableCreateRoom = newBoolSetting("disable_create_room", false, model.SettingGroupRoom)
CreateRoomNeedPwd = newBoolSetting("create_room_need_pwd", false, model.SettingGroupRoom)
RoomMustNeedPwd = newBoolSetting("room_must_need_pwd", false, model.SettingGroupRoom)
CreateRoomNeedReview = newBoolSetting("create_room_need_review", false, model.SettingGroupRoom)
RoomTTL = newInt64Setting("room_ttl", int64(time.Hour*48), model.SettingGroupRoom)
)

@ -7,7 +7,6 @@ import (
json "github.com/json-iterator/go"
"github.com/synctv-org/synctv/internal/op"
"github.com/synctv-org/synctv/internal/settings"
"github.com/gin-gonic/gin"
dbModel "github.com/synctv-org/synctv/internal/model"
@ -64,8 +63,6 @@ func (c *CreateRoomReq) Validate() error {
} else if !alnumPrintReg.MatchString(c.Password) {
return ErrPasswordHasInvalidChar
}
} else if settings.CreateRoomNeedPwd.Get() {
return FormatEmptyPasswordError("room")
}
return nil
@ -105,8 +102,6 @@ func (s *SetRoomPasswordReq) Validate() error {
} else if !alnumPrintReg.MatchString(s.Password) {
return ErrPasswordHasInvalidChar
}
} else if settings.CreateRoomNeedPwd.Get() {
return FormatEmptyPasswordError("room")
}
return nil
}

Loading…
Cancel
Save