Ejemplo n.º 1
0
func UnsubscribeEmails(c *common.HTTPContext) (err error) {
	unsubTag, err := common.DecodeUnsubscribeTag(c.Secret(), c.Vars()["unsubscribe_tag"])
	if err != nil {
		return
	}
	u := &user.User{Id: unsubTag.U}
	if err = c.DB().Get(u); err != nil {
		return
	}
	switch unsubTag.T {
	case common.UnsubscribeMessageEmail:
		u.MessageEmailDisabled = true
	case common.UnsubscribePhaseEmail:
		u.MessageEmailDisabled = true
	}
	if err = c.DB().Set(u); err != nil {
		return
	}
	switch unsubTag.T {
	case common.UnsubscribeMessageEmail:
		fmt.Fprintf(c.Resp(), "%v has successfully been unsubscribed from message emails.", u.Email)
	case common.UnsubscribePhaseEmail:
		fmt.Fprintf(c.Resp(), "%v has successfully been unsubscribed from phase emails.", u.Email)
	}
	return
}
Ejemplo n.º 2
0
func Token(c *common.HTTPContext) (err error) {
	if emailIf, found := c.Session().Values[common.SessionEmail]; found {
		token := &gosubs.Token{
			Principal: fmt.Sprint(emailIf),
			Timeout:   time.Now().Add(time.Second * 10),
		}
		if err = token.Encode(c.Secret()); err != nil {
			return
		}
		err = c.RenderJSON(token)
	} else {
		err = c.RenderJSON(gosubs.Token{})
	}
	return
}