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() { if u.IsBanned() {
return nil, errors.New("user banned") return nil, errors.New("user banned")
} }
if !u.IsAdmin() && settings.CreateRoomNeedReview.Get() { if u.IsAdmin() {
conf = append(conf, db.WithStatus(model.RoomStatusPending))
} else {
conf = append(conf, db.WithStatus(model.RoomStatusActive)) 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))...) 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) { if !u.HasRoomPermission(room, model.PermissionEditRoom) {
return model.ErrNoPermission return model.ErrNoPermission
} }
if !u.IsAdmin() && password == "" && settings.RoomMustNeedPwd.Get() {
return errors.New("room must need password")
}
return room.SetPassword(password) return room.SetPassword(password)
} }

@ -8,7 +8,7 @@ import (
var ( var (
DisableCreateRoom = newBoolSetting("disable_create_room", false, model.SettingGroupRoom) 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) CreateRoomNeedReview = newBoolSetting("create_room_need_review", false, model.SettingGroupRoom)
RoomTTL = newInt64Setting("room_ttl", int64(time.Hour*48), model.SettingGroupRoom) RoomTTL = newInt64Setting("room_ttl", int64(time.Hour*48), model.SettingGroupRoom)
) )

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

Loading…
Cancel
Save