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


Golang SkinnyContext.Secret方法代码示例

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


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

示例1: emailTo

func (self *Phase) emailTo(c common.SkinnyContext, game *Game, member *Member, user *user.User) (err error) {
	to := fmt.Sprintf("%v <%v>", member.Nation, user.Email)
	unsubTag := &common.UnsubscribeTag{
		T: common.UnsubscribePhaseEmail,
		U: user.Id,
	}
	unsubTag.H = unsubTag.Hash(c.Secret())
	encodedUnsubTag, err := unsubTag.Encode()
	if err != nil {
		return
	}
	contextLink, err := user.I("To see this in context: http://%v/games/%v", user.DiplicityHost, self.GameId)
	if err != nil {
		return
	}
	unsubLink, err := user.I("To unsubscribe: http://%v/unsubscribe/%v", user.DiplicityHost, encodedUnsubTag)
	if err != nil {
		return
	}
	text, err := user.I("A new phase has been created")
	if err != nil {
		return
	}
	subject, err := game.Describe(c, user)
	if err != nil {
		return
	}
	body := fmt.Sprintf(common.EmailTemplate, text, contextLink, unsubLink)
	go c.SendMail("diplicity", c.ReceiveAddress(), subject, body, []string{to})
	return
}
开发者ID:arlm,项目名称:diplicity,代码行数:31,代码来源:phase.go

示例2: emailTo

func (self *Message) emailTo(c common.SkinnyContext, game *Game, sender *Member, senderUser *user.User, recip *Member, recipUser *user.User, recipName string) (err error) {
	mailTag := &MailTag{
		M: self.Id,
		R: recip.Id,
	}
	mailTag.H = mailTag.Hash(c.Secret())
	encodedMailTag, err := mailTag.Encode()
	if err != nil {
		return
	}

	unsubTag := &common.UnsubscribeTag{
		T: common.UnsubscribeMessageEmail,
		U: recipUser.Id,
	}
	unsubTag.H = unsubTag.Hash(c.Secret())
	encodedUnsubTag, err := unsubTag.Encode()
	if err != nil {
		return
	}

	parts := strings.Split(c.ReceiveAddress(), "@")
	if len(parts) != 2 {
		if c.Env() == common.Development {
			parts = []string{"user", "host.tld"}
		} else {
			err = fmt.Errorf("Failed parsing %#v as an email address", c.ReceiveAddress())
			return
		}
	}
	senderName := sender.ShortName(game, senderUser)
	replyTo := fmt.Sprintf("%v+%[email protected]%v", parts[0], encodedMailTag, parts[1])
	to := fmt.Sprintf("%v <%v>", recipName, recipUser.Email)
	memberIds := []string{}
	for memberId, _ := range self.RecipientIds {
		memberIds = append(memberIds, memberId)
	}
	sort.Sort(sort.StringSlice(memberIds))
	contextLink, err := recipUser.I("To see this message in context: http://%v/games/%v/messages/%v", recipUser.DiplicityHost, self.GameId, self.ChannelId())
	if err != nil {
		return
	}
	unsubLink, err := recipUser.I("To unsubscribe: http://%v/unsubscribe/%v", recipUser.DiplicityHost, encodedUnsubTag)
	if err != nil {
		return
	}
	body := fmt.Sprintf(common.EmailTemplate, self.Body, contextLink, unsubLink)
	subject, err := game.Describe(c, recipUser)
	if err != nil {
		return
	}
	go c.SendMail(senderName, replyTo, subject, body, []string{to})
	return
}
开发者ID:arlm,项目名称:diplicity,代码行数:54,代码来源:message.go

示例3: IncomingMail

func IncomingMail(c common.SkinnyContext, msg *enmime.MIMEBody) (err error) {
	text := gmail.DecodeText(msg.Text, msg.GetHeader("Content-Type"))
	c.Debugf("Incoming mail to %#v\n%v", msg.GetHeader("To"), text)
	if match := gmail.AddrReg.FindString(msg.GetHeader("To")); match != "" {
		lines := []string{}
		mailUser := strings.Split(c.SendAddress(), "@")[0]
		for _, line := range strings.Split(text, "\n") {
			if !strings.Contains(line, mailUser) && strings.Index(line, ">") != 0 {
				lines = append(lines, line)
			}
		}
		for len(lines) > 0 && strings.TrimSpace(lines[0]) == "" {
			lines = lines[1:]
		}
		for len(lines) > 0 && strings.TrimSpace(lines[len(lines)-1]) == "" {
			lines = lines[:len(lines)-1]
		}
		if len(lines) > 0 {
			if match2 := emailPlusReg.FindStringSubmatch(match); match2 != nil {
				var tag *MailTag
				if tag, err = DecodeMailTag(c.Secret(), match2[1]); err == nil {
					sender := &Member{Id: tag.R}
					if err = c.DB().Get(sender); err != nil {
						return
					}
					parent := &Message{Id: tag.M}
					if err = c.DB().Get(parent); err != nil {
						return
					}
					game := &Game{Id: parent.GameId}
					if err = c.DB().Get(game); err != nil {
						return
					}
					message := &Message{
						Body:         strings.TrimSpace(strings.Join(lines, "\n")),
						GameId:       game.Id,
						RecipientIds: parent.RecipientIds,
					}
					c.Infof("Mail resulted in %+v from %+v", message, sender.Nation)
					return message.Send(c, game, sender)
				}
			}
		}
	}
	return nil
}
开发者ID:JorenC,项目名称:diplicity,代码行数:46,代码来源:message.go

示例4: SendScheduleEmails

func (self *Phase) SendScheduleEmails(c common.SkinnyContext, game *Game) {
	members, err := game.Members(c.DB())
	for _, member := range members {
		user := &user.User{Id: member.UserId}
		if err = c.DB().Get(user); err != nil {
			return
		}
		to := fmt.Sprintf("%v <%v>", member.Nation, user.Email)
		if !user.PhaseEmailDisabled && !c.IsSubscribing(user.Email, fmt.Sprintf("/games/%v", game.Id)) {
			unsubTag := &common.UnsubscribeTag{
				T: common.UnsubscribePhaseEmail,
				U: user.Id,
			}
			unsubTag.H = unsubTag.Hash(c.Secret())
			encodedUnsubTag, err := unsubTag.Encode()
			if err != nil {
				c.Errorf("Failed to encode %+v: %v", unsubTag, err)
				return
			}
			contextLink, err := user.I("To see this in context: http://%v/games/%v", user.DiplicityHost, self.GameId)
			if err != nil {
				c.Errorf("Failed translating context link: %v", err)
				return
			}
			unsubLink, err := user.I("To unsubscribe: http://%v/unsubscribe/%v", user.DiplicityHost, encodedUnsubTag)
			if err != nil {
				c.Errorf("Failed translating unsubscribe link: %v", err)
				return
			}
			text, err := user.I("A new phase has been created")
			if err != nil {
				c.Errorf("Failed translating: %v", err)
				return
			}
			subject, err := game.Describe(c, user)
			if err != nil {
				c.Errorf("Failed describing: %v", err)
				return
			}
			body := fmt.Sprintf(common.EmailTemplate, text, contextLink, unsubLink)
			c.SendMail("diplicity", c.ReceiveAddress(), subject, body, []string{to})
		}
	}
}
开发者ID:JorenC,项目名称:diplicity,代码行数:44,代码来源:phase.go


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