当前位置: 首页>>代码示例>>Golang>>正文


Golang Page.SetUser方法代码示例

本文整理汇总了Golang中pixelrelay/models.Page.SetUser方法的典型用法代码示例。如果您正苦于以下问题:Golang Page.SetUser方法的具体用法?Golang Page.SetUser怎么用?Golang Page.SetUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pixelrelay/models.Page的用法示例。


在下文中一共展示了Page.SetUser方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Login

func Login(session sessions.Session, su models.User, r render.Render, p *models.Page) {

	// Check if we are already logged in
	if su.Id > 0 {
		r.Redirect(strings.Join([]string{utils.AppCfg.Url(), "albums"}, "/"), http.StatusFound)
		return
	}

	session.Set("loggedin", "false")

	// Init error holder
	errs := make(map[string]string)

	err_flash := session.Get("flash")
	if err_flash != nil {
		errs["flash"] = err_flash.(string)
		session.Set("flash", nil)
	}

	genform := utils.GenerateForm(&forms.Login{}, "/login", "POST", errs)

	p.SetUser(su)
	p.SetTitle("Login")
	p.Data = LoginVars{Form: genform}

	encoder.Render(p.Encoding, 200, "login", p, r)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:27,代码来源:login.go

示例2: Hash

func Hash(args martini.Params, su models.User, r render.Render, p *models.Page) {
	var th models.HashID

	user_id, err := strconv.ParseInt(args["user_id"], 10, 10)
	if err != nil {
		log.Println(err)
	}

	image_id, err := strconv.ParseInt(args["image_id"], 10, 10)
	if err != nil {
		log.Println(err)
	}

	time_now := time.Now().Unix()

	th.Init(utils.AppCfg.SecretKey(), 6)
	th.SetIds(int(user_id), int(image_id), int(time_now))
	enc := th.Encrypt()
	log.Println(enc)
	dec := th.Decrypt()
	log.Println(dec)

	p.SetUser(su)
	p.SetTitle("")
	p.Data = th
	encoder.Render(p.Encoding, 200, "test/hash", p, r)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:27,代码来源:hash.go

示例3: Profile

func Profile(args martini.Params, su models.User, session sessions.Session, r render.Render, dbh *db.Dbh, p *models.Page) {
	name := args["user"]

	p.SetTitle("Profile", name)
	p.SetUser(su)
	p.Data = ""

	encoder.Render(p.Encoding, 200, "profile", p, r)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:9,代码来源:profile.go

示例4: Tags

func Tags(su models.User, dbh *db.Dbh, p *models.Page, r render.Render) {
	tags := dbh.GetAllTags()

	p.SetUser(su)
	p.SetTitle("Tags")
	p.Data = tags
	p.Encoding = "json"

	encoder.Render(p.Encoding, 200, "tags", p, r)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:10,代码来源:tags.go

示例5: AlbumUpdate

func AlbumUpdate(req *http.Request, r render.Render, su models.User, dbh *db.Dbh, p *models.Page) {
	p.SetUser(su)

	var reader io.Reader = req.Body
	b, e := ioutil.ReadAll(reader)
	if e != nil {
		log.Println(e)
	}

	var f interface{}
	err := json.Unmarshal(b, &f)
	if err != nil {
		log.Println(err)
	}

	m := f.(map[string]interface{})
	md := m["data"].(map[string]interface{})

	// Default status
	var status string = "Permission Denied"
	var code int = 401

	mi := int64(md["Id"].(float64))
	mo := int64(md["Owner"].(float64))
	name := md["Name"].(string)

	album := dbh.GetAlbumById(mi)

	if album.Id == mi && album.User == mo && su.Id == mo {
		mAlbum := models.Album{
			Id:          mi,
			Description: md["Description"].(string),
			Name:        md["Name"].(string),
			User:        mo,
			Poster:      md["Poster"].(string),
			Private:     md["Private"].(bool),
			Privatekey:  md["Privatekey"].(string)}

		log.Printf("mAlbum: %+v\n", mAlbum)
		uAlbum := dbh.AlbumUpdate(mAlbum)
		log.Printf("uAlbum: %+v\n", uAlbum)
		status = "Success"
		code = 200
	}

	log.Println("Album Update: ", "Name: ", name, " Album Id: ", album.Id, "=", mi, " Album User: ", album.User, "=", mo, " Session: ", su.Id, "=", mo, " Status: ", status)

	p.Data = models.AlbumResult{Status: status}
	encoder.Render("json", code, "", p, r)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:50,代码来源:albumupdate.go

示例6: ImagePage

func ImagePage(args martini.Params, su models.User, res http.ResponseWriter, req *http.Request, r render.Render, dbh *db.Dbh, p *models.Page) {
	name := args["name"]

	image := dbh.FirstImageByName(name)
	tags := dbh.GetAllTagsByImageId(image.Id)

	errs := make(map[string]string)
	form := utils.GenerateForm(&forms.Tag{Image: name}, "/tag", "POST", errs)

	p.SetUser(su)
	p.SetTitle("Image")

	src := fmt.Sprintf("%s/i/%s", utils.AppCfg.Url(), name)
	fullsrc := fmt.Sprintf("%s/o/%s", utils.AppCfg.Url(), name)
	p.Data = ImagePageVars{Name: src, Full: fullsrc, Tags: tags, Form: form}

	encoder.Render(p.Encoding, 200, "image", p, r)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:18,代码来源:imagepage.go

示例7: ListThumb

func ListThumb(args martini.Params, su models.User, r render.Render, p *models.Page) {

	files, _ := ioutil.ReadDir(utils.ImageCfg.Root())

	var imageLinks []ImageLink

	for _, f := range files {
		if strings.Contains(f.Name(), ".") && !strings.HasPrefix(f.Name(), ".") {
			imageLinks = append(imageLinks, ImageLink{Title: f.Name(), FileName: f.Name()})
		}
	}

	p.SetUser(su)
	p.SetTitle("List", "Thumbs")
	p.Data = ListVars{Title: "All Images", Description: "Listing of all images in database", ImageLinks: imageLinks}

	encoder.Render(p.Encoding, 200, "test/thumbs", p, r)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:18,代码来源:listt.go

示例8: ImageTrash

func ImageTrash(args martini.Params, su models.User, dbh *db.Dbh, r render.Render, p *models.Page) {
	album := args["album"]
	name := args["name"]

	// Default status
	var status string = "Permission Denied"
	var code int = 401

	log.Printf("Trashing image: %s from %s", name, album)

	image := dbh.FirstImageByName(name)
	if su.Id == image.User {
		image.Trashed = true
		dbh.UpdateImage(image)
		status = "Success"
		code = 200
	}

	p.SetUser(su)
	p.Data = TrashRecover{Name: name, Album: album, Action: "Trash", Status: status}

	encoder.Render("json", code, "", p, r)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:23,代码来源:imagetrash.go

示例9: Tagged

func Tagged(args martini.Params, r render.Render, su models.User, dbh *db.Dbh, p *models.Page) {

	tag := args["tag"]

	images := dbh.GetImagesWithTag(tag)

	var imageLinks []imageLink
	for _, f := range images {
		if f.Trashed {
			log.Println("Trashed: ", f)
			continue
		}
		imageLinks = append(imageLinks, imageLink{Title: f.Name, FileName: f.Name})
	}

	p.SetUser(su)
	p.SetTitle("Tagged", tag)
	description := fmt.Sprintf("Images tagged as %s", tag)
	p.Data = TaggedVars{Title: tag, Description: description, ImageLinks: imageLinks}
	p.Encoding = "json"

	encoder.Render(p.Encoding, 200, "image_link", p, r)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:23,代码来源:tagged.go

示例10: Account

func Account(su models.User, session sessions.Session, r render.Render, dbh *db.Dbh, p *models.Page) {

	// Init error holder
	errs := make(map[string]string)

	account := forms.Account{}
	account.Id = su.Id
	account.Email = su.Email
	account.Name = su.Name

	username := su.UserName
	if username == "" {
		username = genUserName(su.Email, dbh)
	}
	account.UserName = username
	genform := utils.GenerateForm(&account, "/account", "POST", errs)

	p.SetTitle("Account")
	p.SetUser(su)
	p.Data = accountVars{Form: genform}

	encoder.Render(p.Encoding, 200, "account", p, r)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:23,代码来源:account.go

示例11: Album

func Album(args martini.Params, su models.User, session sessions.Session, r render.Render, dbh *db.Dbh, p *models.Page) {
	name := args["name"]
	auser := args["user"]
	key := args["key"]

	if auser != "" {
		log.Println("album user: ", auser)
	}

	album := dbh.GetAlbumByName(name)
	if su.Id != album.User && album.Private && album.Privatekey != key {
		session.Set("flash", "Login Required")
		r.Redirect(strings.Join([]string{utils.AppCfg.Url(), "login"}, "/"), http.StatusFound)
		return
	}

	images := dbh.GetAllImagesByAlbumId(album.Id)

	var imageLinks []imageLink
	for _, f := range images {
		if f.Trashed {
			continue
		}
		var file_name = f.Name
		if f.HashId != "" {
			file_name = f.HashId
		}
		log.Println(file_name, f)
		imageLinks = append(imageLinks, imageLink{Id: f.Id, Title: f.Name, FileName: file_name, Owner: f.User})
	}

	p.SetTitle("Album", name)
	p.SetUser(su)
	p.Data = AlbumVars{Title: name, Description: album.Description, ImageLinks: imageLinks}

	encoder.Render(p.Encoding, 200, "image_link", p, r)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:37,代码来源:album.go

示例12: Index

func Index(su models.User, r render.Render, p *models.Page) {

	p.SetUser(su)
	p.SetTitle("")
	encoder.Render(p.Encoding, 200, "index", p, r)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:6,代码来源:index.go

示例13: NotFound

func NotFound(su models.User, r render.Render, p *models.Page) {
	p.SetUser(su)
	p.SetTitle("404")
	encoder.Render(p.Encoding, 404, "notfound", p, r)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:5,代码来源:notfound.go


注:本文中的pixelrelay/models.Page.SetUser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。