diff --git a/cmd/web-app/handlers/account.go b/cmd/web-app/handlers/account.go
index f43a11e..03a32d7 100644
--- a/cmd/web-app/handlers/account.go
+++ b/cmd/web-app/handlers/account.go
@@ -209,13 +209,8 @@ func (h *Account) Update(ctx context.Context, w http.ResponseWriter, r *http.Req
webcontext.SessionFlashSuccess(ctx,
"Account Updated",
"Account profile successfully updated.")
- err = webcontext.ContextSession(ctx).Save(r, w)
- if err != nil {
- return false, err
- }
- http.Redirect(w, r, "/account", http.StatusFound)
- return true, nil
+ return true, web.Redirect(ctx, w, r, "/account", http.StatusFound)
}
acc, err := account.ReadByID(ctx, claims, h.MasterDB, claims.Audience)
diff --git a/cmd/web-app/handlers/projects.go b/cmd/web-app/handlers/projects.go
index 8aac2ba..1025e60 100644
--- a/cmd/web-app/handlers/projects.go
+++ b/cmd/web-app/handlers/projects.go
@@ -203,13 +203,8 @@ func (h *Projects) Create(ctx context.Context, w http.ResponseWriter, r *http.Re
webcontext.SessionFlashSuccess(ctx,
"Project Created",
"Project successfully created.")
- err = webcontext.ContextSession(ctx).Save(r, w)
- if err != nil {
- return false, err
- }
- http.Redirect(w, r, urlProjectsView(usr.ID), http.StatusFound)
- return true, nil
+ return true, web.Redirect(ctx, w, r, urlProjectsView(usr.ID), http.StatusFound)
}
return false, nil
@@ -266,13 +261,8 @@ func (h *Projects) View(ctx context.Context, w http.ResponseWriter, r *http.Requ
webcontext.SessionFlashSuccess(ctx,
"Project Archive",
"Project successfully archive.")
- err = webcontext.ContextSession(ctx).Save(r, w)
- if err != nil {
- return false, err
- }
- http.Redirect(w, r, urlProjectsIndex(), http.StatusFound)
- return true, nil
+ return true, web.Redirect(ctx, w, r, urlProjectsIndex(), http.StatusFound)
}
}
@@ -347,13 +337,8 @@ func (h *Projects) Update(ctx context.Context, w http.ResponseWriter, r *http.Re
webcontext.SessionFlashSuccess(ctx,
"Project Updated",
"Project successfully updated.")
- err = webcontext.ContextSession(ctx).Save(r, w)
- if err != nil {
- return false, err
- }
- http.Redirect(w, r, urlProjectsView(req.ID), http.StatusFound)
- return true, nil
+ return true, web.Redirect(ctx, w, r, urlProjectsView(req.ID), http.StatusFound)
}
return false, nil
diff --git a/cmd/web-app/handlers/root.go b/cmd/web-app/handlers/root.go
index 93c1726..a327e42 100644
--- a/cmd/web-app/handlers/root.go
+++ b/cmd/web-app/handlers/root.go
@@ -40,12 +40,10 @@ func (h *Root) indexDashboard(ctx context.Context, w http.ResponseWriter, r *htt
// indexDefault loads the root index page when a user has no authentication.
func (u *Root) indexDefault(ctx context.Context, w http.ResponseWriter, r *http.Request, params map[string]string) error {
-
return u.Renderer.Render(ctx, w, r, tmplLayoutSite, "site-index.gohtml", web.MIMETextHTMLCharsetUTF8, http.StatusOK, nil)
-
}
-// indexDefault loads the root index page when a user has no authentication.
+// SitePage loads the page with the layout for site instead of the app base.
func (u *Root) SitePage(ctx context.Context, w http.ResponseWriter, r *http.Request, params map[string]string) error {
var tmpName string
@@ -63,18 +61,15 @@ func (u *Root) SitePage(ctx context.Context, w http.ResponseWriter, r *http.Requ
case "/legal/terms":
tmpName = "legal-terms.gohtml"
default:
- http.Redirect(w, r, "/", http.StatusFound)
- return nil
+ return web.Redirect(ctx, w, r, "/", http.StatusFound)
}
return u.Renderer.Render(ctx, w, r, tmplLayoutSite, tmpName, web.MIMETextHTMLCharsetUTF8, http.StatusOK, nil)
-
}
// IndexHtml redirects /index.html to the website root page.
func (u *Root) IndexHtml(ctx context.Context, w http.ResponseWriter, r *http.Request, params map[string]string) error {
- http.Redirect(w, r, "/", http.StatusMovedPermanently)
- return nil
+ return web.Redirect(ctx, w, r, "/", http.StatusMovedPermanently)
}
// RobotHandler returns a robots.txt response.
diff --git a/cmd/web-app/handlers/signup.go b/cmd/web-app/handlers/signup.go
index a25bd90..4f3ece4 100644
--- a/cmd/web-app/handlers/signup.go
+++ b/cmd/web-app/handlers/signup.go
@@ -86,14 +86,9 @@ func (h *Signup) Step1(ctx context.Context, w http.ResponseWriter, r *http.Reque
webcontext.SessionFlashSuccess(ctx,
"Thank you for Joining",
"You workflow will be a breeze starting today.")
- err = webcontext.ContextSession(ctx).Save(r, w)
- if err != nil {
- return false, err
- }
// Redirect the user to the dashboard.
- http.Redirect(w, r, "/", http.StatusFound)
- return true, nil
+ return true, web.Redirect(ctx, w, r, "/", http.StatusFound)
}
return false, nil
@@ -103,6 +98,10 @@ func (h *Signup) Step1(ctx context.Context, w http.ResponseWriter, r *http.Reque
if err != nil {
return web.RenderError(ctx, w, r, err, h.Renderer, TmplLayoutBase, TmplContentErrorGeneric, web.MIMETextHTMLCharsetUTF8)
} else if end {
+ err = webcontext.ContextSession(ctx).Save(r, w)
+ if err != nil {
+ return err
+ }
return nil
}
diff --git a/cmd/web-app/handlers/user.go b/cmd/web-app/handlers/user.go
index 119135a..9817ac1 100644
--- a/cmd/web-app/handlers/user.go
+++ b/cmd/web-app/handlers/user.go
@@ -112,8 +112,7 @@ func (h *User) Login(ctx context.Context, w http.ResponseWriter, r *http.Request
}
// Redirect the user to the dashboard.
- http.Redirect(w, r, redirectUri, http.StatusFound)
- return true, nil
+ return true, web.Redirect(ctx, w, r, redirectUri, http.StatusFound)
}
return false, nil
@@ -148,9 +147,7 @@ func (h *User) Logout(ctx context.Context, w http.ResponseWriter, r *http.Reques
}
// Redirect the user to the root page.
- http.Redirect(w, r, "/", http.StatusFound)
-
- return nil
+ return web.Redirect(ctx, w, r, "/", http.StatusFound)
}
// ResetPassword allows a user to perform forgot password.
@@ -281,8 +278,7 @@ func (h *User) ResetConfirm(ctx context.Context, w http.ResponseWriter, r *http.
}
// Redirect the user to the dashboard.
- http.Redirect(w, r, "/", http.StatusFound)
- return true, nil
+ return true, web.Redirect(ctx, w, r, "/", http.StatusFound)
}
_, err = user.ParseResetHash(ctx, h.SecretKey, resetHash, ctxValues.Now)
@@ -432,13 +428,8 @@ func (h *User) Update(ctx context.Context, w http.ResponseWriter, r *http.Reques
webcontext.SessionFlashSuccess(ctx,
"Profile Updated",
"User profile successfully updated.")
- err = webcontext.ContextSession(ctx).Save(r, w)
- if err != nil {
- return false, err
- }
- http.Redirect(w, r, "/user", http.StatusFound)
- return true, nil
+ return true, web.Redirect(ctx, w, r, "/user", http.StatusFound)
}
return false, nil
@@ -584,16 +575,8 @@ func (h *User) VirtualLogin(ctx context.Context, w http.ResponseWriter, r *http.
fmt.Sprintf("You are now virtually logged into user %s.",
usr.Response(ctx).Name))
- // Write the session to the client.
- err = webcontext.ContextSession(ctx).Save(r, w)
- if err != nil {
- return false, err
- }
-
// Redirect the user to the dashboard with the new credentials.
- http.Redirect(w, r, "/", http.StatusFound)
-
- return true, nil
+ return true, web.Redirect(ctx, w, r, "/", http.StatusFound)
}
return false, nil
@@ -724,9 +707,7 @@ func (h *User) VirtualLogout(ctx context.Context, w http.ResponseWriter, r *http
}
// Redirect the user to the dashboard with the new credentials.
- http.Redirect(w, r, "/", http.StatusFound)
-
- return nil
+ return web.Redirect(ctx, w, r, "/", http.StatusFound)
}
// VirtualLogin handles switching the scope of the context to another user.
@@ -800,16 +781,8 @@ func (h *User) SwitchAccount(ctx context.Context, w http.ResponseWriter, r *http
fmt.Sprintf("You are now logged into account %s.",
acc.Response(ctx).Name))
- // Write the session to the client.
- err = webcontext.ContextSession(ctx).Save(r, w)
- if err != nil {
- return false, err
- }
-
// Redirect the user to the dashboard with the new credentials.
- http.Redirect(w, r, "/", http.StatusFound)
-
- return true, nil
+ return true, web.Redirect(ctx, w, r, "/", http.StatusFound)
}
return false, nil
diff --git a/cmd/web-app/handlers/users.go b/cmd/web-app/handlers/users.go
index be36709..329311c 100644
--- a/cmd/web-app/handlers/users.go
+++ b/cmd/web-app/handlers/users.go
@@ -259,13 +259,8 @@ func (h *Users) Create(ctx context.Context, w http.ResponseWriter, r *http.Reque
webcontext.SessionFlashSuccess(ctx,
"User Created",
"User successfully created.")
- err = webcontext.ContextSession(ctx).Save(r, w)
- if err != nil {
- return false, err
- }
- http.Redirect(w, r, urlUsersView(usr.ID), http.StatusFound)
- return true, nil
+ return true, web.Redirect(ctx, w, r, urlUsersView(usr.ID), http.StatusFound)
}
return false, nil
@@ -333,13 +328,8 @@ func (h *Users) View(ctx context.Context, w http.ResponseWriter, r *http.Request
webcontext.SessionFlashSuccess(ctx,
"User Archive",
"User successfully archive.")
- err = webcontext.ContextSession(ctx).Save(r, w)
- if err != nil {
- return false, err
- }
- http.Redirect(w, r, urlUsersIndex(), http.StatusFound)
- return true, nil
+ return true, web.Redirect(ctx, w, r, urlUsersIndex(), http.StatusFound)
}
}
@@ -483,13 +473,8 @@ func (h *Users) Update(ctx context.Context, w http.ResponseWriter, r *http.Reque
webcontext.SessionFlashSuccess(ctx,
"User Updated",
"User successfully updated.")
- err = webcontext.ContextSession(ctx).Save(r, w)
- if err != nil {
- return false, err
- }
- http.Redirect(w, r, urlUsersView(req.ID), http.StatusFound)
- return true, nil
+ return true, web.Redirect(ctx, w, r, urlUsersView(req.ID), http.StatusFound)
}
return false, nil
@@ -607,13 +592,7 @@ func (h *Users) Invite(ctx context.Context, w http.ResponseWriter, r *http.Reque
"No users were invited.")
}
- err = webcontext.ContextSession(ctx).Save(r, w)
- if err != nil {
- return false, err
- }
-
- http.Redirect(w, r, urlUsersIndex(), http.StatusFound)
- return true, nil
+ return true, web.Redirect(ctx, w, r, urlUsersIndex(), http.StatusFound)
}
return false, nil
@@ -652,7 +631,7 @@ func (h *Users) InviteAccept(ctx context.Context, w http.ResponseWriter, r *http
}
//
- req := new(invite.AcceptInviteRequest)
+ req := new(invite.AcceptInviteUserRequest)
data := make(map[string]interface{})
f := func() (bool, error) {
@@ -670,30 +649,33 @@ func (h *Users) InviteAccept(ctx context.Context, w http.ResponseWriter, r *http
// Append the query param value to the request.
req.InviteHash = inviteHash
- hash, err := invite.AcceptInvite(ctx, h.MasterDB, *req, h.SecretKey, ctxValues.Now)
+ hash, err := invite.AcceptInviteUser(ctx, h.MasterDB, *req, h.SecretKey, ctxValues.Now)
if err != nil {
switch errors.Cause(err) {
case invite.ErrInviteExpired:
webcontext.SessionFlashError(ctx,
"Invite Expired",
"The invite has expired.")
+
return false, nil
+
case invite.ErrUserAccountActive:
webcontext.SessionFlashError(ctx,
"User already Active",
- "The user already is already active for the account. Try to login or use forgot password.")
- http.Redirect(w, r, "/user/login", http.StatusFound)
- return true, nil
- case invite.ErrInviteUserPasswordSet:
+ "The user is already is already active for the account. Try to login or use forgot password.")
+
+ return true, web.Redirect(ctx, w, r, "/user/login", http.StatusFound)
+
+ case invite.ErrNoPendingInvite:
webcontext.SessionFlashError(ctx,
- "Invite already Accepted",
+ "Invite Accepted",
"The invite has already been accepted. Try to login or use forgot password.")
- http.Redirect(w, r, "/user/login", http.StatusFound)
- return true, nil
+
+ return true, web.Redirect(ctx, w, r, "/user/login", http.StatusFound)
+
case user_account.ErrNotFound:
return false, err
- case invite.ErrNoPendingInvite:
- return false, err
+
default:
if verr, ok := weberror.NewValidationError(ctx, err); ok {
data["validationErrors"] = verr.(*weberror.Error)
@@ -732,36 +714,57 @@ func (h *Users) InviteAccept(ctx context.Context, w http.ResponseWriter, r *http
}
// Redirect the user to the dashboard.
- http.Redirect(w, r, "/", http.StatusFound)
- return true, nil
+ return true, web.Redirect(ctx, w, r, "/", http.StatusFound)
}
- hash, err := invite.ParseInviteHash(ctx, h.SecretKey, inviteHash, ctxValues.Now)
+ usrAcc, err := invite.AcceptInvite(ctx, h.MasterDB, invite.AcceptInviteRequest{
+ InviteHash: inviteHash,
+ }, h.SecretKey, ctxValues.Now)
if err != nil {
+
switch errors.Cause(err) {
case invite.ErrInviteExpired:
webcontext.SessionFlashError(ctx,
"Invite Expired",
"The invite has expired.")
- return false, nil
- case invite.ErrInviteUserPasswordSet:
+
+ return true, web.Redirect(ctx, w, r, "/user/login", http.StatusFound)
+
+ case invite.ErrUserAccountActive:
webcontext.SessionFlashError(ctx,
- "Invite already Accepted",
+ "User already Active",
+ "The user is already is already active for the account. Try to login or use forgot password.")
+
+ return true, web.Redirect(ctx, w, r, "/user/login", http.StatusFound)
+
+ case invite.ErrNoPendingInvite:
+ webcontext.SessionFlashError(ctx,
+ "Invite Accepted",
"The invite has already been accepted. Try to login or use forgot password.")
- http.Redirect(w, r, "/user/login", http.StatusFound)
- return true, nil
+
+ return true, web.Redirect(ctx, w, r, "/user/login", http.StatusFound)
+
+ case user_account.ErrNotFound:
+ return false, err
default:
if verr, ok := weberror.NewValidationError(ctx, err); ok {
data["validationErrors"] = verr.(*weberror.Error)
+
return false, nil
} else {
return false, err
}
}
+ } else if usrAcc.Status == user_account.UserAccountStatus_Active {
+ webcontext.SessionFlashError(ctx,
+ "Invite Accepted",
+ "The invite has been accepted. Login to continue.")
+
+ return true, web.Redirect(ctx, w, r, "/user/login", http.StatusFound)
}
// Read user by ID with no claims.
- usr, err := user.ReadByID(ctx, auth.Claims{}, h.MasterDB, hash.UserID)
+ usr, err := user.ReadByID(ctx, auth.Claims{}, h.MasterDB, usrAcc.UserID)
if err != nil {
return false, err
}
@@ -791,7 +794,7 @@ func (h *Users) InviteAccept(ctx context.Context, w http.ResponseWriter, r *http
data["form"] = req
- if verr, ok := weberror.NewValidationError(ctx, webcontext.Validator().Struct(invite.AcceptInviteRequest{})); ok {
+ if verr, ok := weberror.NewValidationError(ctx, webcontext.Validator().Struct(invite.AcceptInviteUserRequest{})); ok {
data["validationDefaults"] = verr.(*weberror.Error)
}
diff --git a/cmd/web-app/templates/content/user-view.gohtml b/cmd/web-app/templates/content/user-view.gohtml
index 60584fa..389d987 100644
--- a/cmd/web-app/templates/content/user-view.gohtml
+++ b/cmd/web-app/templates/content/user-view.gohtml
@@ -55,13 +55,13 @@
Role
{{ if .userAccount }}
- {{ range $r := .userAccount.Roles }}
- {{ if eq $r "admin" }}
- {{ $r }}
+ {{ range $r := .userAccount.Roles.Options }}{{ if $r.Selected }}
+ {{ if eq $r.Value "admin" }}
+ {{ $r.Title }}
{{else}}
- {{ $r }}
+ {{ $r.Title }}
{{end}}
- {{ end }}
+ {{ end }}{{ end }}
{{ end }}