本文整理汇总了Golang中github.com/zond/diplicity/common.HTTPContext类的典型用法代码示例。如果您正苦于以下问题:Golang HTTPContext类的具体用法?Golang HTTPContext怎么用?Golang HTTPContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTTPContext类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: AdminCreateUser
func AdminCreateUser(c *common.HTTPContext) (err error) {
user := &User{}
if err = json.NewDecoder(c.Req().Body).Decode(user); err != nil {
return
}
err = c.DB().Set(user)
return
}
开发者ID:arlm,项目名称:diplicity,代码行数:8,代码来源:controller.go
示例2: AdminGetOptions
func AdminGetOptions(c *common.HTTPContext) (err error) {
gameId, err := base64.URLEncoding.DecodeString(c.Vars()["game_id"])
if err != nil {
return
}
game := &Game{Id: gameId}
if err = c.DB().Get(game); err != nil {
return
}
_, last, err := game.Phase(c.DB(), 0)
if err != nil {
return
}
opts, err := last.Options(dip.Nation(c.Vars()["nation"]))
if err != nil {
return
}
return c.RenderJSON(opts)
}
开发者ID:JorenC,项目名称:diplicity,代码行数:19,代码来源:controller.go
示例3: Token
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
}
开发者ID:arlm,项目名称:diplicity,代码行数:15,代码来源:controller.go
示例4: AdminRecalcOptions
func AdminRecalcOptions(c *common.HTTPContext) (err error) {
gameId, err := base64.URLEncoding.DecodeString(c.Vars()["game_id"])
if err != nil {
return
}
g := &Game{Id: gameId}
if err = c.DB().Get(g); err != nil {
return
}
_, last, err := g.Phase(c.DB(), 0)
if err != nil {
return
}
members, err := g.Members(c.DB())
if err != nil {
return
}
for index, _ := range members {
opts := dip.Options{}
if opts, err = last.Options(members[index].Nation); err != nil {
return
}
members[index].Options = opts
if len(opts) == 0 {
members[index].Committed = true
members[index].NoOrders = true
} else {
members[index].Committed = false
members[index].NoOrders = false
}
if err = c.DB().Set(&members[index]); err != nil {
return
}
}
return
}
开发者ID:JorenC,项目名称:diplicity,代码行数:36,代码来源:controller.go
示例5: AdminReindexGames
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
}
开发者ID:JorenC,项目名称:diplicity,代码行数:13,代码来源:controller.go
示例6: AdminSetRank1
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
}
开发者ID:arlm,项目名称:diplicity,代码行数:15,代码来源:controller.go
示例7: Resolve
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
}
开发者ID:arlm,项目名称:diplicity,代码行数:39,代码来源:controller.go
示例8: AdminBecome
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
}
开发者ID:arlm,项目名称:diplicity,代码行数:8,代码来源:controller.go
示例9: Logout
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
}
开发者ID:arlm,项目名称:diplicity,代码行数:12,代码来源:controller.go
示例10: AdminGetGame
func AdminGetGame(c *common.HTTPContext) (err error) {
gameId, err := base64.URLEncoding.DecodeString(c.Vars()["game_id"])
if err != nil {
return
}
g := &Game{Id: gameId}
if err = c.DB().Get(g); err != nil {
return
}
members, err := g.Members(c.DB())
if err != nil {
return
}
memberStates, err := members.ToStates(c.DB(), g, "", true)
if err != nil {
return
}
phases, err := g.Phases(c.DB())
if err != nil {
return
}
sort.Sort(phases)
return c.RenderJSON(AdminGameState{
Game: g,
Phases: phases,
Members: memberStates,
})
}
开发者ID:JorenC,项目名称:diplicity,代码行数:28,代码来源:controller.go
示例11: UnsubscribeEmails
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
}
开发者ID:JorenC,项目名称:diplicity,代码行数:26,代码来源:controller.go
示例12: AdminRollback
func AdminRollback(c *common.HTTPContext) (err error) {
gameId, err := base64.URLEncoding.DecodeString(c.Vars()["game_id"])
if err != nil {
return
}
epoch, err := epoch.Get(c.DB())
if err != nil {
return
}
g := &Game{Id: gameId}
if err = c.DB().Get(g); err != nil {
return
}
ordinal, err := strconv.Atoi(c.Vars()["until"])
if err != nil {
return
}
members, err := g.Members(c.DB())
if err != nil {
return
}
phases, err := g.Phases(c.DB())
if err != nil {
return
}
sort.Sort(phases)
for index, _ := range phases {
phase := &phases[index]
if phase.Ordinal == ordinal {
phase.Resolutions = map[dip.Province]string{}
phase.Resolved = false
phase.Deadline = epoch + (time.Minute * time.Duration(g.Deadlines[phase.Type]))
for index, _ := range members {
opts := dip.Options{}
if opts, err = phase.Options(members[index].Nation); err != nil {
return
}
members[index].Options = opts
if len(opts) == 0 {
members[index].Committed = true
members[index].NoOrders = true
} else {
members[index].Committed = false
members[index].NoOrders = false
}
if err = c.DB().Set(&members[index]); err != nil {
return
}
}
if err = c.DB().Set(phase); err != nil {
return
}
} else if phase.Ordinal > ordinal {
if err = c.DB().Del(phase); err != nil {
return
}
}
}
return
}
开发者ID:JorenC,项目名称:diplicity,代码行数:60,代码来源:controller.go
示例13: Openid
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
}
开发者ID:JorenC,项目名称:diplicity,代码行数:30,代码来源:controller.go
示例14: Login
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
}
开发者ID:JorenC,项目名称:diplicity,代码行数:18,代码来源:controller.go
注:本文中的github.com/zond/diplicity/common.HTTPContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论