[cmd] initiate
This commit is contained in:
@@ -69,6 +69,11 @@ func (s *SettingService) GetAllSetting() (*map[string]string, error) {
|
||||
return &allSetting, nil
|
||||
}
|
||||
|
||||
func (s *SettingService) ResetSettings() error {
|
||||
db := database.GetDB()
|
||||
return db.Where("1 = 1").Delete(model.Setting{}).Error
|
||||
}
|
||||
|
||||
func (s *SettingService) getSetting(key string) (*model.Setting, error) {
|
||||
db := database.GetDB()
|
||||
setting := &model.Setting{}
|
||||
@@ -174,6 +179,16 @@ func (s *SettingService) GetWebPath() (string, error) {
|
||||
return webPath, nil
|
||||
}
|
||||
|
||||
func (s *SettingService) SetWebPath(webPath string) error {
|
||||
if !strings.HasPrefix(webPath, "/") {
|
||||
webPath = "/" + webPath
|
||||
}
|
||||
if !strings.HasSuffix(webPath, "/") {
|
||||
webPath += "/"
|
||||
}
|
||||
return s.setString("webPath", webPath)
|
||||
}
|
||||
|
||||
func (s *SettingService) GetSecret() ([]byte, error) {
|
||||
secret, err := s.getString("webSecret")
|
||||
if secret == defaultValueMap["webSecret"] {
|
||||
@@ -211,6 +226,10 @@ func (s *SettingService) GetSubPort() (int, error) {
|
||||
return s.getInt("subPort")
|
||||
}
|
||||
|
||||
func (s *SettingService) SetSubPort(subPort int) error {
|
||||
return s.setInt("subPort", subPort)
|
||||
}
|
||||
|
||||
func (s *SettingService) GetSubPath() (string, error) {
|
||||
subPath, err := s.getString("subPath")
|
||||
if err != nil {
|
||||
@@ -225,6 +244,16 @@ func (s *SettingService) GetSubPath() (string, error) {
|
||||
return subPath, nil
|
||||
}
|
||||
|
||||
func (s *SettingService) SetSubPath(subPath string) error {
|
||||
if !strings.HasPrefix(subPath, "/") {
|
||||
subPath = "/" + subPath
|
||||
}
|
||||
if !strings.HasSuffix(subPath, "/") {
|
||||
subPath += "/"
|
||||
}
|
||||
return s.setString("subPath", subPath)
|
||||
}
|
||||
|
||||
func (s *SettingService) GetSubDomain() (string, error) {
|
||||
return s.getString("subDomain")
|
||||
}
|
||||
|
||||
@@ -13,6 +13,40 @@ import (
|
||||
type UserService struct {
|
||||
}
|
||||
|
||||
func (s *UserService) GetFirstUser() (*model.User, error) {
|
||||
db := database.GetDB()
|
||||
|
||||
user := &model.User{}
|
||||
err := db.Model(model.User{}).
|
||||
First(user).
|
||||
Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (s *UserService) UpdateFirstUser(username string, password string) error {
|
||||
if username == "" {
|
||||
return common.NewError("username can not be empty")
|
||||
} else if password == "" {
|
||||
return common.NewError("password can not be empty")
|
||||
}
|
||||
db := database.GetDB()
|
||||
user := &model.User{}
|
||||
err := db.Model(model.User{}).First(user).Error
|
||||
if database.IsNotFound(err) {
|
||||
user.Username = username
|
||||
user.Password = password
|
||||
return db.Model(model.User{}).Create(user).Error
|
||||
} else if err != nil {
|
||||
return err
|
||||
}
|
||||
user.Username = username
|
||||
user.Password = password
|
||||
return db.Save(user).Error
|
||||
}
|
||||
|
||||
func (s *UserService) Login(username string, password string, remoteIP string) (string, error) {
|
||||
user := s.CheckUser(username, password, remoteIP)
|
||||
if user == nil {
|
||||
|
||||
Reference in New Issue
Block a user