func (controller *UserController) UserLogup() {
	var params struct {
		UserName   string `form:"user_name" valid:"Required; MinSize(4)" error:"invalid_user_name"`
		UserPwd    string `form:"user_pwd" valid:"Required; MinSize(6)" error:"invalid_user_pwd"`
		UserMobile string `form:"user_mobile" valid:"Required; MinSize(6)" error:"invalid_user_mobile"`
		UserQQ     string `form:"user_qq" valid:"Required; MinSize(6)" error:"invalid_user_qq"`
		UserWechat string `form:"user_wechat" valid:"Required; MinSize(6)" error:"invalid_user_wechat"`
		UserEmail  string `form:"user_email" valid:"Required; MinSize(6)" error:"invalid_user_email"`
	}

	if controller.ParseAndValidate(&params) == false {
		return
	}

	userInfo := userModel.UserInfo{}
	if err := controller.ParseForm(&userInfo); err != nil {
		return
	}

	resData, err := userService.UserLogup(&controller.Service, userInfo)
	if err != nil {
		log.CompletedErrorf(err, controller.UserID, "UserController.UserLogup", "UserName[%s]", params.UserName)
		controller.ServeError(err)
		return
	}

	controller.Data["json"] = resData
	controller.ServeJSON()
}
func (controller *UserController) UserLogin() {
	var params struct {
		UserName string `form:"user_name" valid:"Required; MinSize(4)" error:"invalid_user_name"`
		UserPwd  string `form:"user_pwd" valid:"Required; MinSize(6)" error:"invalid_user_pwd"`
	}

	if controller.ParseAndValidate(&params) == false {
		return
	}

	userInfo, err := userService.UserLogin(&controller.Service, params.UserName, params.UserPwd)
	if err != nil {
		log.CompletedErrorf(err, controller.UserID, "UserController.UserLogin", "UserName[%s]", params.UserName)
		controller.ServeError(err)
		return
	}

	// set session
	if len(userInfo.ID) > 0 {
		log.Trace("UserController", "UserLogin", "userID[%s]", userInfo.ID.Hex())
		controller.SetSession("UserID", userInfo.ID.Hex())
	}
	controller.Data["json"] = userInfo
	controller.ServeJson()
}
func (controller *SettingsController) SaveWinSettings() {
	var params struct {
		Settings string `form:"win_settings" valid:"Required; MinSize(6)" error:"invalid_win_settings"`
	}

	if controller.AuthUser() == false {
		return
	}

	if controller.ParseAndValidate(&params) == false {
		return
	}
	userID := controller.GetSession("UserID").(string)
	// 获取设置属性
	settings, err := settingsService.FindSettings(&controller.Service, userID)
	if err != nil {
		log.CompletedErrorf(err, controller.UserID, "SettingsController.SaveWinSettings", "UserID[%s]", userID)
		controller.ServeError(err)
		return
	}

	var win_settings settingsModel.WinSettings

	win_settings.ID = settings.ID
	win_settings.UserID = userID
	win_settings.Settings = params.Settings

	// save settings
	resData, err := settingsService.SaveSettings(&controller.Service, win_settings)
	if err != nil {
		log.CompletedErrorf(err, controller.UserID, "SettingsController.SaveWinSettings", "UserID[%s]", userID)
		controller.ServeError(err)
		return
	}

	controller.Data["json"] = resData
	controller.ServeJson()
}
func (controller *InfoController) FindInfo() {
	if controller.AuthUser() == false {
		return
	}

	userID := controller.GetSession("UserID").(string)
	info, err := infoService.FindInfo(&controller.Service, userID)
	if err != nil {
		log.CompletedErrorf(err, controller.UserID, "InfoController.FindInfo", "UserID[%s]", userID)
		controller.ServeError(err)
		return
	}

	controller.Data["json"] = info
	controller.ServeJSON()
}
func (controller *SettingsController) FindWinSettings() {
	if controller.AuthUser() == false {
		return
	}

	userID := controller.GetSession("UserID").(string)
	settings, err := settingsService.FindSettings(&controller.Service, userID)
	if err != nil {
		log.CompletedErrorf(err, controller.UserID, "SettingsController.GetWinSettings", "UserID[%s]", userID)
		controller.ServeError(err)
		return
	}

	controller.Data["json"] = settings
	controller.ServeJson()
}
func (controller *MsgController) FindMsg() {
	if controller.AuthUser() == false {
		return
	}

	userID := controller.GetSession("UserID").(string)
	settings, err := msgService.FindMsg(&controller.Service, userID)
	if err != nil {
		log.CompletedErrorf(err, controller.UserID, "MsgController.FindMsg", "UserID[%s]", userID)
		controller.ServeError(err)
		return
	}

	controller.Data["json"] = settings
	controller.ServeJSON()
}
Beispiel #7
0
// Index is the initial view for the buoy system.
func (controller *BuoyController) Index() {
	region := "Gulf Of Mexico"
	log.Startedf(controller.UserID, "BuoyController.Index", "Region[%s]", region)

	buoyStations, err := buoyService.FindRegion(&controller.Service, region)
	if err != nil {
		log.CompletedErrorf(err, controller.UserID, "BuoyController.Index", "Region[%s]", region)
		controller.ServeError(err)
		return
	}

	controller.Data["Stations"] = buoyStations
	controller.Layout = "shared/basic-layout.html"
	controller.TplNames = "buoy/content.html"
	controller.LayoutSections = map[string]string{}
	controller.LayoutSections["PageHead"] = "buoy/page-head.html"
	controller.LayoutSections["Header"] = "shared/header.html"
	controller.LayoutSections["Modal"] = "shared/modal.html"
}
Beispiel #8
0
// Stations handles the example 3 tab
// http://localhost:9003/buoy/station/42002
func (controller *BuoyController) RetrieveStationJson() {
	params := struct {
		StationId string `form:":stationId" valid:"Required; MinSize(4)" error:"invalid_station_id"`
	}{}

	if controller.ParseAndValidate(&params) == false {
		return
	}

	buoyStation, err := buoyService.FindStation(&controller.Service, params.StationId)
	if err != nil {
		tracelog.CompletedErrorf(err, controller.UserId, "Station", "StationId[%s]", params.StationId)
		controller.ServeError(err)
		return
	}

	controller.Data["json"] = &buoyStation
	controller.ServeJson()
}
Beispiel #9
0
// RetrieveStationJSON handles the example 3 tab.
// http://localhost:9003/buoy/station/42002
func (controller *BuoyController) RetrieveStationJSON() {
	// The call to ParseForm inside of ParseAndValidate is failing. This is a BAD FIX
	params := struct {
		StationID string `form:":stationId" valid:"Required; MinSize(4)" error:"invalid_station_id"`
	}{controller.GetString(":stationId")}

	if controller.ParseAndValidate(&params) == false {
		return
	}

	buoyStation, err := buoyService.FindStation(&controller.Service, params.StationID)
	if err != nil {
		log.CompletedErrorf(err, controller.UserID, "Station", "StationID[%s]", params.StationID)
		controller.ServeError(err)
		return
	}

	controller.Data["json"] = buoyStation
	controller.ServeJson()
}
func (controller *InfoController) SaveInfo() {
	var params struct {
		ID          string `form:"_id" valid:"Required; MinSize(6)" error:"invalid_id"`
		InfoType    string `form:"info_type" valid:"Required; MinSize(6)" error:"invalid_info_type"`
		CreatedBy   string `form:"created_by" valid:"Required; MinSize(6)" error:"invalid_created_by"`
		CreatedTime int64  `form:"created_time" valid:"Required; MinSize(6)" error:"invalid_win_settings"`
		Origin      string `form:"info_origin" valid:"Required; MinSize(6)" error:"invalid_info_origin"`
		Destination string `form:"info_destination" valid:"Required; MinSize(6)" error:"invalid_info_destination"`
		Frequency   string `form:"info_frequency" valid:"Required; MinSize(6)" error:"invalid_info_frequency"`
		InfoContent string `form:"info_content" valid:"Required; MinSize(6)" error:"invalid_info_content"`
		InfoTime    int64  `form:"info_time" valid:"Required; MinSize(6)" error:"invalid_info_time"`
		Mobile      string `form:"info_mobile" valid:"Required; MinSize(6)" error:"invalid_info_mobile"`
		Wechat      string `form:"info_wechat" valid:"Required; MinSize(6)" error:"invalid_info_wechat"`
		QQ          string `form:"info_qq" valid:"Required; MinSize(6)" error:"invalid_info_qq"`
	}

	if controller.AuthUser() == false {
		return
	}

	if controller.ParseAndValidate(&params) == false {
		return
	}

	information := infoModel.Information{}
	if err := controller.ParseForm(&information); err != nil {
		return
	}

	// save msg
	resData, err := infoService.SaveInfo(&controller.Service, information)
	if err != nil {
		log.CompletedErrorf(err, controller.UserID, "InfoController.SaveInfo", "UserID[%s]", controller.UserID)
		controller.ServeError(err)
		return
	}

	controller.Data["json"] = resData
	controller.ServeJSON()
}
Beispiel #11
0
// LoadJSON takes a json document of translations and manually
// loads them into the system
func LoadJSON(userLocale string, translationDocument string) error {
	tracelog.Startedf("localize", "LoadJSON", "userLocale[%s] length[%d]", userLocale, len(translationDocument))

	var tranDocuments []map[string]interface{}
	if err := json.Unmarshal([]byte(translationDocument), &tranDocuments); err != nil {
		tracelog.CompletedErrorf(err, "localize", "LoadJSON", "**************>")
		return err
	}

	for _, tranDocument := range tranDocuments {
		tran, err := translation.NewTranslation(tranDocument)
		if err != nil {
			tracelog.CompletedError(err, "localize", "LoadJSON")
			return err
		}

		i18n.AddTranslation(locale.MustNew(userLocale), tran)
	}

	tracelog.Completed("localize", "LoadJSON")
	return nil
}
Beispiel #12
0
// RetrieveStation handles the example 2 tab.
func (controller *BuoyController) RetrieveStation() {
	var params struct {
		StationID string `form:"stationID" valid:"Required; MinSize(4)" error:"invalid_station_id"`
	}

	if controller.ParseAndValidate(&params) == false {
		return
	}

	buoyStation, err := buoyService.FindStation(&controller.Service, params.StationID)
	if err != nil {
		log.CompletedErrorf(err, controller.UserID, "BuoyController.RetrieveStation", "StationID[%s]", params.StationID)
		controller.ServeError(err)
		return
	}

	controller.Data["Station"] = buoyStation
	controller.Layout = ""
	controller.TplNames = "buoy/modal/pv_station-detail.html"
	view, _ := controller.RenderString()

	controller.AjaxResponse(0, "SUCCESS", view)
}
func (controller *MsgController) SaveMsg() {
	var params struct {
		ID          string `form:"_id" valid:"Required; MinSize(6)" error:"invalid_id"`
		MsgType     string `form:"msg_type" valid:"Required; MinSize(6)" error:"invalid_msg_type"`
		CreatedBy   string `form:"created_by" valid:"Required; MinSize(6)" error:"invalid_created_by"`
		CreatedTime int64  `form:"created_time" valid:"Required; MinSize(6)" error:"invalid_win_settings"`
		PushObject  string `form:"push_object" valid:"Required; MinSize(6)" error:"invalid_push_object"`
		PushTime    string `form:"push_time" valid:"Required; MinSize(6)" error:"invalid_push_time"`
		HasPushed   string `form:"has_pushed" valid:"Required; MinSize(6)" error:"invalid_has_pushed"`
		MsgContent  string `form:"msg_content" valid:"Required; MinSize(6)" error:"invalid_msg_content"`
		HasViewed   int64  `form:"has_viewed" valid:"Required; MinSize(6)" error:"invalid_has_viewed"`
	}

	if controller.AuthUser() == false {
		return
	}

	if controller.ParseAndValidate(&params) == false {
		return
	}

	message := msgModel.Message{}
	if err := controller.ParseForm(&message); err != nil {
		return
	}

	// save msg
	resData, err := msgService.SaveMsg(&controller.Service, message)
	if err != nil {
		log.CompletedErrorf(err, controller.UserID, "MsgController.SaveMsg", "UserID[%s]", controller.UserID)
		controller.ServeError(err)
		return
	}

	controller.Data["json"] = resData
	controller.ServeJSON()
}