Parcourir la source

Minor code cleanup on settings page to improve oauth account management UI. T713

pull/243/head
Nick Gerakines il y a 4 ans
Parent
révision
5d834c1cd2
3 fichiers modifiés avec 44 ajouts et 21 suppressions
  1. +17
    -2
      account.go
  2. +1
    -0
      templates.go
  3. +26
    -19
      templates/user/settings.tmpl

+ 17
- 2
account.go Voir le fichier

@@ -1038,11 +1038,24 @@ func viewSettings(app *App, u *User, w http.ResponseWriter, r *http.Request) err


flashes, _ := getSessionFlashes(app, w, r, nil) flashes, _ := getSessionFlashes(app, w, r, nil)


enableOauthSlack := app.Config().SlackOauth.ClientID != ""
enableOauthWriteAs := app.Config().WriteAsOauth.ClientID != ""

oauthAccounts, err := app.db.GetOauthAccounts(r.Context(), u.ID) oauthAccounts, err := app.db.GetOauthAccounts(r.Context(), u.ID)
if err != nil { if err != nil {
log.Error("Unable to get oauth accounts for settings: %s", err) log.Error("Unable to get oauth accounts for settings: %s", err)
return impart.HTTPError{http.StatusInternalServerError, "Unable to retrieve user data. The humans have been alerted."} return impart.HTTPError{http.StatusInternalServerError, "Unable to retrieve user data. The humans have been alerted."}
} }
for _, oauthAccount := range oauthAccounts {
switch oauthAccount.Provider {
case "slack":
enableOauthSlack = false
case "write.as":
enableOauthWriteAs = false
}
}

displayOauthSection := enableOauthSlack || enableOauthWriteAs || len(oauthAccounts) > 0


obj := struct { obj := struct {
*UserPage *UserPage
@@ -1050,6 +1063,7 @@ func viewSettings(app *App, u *User, w http.ResponseWriter, r *http.Request) err
HasPass bool HasPass bool
IsLogOut bool IsLogOut bool
Suspended bool Suspended bool
OauthSection bool
OauthAccounts []oauthAccountInfo OauthAccounts []oauthAccountInfo
OauthSlack bool OauthSlack bool
OauthWriteAs bool OauthWriteAs bool
@@ -1059,9 +1073,10 @@ func viewSettings(app *App, u *User, w http.ResponseWriter, r *http.Request) err
HasPass: passIsSet, HasPass: passIsSet,
IsLogOut: r.FormValue("logout") == "1", IsLogOut: r.FormValue("logout") == "1",
Suspended: fullUser.IsSilenced(), Suspended: fullUser.IsSilenced(),
OauthSection: displayOauthSection,
OauthAccounts: oauthAccounts, OauthAccounts: oauthAccounts,
OauthSlack: app.Config().SlackOauth.ClientID != "",
OauthWriteAs: app.Config().WriteAsOauth.ClientID != "",
OauthSlack: enableOauthSlack,
OauthWriteAs: enableOauthWriteAs,
} }


showUserPage(w, "settings", obj) showUserPage(w, "settings", obj)


+ 1
- 0
templates.go Voir le fichier

@@ -37,6 +37,7 @@ var (
"localstr": localStr, "localstr": localStr,
"localhtml": localHTML, "localhtml": localHTML,
"tolower": strings.ToLower, "tolower": strings.ToLower,
"title": strings.Title,
} }
) )




+ 26
- 19
templates/user/settings.tmpl Voir le fichier

@@ -67,26 +67,33 @@ h3 { font-weight: normal; }
</div> </div>
</form> </form>


{{ if .OauthAccounts }}
{{ range $oauth_account := .OauthAccounts }}
<form method="post" action="/me/oauth/remove" autocomplete="false">
<input type="hidden" name="provider" value="{{ $oauth_account.Provider }}" />
<input type="hidden" name="client_id" value="{{ $oauth_account.ClientID }}" />
<input type="hidden" name="remote_user_id" value="{{ $oauth_account.RemoteUserID }}" />
<div class="option">
<h3>{{ $oauth_account.Provider }} </h3>
<div class="section">
<input type="submit" value="Remove" style="margin-left: 1em;" />
</div>
</div>
</form>
{{ if .OauthSection }}
<h1>OAuth Management</h1>
{{ if .OauthAccounts }}
<p>Existing OAuth accounts can be removed from your account.</p>
{{ range $oauth_account := .OauthAccounts }}
<form method="post" action="/me/oauth/remove" autocomplete="false">
<input type="hidden" name="provider" value="{{ $oauth_account.Provider }}" />
<input type="hidden" name="client_id" value="{{ $oauth_account.ClientID }}" />
<input type="hidden" name="remote_user_id" value="{{ $oauth_account.RemoteUserID }}" />
<div class="option">
<div class="section">
<input type="submit" value="Remove {{ $oauth_account.Provider | title }}" style="margin-left: 1em;" />
</div>
</div>
</form>
{{ end }}
{{ end }}
{{ if or .OauthSlack .OauthWriteAs }}
<p>
{{ if .OauthSlack }}
<a class="loginbtn" href="/oauth/slack?attach=t"><img alt="Sign in with Slack" height="40" width="172" src="/img/sign_in_with_slack.png" srcset="/img/sign_in_with_slack.png 1x, /img/sign_in_with_slack@2x.png 2x" /></a>
{{ end }}
{{ if .OauthWriteAs }}
<a class="btn cta loginbtn" id="writeas-login" href="/oauth/write.as?attach=t">Link your <strong>Write.as</strong> account.</a>
{{ end }}
</p>
{{ end }} {{ end }}
{{ end }}
{{ if .OauthSlack }}
<a class="loginbtn" href="/oauth/slack?attach=t"><img alt="Sign in with Slack" height="40" width="172" src="/img/sign_in_with_slack.png" srcset="/img/sign_in_with_slack.png 1x, /img/sign_in_with_slack@2x.png 2x" /></a>
{{ end }}
{{ if .OauthWriteAs }}
<a class="btn cta loginbtn" id="writeas-login" href="/oauth/write.as?attach=t">Link your <strong>Write.as</strong> account.</a>
{{ end }} {{ end }}
</div> </div>




Chargement…
Annuler
Enregistrer