Beispiel #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
}
Beispiel #2
0
func Openid(c *common.HTTPContext) (err error) {
	redirect, email, ok, err := gopenid.VerifyAuth(c.Req())
	if err != nil {
		return
	}
	if ok {
		email = strings.ToLower(email)
		c.Session().Values[common.SessionEmail] = email
		u := &User{Id: kol.Id(email)}
		err = c.DB().Get(u)
		if err == kol.NotFound {
			err = nil
			u.Email = email
			u.Ranking = 1
		}
		if err == nil {
			u.Language = common.GetLanguage(c.Req())
			u.DiplicityHost = c.Req().Host
			u.LastLoginAt = time.Now()
			err = c.DB().Set(u)
		}
	} else {
		delete(c.Session().Values, common.SessionEmail)
	}
	c.Close()
	c.Resp().Header().Set("Location", redirect.String())
	c.Resp().WriteHeader(302)
	fmt.Fprintln(c.Resp(), redirect.String())
	return
}
Beispiel #3
0
func AdminBecome(c *common.HTTPContext) (err error) {
	c.Session().Values[common.SessionEmail] = c.Req().FormValue("become")
	c.Close()
	c.Resp().Header().Set("Location", "/")
	c.Resp().WriteHeader(302)
	fmt.Fprintln(c.Resp(), "/")
	return
}
Beispiel #4
0
func Logout(c *common.HTTPContext) (err error) {
	delete(c.Session().Values, common.SessionEmail)
	c.Close()
	redirect := c.Req().FormValue("return_to")
	if redirect == "" {
		redirect = fmt.Sprintf("http://%v/", c.Req().Host)
	}
	c.Resp().Header().Set("Location", redirect)
	c.Resp().WriteHeader(302)
	fmt.Fprintln(c.Resp(), redirect)
	return
}
Beispiel #5
0
func AdminReindexGames(c *common.HTTPContext) (err error) {
	games := Games{}
	if err = c.DB().Query().All(&games); err != nil {
		return
	}
	for _, game := range games {
		if err = c.DB().Index(game); err != nil {
			return
		}
		fmt.Fprintf(c.Resp(), "Reindexed %#v\n", game.Id.String())
	}
	return
}
Beispiel #6
0
func AdminSetRank1(c *common.HTTPContext) (err error) {
	users := Users{}
	if err = c.DB().Query().All(&users); err != nil {
		return
	}
	for _, user := range users {
		user.Ranking = 1
		if err = c.DB().Set(&user); err != nil {
			return
		}
		fmt.Fprintf(c.Resp(), "Set rank of %#v to 1\n", user.Email)
	}
	return

}
Beispiel #7
0
func Login(c *common.HTTPContext) (err error) {
	redirect := c.Req().FormValue("return_to")
	if redirect == "" {
		redirect = fmt.Sprintf("http://%v/", c.Req().Host)
	}
	redirectUrl, err := url.Parse(redirect)
	if err != nil {
		return
	}
	url, err := gopenid.GetAuthURL(c.Req(), redirectUrl)
	if err != nil {
		return
	}
	c.Resp().Header().Set("Location", url.String())
	c.Resp().WriteHeader(302)
	fmt.Fprintln(c.Resp(), url.String())
	return
}
Beispiel #8
0
func Resolve(c *common.HTTPContext) (err error) {
	phase := &Phase{}
	if err = json.NewDecoder(c.Req().Body).Decode(phase); err != nil {
		return
	}
	state, err := phase.State()
	if err != nil {
		return
	}
	if err = state.Next(); err != nil {
		return
	}
	// Load the new godip phase from the state
	nextDipPhase := state.Phase()
	// Create a diplicity phase for the new phase
	nextPhase := &Phase{
		Ordinal:     phase.Ordinal + 1,
		Orders:      map[dip.Nation]map[dip.Province][]string{},
		Resolutions: map[dip.Province]string{},
		Season:      nextDipPhase.Season(),
		Year:        nextDipPhase.Year(),
		Type:        nextDipPhase.Type(),
	}
	// Set the new phase positions
	var resolutions map[dip.Province]error
	nextPhase.Units, nextPhase.SupplyCenters, nextPhase.Dislodgeds, nextPhase.Dislodgers, nextPhase.Bounces, resolutions = state.Dump()
	for prov, err := range resolutions {
		if err == nil {
			nextPhase.Resolutions[prov] = "OK"
		} else {
			nextPhase.Resolutions[prov] = err.Error()
		}
	}
	c.Resp().Header().Set("Content-Type", "application/json; charset=UTF-8")
	if err = json.NewEncoder(c.Resp()).Encode(nextPhase); err != nil {
		return
	}
	return
}