예제 #1
0
파일: member.go 프로젝트: arlm/diplicity
func (self Members) Disallows(d *kol.DB, asking *user.User) (result bool, err error) {
	var askerList map[string]bool
	if askerList, err = asking.Blacklistings(d); err != nil {
		return
	}
	for _, member := range self {
		if askerList[member.UserId.String()] {
			result = true
			return
		}
	}
	for _, member := range self {
		memberUser := &user.User{Id: member.UserId}
		if err = d.Get(memberUser); err != nil {
			return
		}
		var memberList map[string]bool
		if memberList, err = memberUser.Blacklistings(d); err != nil {
			return
		}
		if memberList[asking.Id.String()] {
			result = true
			return
		}
	}
	return
}
예제 #2
0
파일: phase.go 프로젝트: arlm/diplicity
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
}
예제 #3
0
파일: message.go 프로젝트: arlm/diplicity
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+%v@%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
}
예제 #4
0
파일: game.go 프로젝트: JorenC/diplicity
func (self *Game) Disallows(u *user.User) bool {
	return (self.MinimumRanking != 0 && u.Ranking < self.MinimumRanking) ||
		(self.MaximumRanking != 0 && u.Ranking > self.MaximumRanking) ||
		u.Reliability() < self.MinimumReliability
}