()
| 604 | } |
| 605 | |
| 606 | func (h *SettingsHandler) ApplicationsPost() macaron.Handler { |
| 607 | return func(c *context.Context, f form.NewAccessToken) { |
| 608 | c.Title("settings.applications") |
| 609 | c.PageIs("SettingsApplications") |
| 610 | |
| 611 | if c.HasError() { |
| 612 | tokens, err := h.store.ListAccessTokens(c.Req.Context(), c.User.ID) |
| 613 | if err != nil { |
| 614 | c.Errorf(err, "list access tokens") |
| 615 | return |
| 616 | } |
| 617 | |
| 618 | c.Data["Tokens"] = tokens |
| 619 | c.HTML(http.StatusBadRequest, tmplUserSettingsApplications) |
| 620 | return |
| 621 | } |
| 622 | |
| 623 | t, err := h.store.CreateAccessToken(c.Req.Context(), c.User.ID, f.Name) |
| 624 | if err != nil { |
| 625 | if database.IsErrAccessTokenAlreadyExist(err) { |
| 626 | c.Flash.Error(c.Tr("settings.token_name_exists")) |
| 627 | c.RedirectSubpath("/user/settings/applications") |
| 628 | } else { |
| 629 | c.Errorf(err, "new access token") |
| 630 | } |
| 631 | return |
| 632 | } |
| 633 | |
| 634 | c.Flash.Success(c.Tr("settings.generate_token_succees")) |
| 635 | c.Flash.Info(t.Sha1) |
| 636 | c.RedirectSubpath("/user/settings/applications") |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | func (h *SettingsHandler) DeleteApplication() macaron.Handler { |
| 641 | return func(c *context.Context) { |
no test coverage detected