예제 #1
0
파일: http.go 프로젝트: johnnywww/swd
func GetSessionUserInfoByForm(form url.Values) (userInfo *model.UserInfo, errorMsg string) {
	userInfo = nil
	username := form.Get("username")
	password := form.Get("password")
	if utils.IsEmptyStr(username) {
		errorMsg = "用户名为空"
		return
	}
	if utils.IsEmptyStr(password) {
		errorMsg = "密码为空"
		return
	}
	setupInfo := &model.SetupInfo{}
	if !model.NewSetupHandle().GetSetupInfo(setupInfo) {
		errorMsg = "没有配置信息,请找管理员"
		return
	}
	for _, userInfo1 := range setupInfo.Users {
		if userInfo1.Equal(username, password) {
			userInfo = &userInfo1
			break
		}
	}
	if nil == userInfo {
		errorMsg = "用户名或密码错误"
	}
	return userInfo, errorMsg
}
예제 #2
0
func (routeUserDelete *RouteUserDelete) Routes(m *martini.ClassicMartini) {
	m.Post("/user/delete", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /user/delete")
		SetResponseJsonHeader(w)
		setupInfo := model.SetupInfo{}
		setupHandle := model.NewSetupHandle()
		if !setupHandle.GetSetupInfo(&setupInfo) {
			return model.GetErrorDtoJson("读取用户信息失败")
		}
		r.ParseForm()
		log.WriteLog("user delete %v", r.Form)
		userName := r.Form.Get("username")

		if common.USER_NAME_ADMIN == userName {
			log.WriteLog("删除admin失败")
			return model.GetErrorDtoJson("删除管理员信息失败")
		}
		if !setupInfo.DeleteUserByUserName(userName) {
			log.WriteLog("删除用户信息失败")
			return model.GetErrorDtoJson("删除用户信息失败")
		}

		if !setupHandle.SaveSetupInfo(&setupInfo) {
			log.WriteLog("保存删除用户信息失败")
			return model.GetErrorDtoJson("保存删除用户信息失败")
		}
		return model.GetDataDtoJson(nil)
	})
}
예제 #3
0
파일: http.go 프로젝트: johnnywww/swd
func StartHttp(routeHandle model.RouteHandle) {
	checkEnv()
	port := 9500
	setupInfo := &model.SetupInfo{}
	if model.NewSetupHandle().GetSetupInfo(setupInfo) {
		if setupInfo.Port > 0 {
			port = setupInfo.Port
		}
	}
	m := martini.Classic()
	m.Use(render.Renderer(render.Options{
		Funcs: []template.FuncMap{{
			"pageStartIndex": getPageStartIndex,
			"pageEndIndex":   getPageEndIndex,
			"pageIndexHtml":  getPageIndexHtml,
			"serverType":     getServerType,
		}},
	}))
	routeHandle.Routes(m)
	error := http.ListenAndServe(":"+strconv.Itoa(port), m)
	if nil != error {
		log.WriteLog("start http %d failed %s", port, error.Error())
	}

}
예제 #4
0
파일: route.go 프로젝트: johnnywww/swd
func getUniqueServerName() string {
	result := ""
	setupInfo := model.SetupInfo{}
	if !model.NewSetupHandle().GetSetupInfo(&setupInfo) {
		return result
	}
	if len(setupInfo.Servers) == 1 {
		result = setupInfo.Servers[0].ServerName
	}
	return result
}
func (getServerInfoByServerNameImpl *getServerInfoByServerNameImpl) getInfo(serverName string) (*model.ServerInfo, error) {
	setupInfo := model.SetupInfo{}
	if !model.NewSetupHandle().GetSetupInfo(&setupInfo) {
		return nil, errors.New("读取配置失败")
	}
	index := setupInfo.GetServerIndexByServerName(serverName)
	if index < 0 {
		return nil, errors.New(fmt.Sprintf("没有找到对应的服务器%s", serverName))
	}
	return &setupInfo.Servers[index], nil
}
예제 #6
0
func (routeUserSave *RouteUserSave) Routes(m *martini.ClassicMartini) {
	m.Post("/user/save", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /user/save")
		SetResponseJsonHeader(w)
		setupInfo := model.SetupInfo{}
		setupHandle := model.NewSetupHandle()
		if !setupHandle.GetSetupInfo(&setupInfo) {
			return model.GetErrorDtoJson("读取用户信息失败")
		}
		r.ParseForm()
		log.WriteLog("user save %v", r.Form)
		ousername := r.Form.Get("ousername")
		username := r.Form.Get("username")
		addFlag := utils.IsEmptyStr(ousername)
		password := r.Form.Get("password")
		if utils.IsEmptyStr(username) {
			return model.GetErrorDtoJson("没有用户名称")
		}
		if utils.IsEmptyStr(password) {
			return model.GetErrorDtoJson("没有密码")
		}
		index := setupInfo.GetUserIndexByUserName(username)
		oindex := setupInfo.GetUserIndexByUserName(ousername)
		var pUserInfo *model.UserInfo = nil
		if addFlag {
			if index > -1 {
				return model.GetErrorDtoJson("用户名称输入重复")
			}
			userInfo := model.UserInfo{UserName: username, Password: password}
			setupInfo.AddUserInfo(userInfo)
			pUserInfo = &userInfo
		} else {
			if oindex < 0 {
				return model.GetErrorDtoJson("没有找到用户")
			} else {
				if index > -1 && oindex != index {
					return model.GetErrorDtoJson("用户名称输入重复")
				}
			}
			setupInfo.Users[oindex].UserName = username
			setupInfo.Users[oindex].Password = password
			pUserInfo = &setupInfo.Users[oindex]
		}
		if !setupHandle.SaveSetupInfo(&setupInfo) {
			log.WriteLog("保存删除用户信息失败")
			return model.GetErrorDtoJson("保存删除用信息失败")
		}
		return model.GetDataDtoJson(model.UserSaveInfo{UserInfo: *pUserInfo, OUserName: ousername, AddFlag: addFlag})
	})

}
예제 #7
0
func (routeServerDelete *RouteServerDelete) Routes(m *martini.ClassicMartini) {
	m.Post("/server/delete", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /server/delete")
		SetResponseJsonHeader(w)
		setupInfo := model.SetupInfo{}
		setupHandle := model.NewSetupHandle()
		if !setupHandle.GetSetupInfo(&setupInfo) {
			return model.GetErrorDtoJson("读取服务器信息失败")
		}
		r.ParseForm()
		log.WriteLog("server delete %v", r.Form)
		serverName := r.Form.Get("servername")
		if !setupInfo.DeleteServerByServerName(serverName) {
			log.WriteLog("删除服务器信息失败")
			return model.GetErrorDtoJson("删除服务器信息失败")
		}
		if !setupHandle.SaveSetupInfo(&setupInfo) {
			log.WriteLog("保存删除服务器信息失败")
			return model.GetErrorDtoJson("保存删除服务器信息失败")
		}
		return model.GetDataDtoJson(nil)
	})
}
예제 #8
0
func (routeServerSave *RouteServerSave) Routes(m *martini.ClassicMartini) {
	m.Post("/server/save", func(w http.ResponseWriter, r *http.Request) string {
		log.WriteLog("addr: /server/save")
		SetResponseJsonHeader(w)
		setupInfo := model.SetupInfo{}
		setupHandle := model.NewSetupHandle()
		if !setupHandle.GetSetupInfo(&setupInfo) {
			return model.GetErrorDtoJson("读取服务器信息失败")
		}
		r.ParseForm()
		log.WriteLog("server save %v", r.Form)
		oservername := r.Form.Get("oservername")
		servername := r.Form.Get("servername")
		addFlag := utils.IsEmptyStr(oservername)
		address := r.Form.Get("address")
		iType, err := strconv.Atoi(r.FormValue("servertype"))
		if nil != err {
			log.WriteLog("error: %v", err)
			iType = common.SERVER_TYPE_CMS
		}
		if utils.IsEmptyStr(servername) {
			return model.GetErrorDtoJson("没有服务器名称")
		}
		if utils.IsEmptyStr(address) {
			return model.GetErrorDtoJson("没有服务器地址")
		}
		index := setupInfo.GetServerIndexByServerName(servername)
		oindex := setupInfo.GetServerIndexByServerName(oservername)
		var pServerInfo *model.ServerInfo = nil
		if addFlag {
			if index > -1 {
				return model.GetErrorDtoJson("服务器名称输入重复")
			}
			serverInfo := model.ServerInfo{ServerName: servername, Address: address, Type: iType}
			setupInfo.AddServerInfo(serverInfo)
			pServerInfo = &serverInfo
		} else {
			if oindex < 0 {
				return model.GetErrorDtoJson("没有找到服务器")
			} else {
				if index > -1 && oindex != index {
					return model.GetErrorDtoJson("服务器名称输入重复")
				}
			}
			setupInfo.Servers[oindex].ServerName = servername
			setupInfo.Servers[oindex].Address = address
			setupInfo.Servers[oindex].Type = iType
			pServerInfo = &setupInfo.Servers[oindex]
		}
		if nil != routeServerSave.CheckServerSave {
			err := routeServerSave.CheckServerSave.CheckServerSave(oservername, pServerInfo)
			if nil != err {
				return model.GetErrorObjDtoJson(err)
			}
		}
		if !setupHandle.SaveSetupInfo(&setupInfo) {
			log.WriteLog("保存删除服务器信息失败")
			return model.GetErrorDtoJson("保存删除服务器信息失败")
		}
		return model.GetDataDtoJson(model.ServerSaveInfo{ServerInfo: *pServerInfo, OServerName: oservername, AddFlag: addFlag})
	})
}