Exemple #1
0
func (c *ContentController) Get() {
	openid := getContentCookie(c)
	op := c.Input().Get("op")
	beego.Debug("get op :---------------", op)
	switch op {
	case "con":
		id := c.Input().Get("id")
		if len(id) == 0 {
			break
		}
		// id = c.Input().Get("id")
		post, err := models.GetOnePost(id)
		if err != nil {
			beego.Error(err)
		}
		beego.Debug("id :", id)
		c.Data["Id"] = id
		c.Data["Post"] = post
		beego.Debug("is con " + post.Title)
		help_num, err := models.GatPostHelpNum(id)
		c.Data["HelpNum"] = help_num
		state, err := models.GatPaseHelpState(id, openid)
		c.Data["HelpState"] = state
		c.TplName = "content.html"
		return
	}
	c.TplName = "content.html"
}
Exemple #2
0
func (this *RoleController) Post() {
	form := models.RolePostForm{}
	err := json.Unmarshal(this.Ctx.Input.RequestBody, &form)
	if err != nil {
		beego.Debug("ParseRolePost:", err)
		this.RetError(errInputData)
		return
	}
	beego.Debug("ParseRolePost:", &form)

	regDate := time.Now()
	role := models.NewRole(&form, regDate)
	beego.Debug("NewRole:", role)

	if code, err := role.Insert(); err != nil {
		beego.Error("InsertRole:", err)
		if code == models.ErrDupRows {
			this.RetError(errDupUser)
		} else {
			this.RetError(errDatabase)
		}
		return
	}

	role.ClearPass()

	this.Data["json"] = &models.RolePostInfo{RoleInfo: role}
	this.ServeJson()
}
Exemple #3
0
func (this *MainController) View() {
	var (
		post models.Post
		err  error
	)

	Title := this.Ctx.Input.Param(":Title")
	beego.Debug(";Title=", Title)
	if Title != "" {
		post.Title = Title
		err = post.Read("Title")
	} else {
		id, _ := strconv.Atoi(this.Ctx.Input.Param(":id"))
		post.Id = id
		err = post.Read()
	}
	if err != nil || post.Status != 0 {
		beego.Debug("show err:", err)
		this.Abort("404")
		return
	}

	post.Views++
	post.Update("Views")

	post.Content = strings.Replace(post.Content, "_ueditor_page_break_tag_", "", -1)

	this.Data["post"] = post
	//beego.Debug("show,post", post)
	this.setHeadMetas(post.Title, strings.Trim(post.Tags, ","), post.Title)
	this.display("post")
}
func (c *ZhouBianWifiWXController) Get() {
	op := c.Input().Get("op")
	switch op {
	case "location":
		latitude := c.Input().Get("latitude")
		longitude := c.Input().Get("longitude")
		c.Data["latitude"] = latitude
		c.Data["longitude"] = longitude
		beego.Debug("latitude:", latitude)
		beego.Debug("longitude:", longitude)
		getWifi(longitude, latitude, c)
		c.TplName = "zhoubianwifi.html"
		return
	}
	appId := ""
	iniconf, err := config.NewConfig("json", "conf/myconfig.json")
	if err != nil {
		beego.Debug(err)
	} else {
		appId = iniconf.String("qax580::appid")
	}
	timestamp := time.Now().Unix()
	noncestr := getNonceStr(16, KC_RAND_KIND_ALL)
	c.Data["AppId"] = appId
	c.Data["TimesTamp"] = timestamp
	c.Data["NonceStr"] = noncestr
	getWifiWxJsToken(noncestr, timestamp, c)
	c.TplName = "zhoubianwifiwx.html"
	// getWifi("116.366324", "39.905859", c)
	// c.TplName = "zhoubianwifi.html"
}
Exemple #5
0
// @Title createAppSet
// @router / [post]
func (a *AppSetsController) Post() {
	defer a.ServeJSON()
	appSet := new(models.AppSets)
	err := json.Unmarshal(a.Ctx.Input.RequestBody, appSet)
	if err != nil {
		beego.Warn("[C] Got error:", err)
		a.Data["json"] = map[string]string{
			"message": "Bad request",
			"error":   err.Error(),
		}
		a.Ctx.Output.SetStatus(http.StatusBadRequest)
		return
	}
	beego.Debug("[C] Got data:", appSet)
	id, err := models.AddAppSet(appSet)
	if err != nil {
		beego.Warn("[C] Got error:", err)
		a.Data["json"] = map[string]string{
			"message": "Failed to add New host",
			"error":   err.Error(),
		}
		a.Ctx.Output.SetStatus(http.StatusInternalServerError)
		return
	}

	beego.Debug("[C] Got id:", id)
	a.Data["json"] = map[string]string{
		"id": id,
	}
	a.Ctx.Output.SetStatus(http.StatusCreated)
	return
}
Exemple #6
0
func (c *DqsjController) AdminAddCaiTips() {
	bool, _ := chackDqsjAccount(c.Ctx)
	if bool {

	} else {
		c.Redirect("/dqsj/adminlogin", 302)
		return
	}
	if c.Ctx.Input.IsGet() {
		beego.Debug("AdminAddCaiTips Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("AdminAddCaiTips Post")
		info := c.Input().Get("info")
		if len(info) != 0 {
			err := models.AddCaiTips(info)
			if err != nil {
				beego.Error(err)
			}
			c.Redirect("/dqsj/admincai", 302)
		} else {
			c.Redirect("/dqsj/adminaddcaitips", 302)
		}

	}
	c.TplName = "dqsjadminaddcaitips.html"
}
Exemple #7
0
func run() {
	for {
		for k, v := range alive {
			beego.Debug("keepalive", k, v)

			if time.Now().Sub(v.HitTime) >= time.Duration(TIMEOUT_INTERVAL)*time.Minute {
				//step 1: get and delete user status
				user := &UserStatus{
					UserMac: k,
				}
				user.Get() // first get for stop radius
				user.Delete()

				//step 2: stop radius
				user.Reason = int(radgo.DeauthReasonAging)
				radusr := &RadUser{
					User: user,
				}
				radgo.ClientAcctStop(radusr)

				//step 3: unregister user info
				info := &UserInfo{
					UserName: v.UserName,
				}
				info.UnRegister()

				//step 4: delete alive
				delete(alive, k)
			}
		}

		beego.Debug("Listener Gc running...")
		time.Sleep(GC_INTERVAL * time.Minute)
	}
}
func (c *ImageController) AddImg() {
	if c.Ctx.Input.IsGet() {
		beego.Debug("ImageController AddImg Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("ImageController AddImg Post")
	}
	request_json := `{"errcode":1,"errmsg":"parameter error"}`
	// beego.Debug(c.Input())
	// beego.Debug(c.GetFile())
	images := c.Input().Get("images")
	beego.Debug("images:", images)
	if len(images) != 0 {
		// openid, err := getPhotoOpenId(c.Ctx)
		//json 到 []string
		// var wo []string
		// if err := json.Unmarshal(images, &wo); err == nil {
		// 	fmt.Println("================json 到 []string==")
		// 	fmt.Println(wo)
		// }
		//array 到 json str
		// arr := []string{"hello", "apple", "python", "golang", "base", "peach", "pear"}
		// lang, err := json.Marshal(arr)
		// if err == nil {
		// 	fmt.Println("================array 到 json str==")
		// 	fmt.Println(string(lang))
		// }

		//json 到 []string
		var json_images []string
		err := json.Unmarshal([]byte(images), &json_images)
		if err != nil {
			beego.Error(err)
		}
		beego.Debug(len(json_images))
		group := createImageGroupId(len(json_images))
		openid, err := getPhotoOpenId(c.Ctx)
		if err != nil {
			beego.Error(err)
			request_json = fmt.Sprintf(`{"errcode":1,"errmsg":%s}`, "AddImg getPhotoOpenId error")
			// `{"errcode":1,"errmsg":%s}`
			c.Ctx.WriteString(request_json)
			return
		}
		// beego.Debug(group)
		// beego.Debug(openid)
		for i := 0; i < len(json_images); i++ {
			_, err := models.AddPhotos(openid, group, json_images[i])
			if err != nil {
				beego.Error(err)
				request_json = fmt.Sprintf(`{"errcode":1,"errmsg":%s}`, "AddImg AddPhotos error")
				// `{"errcode":1,"errmsg":%s}`
				c.Ctx.WriteString(request_json)
				return
			}
		}
	}
	request_json = `{"errcode":0,"errmsg":"","data":""}`
	c.Ctx.WriteString(request_json)
}
Exemple #9
0
//todo 文件初始化
func init() {
	beego.Debug("init...")
	initConfig()  //读取配置文件
	initFileSys() //初始化文件系统
	initSql()     //连接数据库
	beego.Debug("init done...")
}
Exemple #10
0
//获得jsapi_ticket
func getWxGameJsapiTicket(access_toke string, noncestr string, timestamp int64, url string, c *WeixinGameController) string {
	signature := ""
	wx_url := "[REALM]?access_token=[ACCESS_TOKEN]&type=jsapi"
	realm_name := "https://api.weixin.qq.com/cgi-bin/ticket/getticket"
	wx_url = strings.Replace(wx_url, "[REALM]", realm_name, -1)
	wx_url = strings.Replace(wx_url, "[ACCESS_TOKEN]", access_toke, -1)
	beego.Debug("getJsapiTicketUrl", wx_url)
	resp, err := http.Get(wx_url)
	if err != nil {
		beego.Debug(err)
	}

	defer resp.Body.Close()
	beego.Debug("----------------getWxGameJsapiTicket body--------------------")
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		beego.Debug(err)
	} else {
		beego.Debug(string(body))
	}
	// body := []byte(`{"errcode":0,"errmsg":"ok","ticket":"bxLdikRXVbTPdHSM05e5u5sUoXNKd8-41ZO3MhKoyN5OfkWITDGgnr2fwJ0m9E8NYzWKVZvdVtaUgWvsdshFKA","expires_in":7200}`)
	var ticket JsApiTicketJson
	if err := json.Unmarshal(body, &ticket); err == nil {
		if ticket.ErrCode == 0 {
			signature = signatureWxJs(ticket.Ticket, noncestr, timestamp, url)
		}
	} else {

	}
	return signature
}
Exemple #11
0
func (this *UserController) Logout() {
	form := models.LogoutForm{}
	if err := this.ParseForm(&form); err != nil {
		beego.Debug("ParseLogoutForm:", err)
		this.Data["json"] = models.NewErrorInfo(ErrInputData)
		this.ServeJson()
		return
	}
	beego.Debug("ParseLogoutForm:", &form)

	if err := this.VerifyForm(&form); err != nil {
		beego.Debug("ValidLogoutForm:", err)
		this.Data["json"] = models.NewErrorInfo(ErrInputData)
		this.ServeJson()
		return
	}

	if this.GetSession("user_id") != form.Phone {
		this.Data["json"] = models.NewErrorInfo(ErrInvalidUser)
		this.ServeJson()
		return
	}

	this.DelSession("user_id")

	this.Data["json"] = models.NewNormalInfo("Succes")
	this.ServeJson()
}
Exemple #12
0
func UpdateDevice(device *Deviceinfo) bool {
	beego.Debug("UpdateDevice table=", device.TableName())
	o := orm.NewOrm()

	var dev Deviceinfo
	err := o.QueryTable(device.TableName()).Filter("mac", device.Mac).One(&dev)
	if err != nil {
		return false
	} else {
		dev.State = device.State
		dev.LastKeepaliveTime = device.LastKeepaliveTime
		dev.LastRegistrationTime = device.LastRegistrationTime
		dev.IpAddress = device.IpAddress
		dev.IpLocation = device.IpLocation

		beego.Debug("UpdateDevice clientIp =", dev.IpAddress)

		_, err := o.Update(&dev)
		if err != nil {
			beego.Error(err)
			return false
		}
		return true
	}
}
Exemple #13
0
/**
获得授权token
*/
func getWxAutoToken(appid string, secret string, code string) (models.AccessTokenJson, error) {
	// ?appid=APPID&secret=SECRET&code=CODE&grant_type=authorization_code
	tokenobj := models.AccessTokenJson{}
	response_json := `{"errcode":1,"errmsg":"getWxAccessToken error"}`
	wx_url := "[REALM]?appid=[APPID]&secret=[SECRET]&&code=[CODE]&grant_type=authorization_code"
	realm_name := "https://api.weixin.qq.com/sns/oauth2/access_token"
	wx_url = strings.Replace(wx_url, "[REALM]", realm_name, -1)
	wx_url = strings.Replace(wx_url, "[APPID]", appid, -1)
	wx_url = strings.Replace(wx_url, "[SECRET]", secret, -1)
	wx_url = strings.Replace(wx_url, "[CODE]", code, -1)
	beego.Debug("/poll getWxAutoToken url :", wx_url)
	resp, err := http.Get(wx_url)
	if err != nil {
		beego.Error(err)
		return tokenobj, err
	}

	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		beego.Error(err)
		body = []byte(response_json)
	} else {
		beego.Debug("wxqax getWxToken boey :", string(body))
	}
	var atj models.AccessTokenJson
	if err := json.Unmarshal(body, &atj); err == nil {
		beego.Debug("get Token obj", atj)
		tokenobj = atj
	} else {
		beego.Error(err)
	}
	return tokenobj, err
}
Exemple #14
0
func (c *PollController) AdminpollVote() {
	bool, username := chackAccount(c.Ctx)
	if bool {
		c.Data["isUser"] = bool
		c.Data["User"] = username
	} else {
		c.Redirect("/admin", 302)
		return
	}
	pollsid := c.Input().Get("pollsid")
	pollid := c.Input().Get("pollid")
	if c.Ctx.Input.IsGet() {
		beego.Debug("Adminpollscon Get")
	}

	if c.Ctx.Input.IsPost() {
		beego.Debug("Adminpollscon Post")
	}
	objs, err := models.GetAllVote(pollsid, pollid)
	if err != nil {
		beego.Error(err)
	}
	beego.Debug("pollsid:", pollsid)
	beego.Debug("pollid:", pollid)
	beego.Debug("objs:", objs)
	c.Data["Objs"] = objs
	c.Data["PollsId"] = pollsid
	c.TplName = "adminpollvote.html"
}
Exemple #15
0
//后台
func (c *DqsjController) Admin() {
	if c.Ctx.Input.IsGet() {
		beego.Debug("Admin Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("Admin Post")
	}
	bool, username := chackDqsjAccount(c.Ctx)
	if bool {

	} else {
		c.Redirect("/dqsj/adminlogin", 302)
		return
	}
	c.Data["User"] = username
	c.Data["isUser"] = bool
	beego.Debug("username:"******"op")
	switch op {
	case "back":
		c.Ctx.SetCookie(DQSJ_USERNAME, "", -1, "/")
		c.Ctx.SetCookie(DQSJ_PASSWORD, "", -1, "/")
		c.Redirect("/dqsj/admin", 302)
		return
	}

	c.TplName = "dqsjadmin.html"
}
Exemple #16
0
// @Title createUser
// @router / [post]
func (h *UserController) Post() {
	defer h.ServeJSON()
	user := new(models.Users)
	err := json.Unmarshal(h.Ctx.Input.RequestBody, user)
	if err != nil {
		beego.Warn("[C] Got error:", err)
		h.Data["json"] = map[string]string{
			"message": "Bad request",
			"error":   err.Error(),
		}
		h.Ctx.Output.SetStatus(http.StatusBadRequest)
		return
	}
	beego.Debug("[C] Got data:", user)
	id, err := models.AddUser(user)
	if err != nil {
		beego.Warn("[C] Got error:", err)
		h.Data["json"] = map[string]string{
			"message": "Failed to add New host",
			"error":   err.Error(),
		}
		h.Ctx.Output.SetStatus(http.StatusInternalServerError)
		return
	}

	beego.Debug("[C] Got id:", id)
	h.Data["json"] = map[string]string{
		"id": id,
	}
	h.Ctx.Output.SetStatus(http.StatusCreated)
}
Exemple #17
0
func (c *DqsjController) AdminAddPan() {
	bool, _ := chackDqsjAccount(c.Ctx)
	if bool {

	} else {
		c.Redirect("/dqsj/adminlogin", 302)
		return
	}
	if c.Ctx.Input.IsGet() {
		beego.Debug("AdminAddPan Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("AdminAddPan Post")
		name := c.Input().Get("name")
		info := c.Input().Get("info")
		probability := c.Input().Get("probability")
		if len(name) != 0 && len(info) != 0 {
			err := models.AddPanItem(name, info, probability)
			if err != nil {
				beego.Error(err)
			}
			c.Redirect("/dqsj/adminpan", 302)
		} else {
			c.Redirect("/dqsj/adminaddpan", 302)
		}

	}
	c.TplName = "dqsjadminaddpan.html"
}
Exemple #18
0
// @Title getUser
// @router /:name [get]
func (h *UserController) Get() {
	name := h.GetString(":name")
	beego.Debug("[C] Got name:", name)
	defer h.ServeJSON()
	if name != "" {
		user := &models.Users{
			Name: name,
		}
		users, err := models.GetUser(user, 0, 0)
		if err != nil {
			h.Data["json"] = map[string]string{
				"message": fmt.Sprint("Failed to get  with name:", name),
				"error":   err.Error(),
			}
			beego.Warn("[C] Got error:", err)
			h.Ctx.Output.SetStatus(http.StatusInternalServerError)
			return
		}
		h.Data["json"] = users
		if len(users) == 0 {
			beego.Debug("[C] Got nothing with name:", name)
			h.Ctx.Output.SetStatus(http.StatusNotFound)
		} else {
			h.Ctx.Output.SetStatus(http.StatusOK)
		}
	}
}
Exemple #19
0
func (c *DqsjController) AdminGua() {
	bool, _ := chackDqsjAccount(c.Ctx)
	if bool {

	} else {
		c.Redirect("/dqsj/adminlogin", 302)
		return
	}
	if c.Ctx.Input.IsGet() {
		beego.Debug("AdminGua Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("AdminGua Post")
	}
	op := c.Input().Get("op")
	beego.Debug("op :", op)
	switch op {
	case "del":
		id := c.Input().Get("id")
		err := models.DeleteGuaItem(id)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/dqsj/admingua", 302)
		return
	case "state0":
		id := c.Input().Get("id")
		err := models.UpdateGuaItem(id, 1)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/dqsj/admingua", 302)
		return
	case "state1":
		id := c.Input().Get("id")
		err := models.UpdateGuaItem(id, 0)
		if err != nil {
			beego.Error(err)
		}
		c.Redirect("/dqsj/admingua", 302)
		return
	}
	panitem, err := models.GetAllGuaItem()
	if err != nil {
		beego.Error(err)
	}
	//计算总概率
	allProbability := int64(0)
	for i := 0; i < len(panitem); i++ {
		if panitem[i].State == 1 {
			allProbability += panitem[i].Probability
		}
	}
	for i := 0; i < len(panitem); i++ {
		panitem[i].AllProbability = allProbability
	}
	c.Data["GuaItem"] = panitem

	c.TplName = "dqsjadmingua.html"
}
Exemple #20
0
func (c *WptController) Search() {
	if c.Ctx.Input.IsGet() {
		beego.Debug("WptController Search Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("WptController Search Post")
	}
	search := c.Input().Get("search")
	if len(search) != 0 {
		objs, err := models.GetAllWptLike(search)
		if err != nil {
			beego.Error(err)
		}
		beego.Debug("Search :", objs)
		c.Data["Objs"] = objs
	} else {
		objs, err := models.GetAllWpt()
		if err != nil {
			beego.Error(err)
		}
		c.Data["Objs"] = objs

	}

	c.TplName = "wptsearch.html"
}
Exemple #21
0
func (tm *AdUnitManager) GetCampaignCounts(campaignId string, startDate time.Time, endDate time.Time) (counts []AdunitSummary, count int) {

	o := orm.NewOrm()

	var query string = ""

	query = sql.Get_Adunit_Summary
	var err error

	if campaignId != "" {
		query = query + `where a.campaignId = ?`
		_, err = o.Raw(query, startDate, endDate, startDate, endDate, campaignId).QueryRows(&counts)
	} else {
		_, err = o.Raw(query, startDate, endDate, startDate, endDate).QueryRows(&counts)
	}

	if err != nil {
		beego.Debug("failed to get counts", err)
		return counts, 0
	} else {
		//		for _, v := range counts {
		//			fmt.Println(v["campaignName"])
		//		}
		beego.Debug(counts)
		return counts, len(counts)
	}

}
Exemple #22
0
func (c *ViewController) Post() {
	worldName := c.Ctx.Input.Query("worldName")
	configValue := c.Ctx.Input.Query("value")

	beego.Debug("Post value is  " + worldName + "value:" + configValue)

	var err error
	currentPath, err := os.Getwd()
	if err != nil {
		beego.Debug("Get Current Path failed")
	}
	confPath := filepath.Join(currentPath, "jsonfiles", worldName+".json")

	beego.Debug("Current Path is " + confPath)

	beego.Debug("channel.conf path is " + confPath)

	err2 := ioutil.WriteFile(confPath, ([]byte)(configValue), os.ModeAppend)
	if err2 != nil {
		panic("open file failed!")
	}

	resultMap := make(map[string]string)
	resultMap["defenceStr"] = configValue
	if strings.Contains(worldName, "init") {
		resultMap["detailInfo"] = GetWorldInitStr(worldName)
	} else {
		resultMap["detailInfo"] = GetWorldLevelUpStr(worldName)
	}
	resultBytes, _ := json.Marshal(resultMap)
	c.Ctx.WriteString(string(resultBytes))

}
Exemple #23
0
func UpdateOrder(orderNumber string, transactionStatus string) (rstError error) {
	o := orm.NewOrm()
	rstError = o.Begin()

	transactionHeader := BeTransactionHeader{OrderNumber: orderNumber}

	rstError = o.Read(&transactionHeader, "OrderNumber")

	if rstError == orm.ErrNoRows {
		beego.Debug("No transaction header for order number:", orderNumber)

	} else if rstError == nil {
		beego.Debug("Find transaction header for order number:", orderNumber)
		transactionHeader.TrasactionStatus = transactionStatus
		_, rstError = o.Update(&transactionHeader)
	}

	if rstError != nil {
		beego.Error(rstError.Error())
		rstError = o.Rollback()
	} else {
		rstError = o.Commit()
	}

	return rstError
}
Exemple #24
0
func AddBackupSet(a *BackupSets) (string, error) {
	beego.Debug("[M] Got data:", a)
	o := orm.NewOrm()
	err := o.Begin()
	if err != nil {
		return "", err
	}

	a.Id = uuid.New()
	beego.Debug("[M] Got new id:", a.Id)
	validator := new(validation.Validation)
	valid, err := validator.Valid(a)
	if err != nil {
		o.Rollback()
		return "", err
	}
	if !valid {
		o.Rollback()
		var errS string
		for _, err := range validator.Errors {
			errS = fmt.Sprintf("%s, %s:%s", errS, err.Key, err.Message)
		}
		return "", fmt.Errorf("Bad info: %s", errS)
	}
	beego.Debug("[M] Got new data:", a)
	_, err = o.Insert(a)
	if err != nil {
		o.Rollback()
		return "", err
	}
	beego.Debug("[M] App set saved")
	o.Commit()
	return a.Id, nil
}
Exemple #25
0
// @Title getAppSet
// @router /:name [get]
func (a *AppSetsController) Get() {
	name := a.GetString(":name")
	defer a.ServeJSON()
	beego.Debug("[C] Got name:", name)
	if name != "" {
		appSet := &models.AppSets{
			Name: name,
		}
		appSets, err := models.GetAppSets(appSet, 0, 0)
		if err != nil {
			a.Data["json"] = map[string]string{
				"message": fmt.Sprint("Failed to get  with name:", name),
				"error":   err.Error(),
			}
			beego.Warn("[C] Got error:", err)
			a.Ctx.Output.SetStatus(http.StatusInternalServerError)
			return
		}
		a.Data["json"] = appSets
		if len(appSets) == 0 {
			beego.Debug("[C] Got nothing with name:", name)
			a.Ctx.Output.SetStatus(http.StatusNotFound)
		} else {
			a.Ctx.Output.SetStatus(http.StatusOK)
		}
	}
}
Exemple #26
0
func chackDqsjAccount(ctx *context.Context) (bool, string) {
	ck, err := ctx.Request.Cookie(DQSJ_USERNAME)
	if err != nil {
		return false, ""
	}

	username := ck.Value

	ck, err = ctx.Request.Cookie(DQSJ_PASSWORD)
	if err != nil {
		return false, ""
	}

	password := ck.Value

	admin, err := models.GetOneDqsjAdmin(username)
	beego.Debug("GetOneDqsjAdmin admin:", admin)
	if err != nil {
		return false, ""
	}
	if admin != nil && strings.EqualFold(username, admin.Username) && strings.EqualFold(password, admin.Password) {
		beego.Debug(" cookie username ", username)
		return true, username
	} else {
		return false, username
	}

}
Exemple #27
0
func (this *RoleController) GetOne() {
	idStr := this.Ctx.Input.Params[":id"]
	id, err := strconv.ParseInt(idStr, 0, 64)
	if err != nil {
		beego.Debug("ParseRoleId:", err)
		this.RetError(errInputData)
		return
	}

	role := models.Role{}
	if code, err := role.FindById(id); err != nil {
		beego.Error("FindRoleById:", err)
		if code == models.ErrNotFound {
			this.RetError(errNoUser)
		} else {
			this.RetError(errDatabase)
		}
		return
	}
	beego.Debug("RoleInfo:", &role)

	role.ClearPass()

	this.Data["json"] = &models.RoleGetOneInfo{RoleInfo: &role}
	this.ServeJson()
}
Exemple #28
0
func (c *DqsjController) AdminAddCaiGroup() {
	bool, _ := chackDqsjAccount(c.Ctx)
	if bool {

	} else {
		c.Redirect("/dqsj/adminlogin", 302)
		return
	}
	if c.Ctx.Input.IsGet() {
		beego.Debug("AdminAddCaiGroup Get")
	}
	if c.Ctx.Input.IsPost() {
		beego.Debug("AdminAddCaiGroup Post")
		name := c.Input().Get("name")
		orderid := c.Input().Get("orderid")
		if len(name) != 0 && len(orderid) != 0 {
			err := models.AddCaiGroup(name, orderid)
			if err != nil {
				beego.Error(err)
			}
			c.Redirect("/dqsj/admincai", 302)
		} else {
			c.Redirect("/dqsj/adminaddcaigroup", 302)
		}

	}
	c.TplName = "dqsjadminaddcaigroup.html"
}
Exemple #29
0
//首页, 只显示前N条
func (this *MainController) Index() {
	var (
		list     []*models.Post
		pagesize int
		err      error
		page     int
	)

	if page, err = strconv.Atoi(this.Ctx.Input.Param(":page")); err != nil || page < 1 {
		page = 1
	}

	if pagesize, err = strconv.Atoi(this.getOption("pagesize")); err != nil || pagesize < 1 {
		pagesize = 10
	}
	beego.Debug("pagesize=", pagesize, "offset=", (page-1)*pagesize)
	query := new(models.Post).Query().Filter("status", 0).Filter("urltype", 0)
	count, _ := query.Count()

	beego.Debug("count=", count)
	if count > 0 {
		query.OrderBy("-is_top", "-post_time").Limit(pagesize, (page-1)*pagesize).All(&list)
	}

	this.Data["count"] = count
	this.Data["list"] = list
	beego.Debug("list=", list)
	this.Data["pagebar"] = 1 //util.NewPager(page, int(count), pagesize, "").ToString()
	this.setHeadMetas()
	this.display("home")
	beego.Debug("list=", list)
}
Exemple #30
0
func (this *CommandController) Post() {
	//检查登录状态
	session := this.GetSession("Admin")
	if session == nil {
		beego.Trace("session verify failed!")
		this.Redirect("/", 302)
		return
	}

	//获取表单信息
	mac := this.Input().Get("mac")
	beego.Debug("mac=", mac)
	commandContent := this.Input().Get("commandContent")
	beego.Debug("commandContent=", commandContent)

	//下发action
	device := models.Deviceinfo{
		Mac: mac,
		Act: commandContent,
	}
	ok := models.SetAct(&device)
	if !ok {
		beego.Info("set action failed!")
	}

	//返回设备页面
	this.Redirect("/home", 302)
	return
}