Make oauth prompt use its own context type
And use the common utility to populate the user information
This commit is contained in:
parent
749f8aaec7
commit
8623773edc
3 changed files with 34 additions and 29 deletions
18
sync/dash.go
18
sync/dash.go
|
|
@ -3,6 +3,7 @@ package sync
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"html/template"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
|
|
@ -28,6 +29,19 @@ var (
|
|||
sourceT = buildTemplate("source", "authenticated")
|
||||
)
|
||||
|
||||
type ContextDashboard struct {
|
||||
CountInspections int
|
||||
CountMosquitoSources int
|
||||
CountServiceRequests int
|
||||
Geo template.JS
|
||||
IsSyncOngoing bool
|
||||
LastSync *time.Time
|
||||
MapData ComponentMap
|
||||
Org string
|
||||
RecentRequests []ServiceRequestSummary
|
||||
User User
|
||||
}
|
||||
|
||||
type ContextDistrict struct {
|
||||
MapboxToken string
|
||||
}
|
||||
|
|
@ -85,7 +99,7 @@ func getRoot(w http.ResponseWriter, r *http.Request) {
|
|||
dashboard(r.Context(), w, user)
|
||||
return
|
||||
} else {
|
||||
oauthPrompt(w, user)
|
||||
oauthPrompt(w, r, user)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -224,7 +238,7 @@ func dashboard(ctx context.Context, w http.ResponseWriter, user *models.User) {
|
|||
respondError(w, "Failed to get user context", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
data := ContentDashboard{
|
||||
data := ContextDashboard{
|
||||
CountInspections: int(inspectionCount),
|
||||
CountMosquitoSources: int(sourceCount),
|
||||
CountServiceRequests: int(serviceCount),
|
||||
|
|
|
|||
|
|
@ -15,6 +15,10 @@ var (
|
|||
oauthPromptT = buildTemplate("oauth-prompt", "authenticated")
|
||||
)
|
||||
|
||||
type ContextOauthPrompt struct {
|
||||
User User
|
||||
}
|
||||
|
||||
func getArcgisOauthBegin(w http.ResponseWriter, r *http.Request) {
|
||||
authURL := config.BuildArcGISAuthURL(config.ClientID)
|
||||
http.Redirect(w, r, authURL, http.StatusFound)
|
||||
|
|
@ -46,17 +50,17 @@ func getOAuthRefresh(w http.ResponseWriter, r *http.Request) {
|
|||
http.Redirect(w, r, "/?next=/oauth/refresh", http.StatusFound)
|
||||
return
|
||||
}
|
||||
oauthPrompt(w, user)
|
||||
oauthPrompt(w, r, user)
|
||||
}
|
||||
|
||||
func oauthPrompt(w http.ResponseWriter, user *models.User) {
|
||||
dp := user.DisplayName
|
||||
data := ContentDashboard{
|
||||
User: User{
|
||||
DisplayName: dp,
|
||||
Initials: extractInitials(dp),
|
||||
Username: user.Username,
|
||||
},
|
||||
func oauthPrompt(w http.ResponseWriter, r *http.Request, user *models.User) {
|
||||
userContent, err := contentForUser(r.Context(), user)
|
||||
if err != nil {
|
||||
respondError(w, "Failed to get user content", err, http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
data := ContextOauthPrompt{
|
||||
User: userContent,
|
||||
}
|
||||
htmlpage.RenderOrError(w, oauthPromptT, data)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package sync
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"time"
|
||||
|
||||
"github.com/Gleipnir-Technology/nidus-sync/notification"
|
||||
|
|
@ -64,19 +63,6 @@ type ContentReportDetail struct {
|
|||
}
|
||||
type ContentReportDiagnostic struct {
|
||||
}
|
||||
type ContentDashboard struct {
|
||||
CountInspections int
|
||||
CountMosquitoSources int
|
||||
CountServiceRequests int
|
||||
Geo template.JS
|
||||
IsSyncOngoing bool
|
||||
LastSync *time.Time
|
||||
MapData ComponentMap
|
||||
Org string
|
||||
RecentRequests []ServiceRequestSummary
|
||||
User User
|
||||
}
|
||||
|
||||
type ContentDashboardLoading struct {
|
||||
User User
|
||||
}
|
||||
|
|
@ -114,8 +100,9 @@ type ServiceRequestSummary struct {
|
|||
Status string
|
||||
}
|
||||
type User struct {
|
||||
DisplayName string
|
||||
Initials string
|
||||
Notifications []notification.Notification
|
||||
Username string
|
||||
DisplayName string
|
||||
Initials string
|
||||
Notifications []notification.Notification
|
||||
OrganizationID int
|
||||
Username string
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue