Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

feature: add optional to show legal docs on signup/signin (#394)

Guilherme Oenning01bf0f070abb
diff --git a/Makefile b/Makefile
index 89682d3d1..141e1cc87 100644
--- a/Makefile
+++ b/Makefile
@@ -39,6 +39,8 @@ e2e:
# Development
watch:
+ rm -rf ./dist
+ mkdir ./dist
air -c air.conf &
npx webpack -w
diff --git a/app/actions/idea.go b/app/actions/idea.go
index 45d808bdc..4162bc599 100644
--- a/app/actions/idea.go
+++ b/app/actions/idea.go
@@ -38,7 +38,7 @@ func (input *CreateNewIdea) Validate(user *models.User, services *app.Services)
}
if len(input.Model.Title) > 100 {
- result.AddFieldFailure("title", "Title must be less than 100 characters.")
+ result.AddFieldFailure("title", "Title must have less than 100 characters.")
}
idea, err := services.Ideas.GetBySlug(slug.Make(input.Model.Title))
@@ -84,7 +84,7 @@ func (input *UpdateIdea) Validate(user *models.User, services *app.Services) *va
}
if len(input.Model.Title) > 100 {
- result.AddFieldFailure("title", "Title must be less than 100 characters.")
+ result.AddFieldFailure("title", "Title must have less than 100 characters.")
}
another, err := services.Ideas.GetBySlug(slug.Make(input.Model.Title))
diff --git a/app/actions/invite.go b/app/actions/invite.go
index fe67540e5..cd8685b79 100644
--- a/app/actions/invite.go
+++ b/app/actions/invite.go
@@ -35,7 +35,7 @@ func (input *InviteUsers) Validate(user *models.User, services *app.Services) *v
if input.Model.Subject == "" {
result.AddFieldFailure("subject", "Subject is required.")
} else if len(input.Model.Subject) > 70 {
- result.AddFieldFailure("subject", "Subject must be less than 70 characters.")
+ result.AddFieldFailure("subject", "Subject must have less than 70 characters.")
}
if input.Model.Message == "" {
diff --git a/app/actions/settings.go b/app/actions/settings.go
index 1a589a38e..9a0d7d733 100644
--- a/app/actions/settings.go
+++ b/app/actions/settings.go
@@ -33,7 +33,7 @@ func (input *UpdateUserSettings) Validate(user *models.User, services *app.Servi
}
if len(input.Model.Name) > 50 {
- result.AddFieldFailure("name", "Name must be less than 50 characters.")
+ result.AddFieldFailure("name", "Name must have less than 50 characters.")
}
if input.Model.Settings != nil {
diff --git a/app/actions/signin.go b/app/actions/signin.go
index c9bc3b7ba..fbbcf8c90 100644
--- a/app/actions/signin.go
+++ b/app/actions/signin.go
@@ -33,7 +33,7 @@ func (input *SignInByEmail) Validate(user *models.User, services *app.Services)
}
if len(input.Model.Email) > 200 {
- result.AddFieldFailure("email", "Email must be less than 200 characters.")
+ result.AddFieldFailure("email", "Email must have less than 200 characters.")
}
emailResult := validate.Email(input.Model.Email)
@@ -69,7 +69,7 @@ func (input *CompleteProfile) Validate(user *models.User, services *app.Services
}
if len(input.Model.Name) > 50 {
- result.AddFieldFailure("name", "Name must be less than 50 characters.")
+ result.AddFieldFailure("name", "Name must have less than 50 characters.")
}
if input.Model.Key == "" {
diff --git a/app/actions/tag.go b/app/actions/tag.go
index af87aa36a..4ffd4d949 100644
--- a/app/actions/tag.go
+++ b/app/actions/tag.go
@@ -43,7 +43,7 @@ func (input *CreateEditTag) Validate(user *models.User, services *app.Services)
if input.Model.Name == "" {
result.AddFieldFailure("name", "Name is required.")
} else if len(input.Model.Name) > 30 {
- result.AddFieldFailure("name", "Name must be less than 30 characters.")
+ result.AddFieldFailure("name", "Name must have less than 30 characters.")
} else {
duplicateTag, err := services.Tags.GetBySlug(slug.Make(input.Model.Name))
if err != nil && errors.Cause(err) != app.ErrNotFound {
diff --git a/app/actions/tenant.go b/app/actions/tenant.go
index 0e245fe06..14954b716 100644
--- a/app/actions/tenant.go
+++ b/app/actions/tenant.go
@@ -51,8 +51,8 @@ func (input *CreateTenant) Validate(user *models.User, services *app.Services) *
if input.Model.Name == "" {
result.AddFieldFailure("name", "Name is required.")
}
- if len(input.Model.Name) > 50 {
- result.AddFieldFailure("name", "Name must be less than 50 characters.")
+ if len(input.Model.Name) > 60 {
+ result.AddFieldFailure("name", "Name must have less than 60 characters.")
}
}
@@ -69,6 +69,10 @@ func (input *CreateTenant) Validate(user *models.User, services *app.Services) *
result.AddFieldFailure("subdomain", subdomainResult.Messages...)
}
+ if env.HasLegal() && !input.Model.LegalAgreement {
+ result.AddFieldFailure("legalAgreement", "You must agree before proceeding.")
+ }
+
return result
}
diff --git a/app/actions/tenant_test.go b/app/actions/tenant_test.go
index 32823340a..1058b47a8 100644
--- a/app/actions/tenant_test.go
+++ b/app/actions/tenant_test.go
@@ -23,7 +23,12 @@ func TestCreateTenant_ShouldHaveVerificationKey(t *testing.T) {
func TestCreateTenant_EmptyToken(t *testing.T) {
RegisterT(t)
- action := actions.CreateTenant{Model: &models.CreateTenant{Token: ""}}
+ action := actions.CreateTenant{
+ Model: &models.CreateTenant{
+ Token: "",
+ LegalAgreement: true,
+ },
+ }
result := action.Validate(nil, services)
ExpectFailed(result, "token", "tenantName", "subdomain")
}
@@ -31,7 +36,13 @@ func TestCreateTenant_EmptyToken(t *testing.T) {
func TestCreateTenant_EmptyTenantName(t *testing.T) {
RegisterT(t)
- action := actions.CreateTenant{Model: &models.CreateTenant{Token: jonSnowToken, TenantName: ""}}
+ action := actions.CreateTenant{
+ Model: &models.CreateTenant{
+ Token: jonSnowToken,
+ TenantName: "",
+ LegalAgreement: true,
+ },
+ }
result := action.Validate(nil, services)
ExpectFailed(result, "tenantName", "subdomain")
}
@@ -39,7 +50,13 @@ func TestCreateTenant_EmptyTenantName(t *testing.T) {
func TestCreateTenant_EmptyEmail(t *testing.T) {
RegisterT(t)
- action := actions.CreateTenant{Model: &models.CreateTenant{Name: "Jon Snow", Email: ""}}
+ action := actions.CreateTenant{
+ Model: &models.CreateTenant{
+ Name: "Jon Snow",
+ Email: "",
+ LegalAgreement: true,
+ },
+ }
result := action.Validate(nil, services)
ExpectFailed(result, "email", "tenantName", "subdomain")
}
@@ -47,15 +64,43 @@ func TestCreateTenant_EmptyEmail(t *testing.T) {
func TestCreateTenant_InvalidEmail(t *testing.T) {
RegisterT(t)
- action := actions.CreateTenant{Model: &models.CreateTenant{Name: "Jon Snow", Email: "jonsnow"}}
+ action := actions.CreateTenant{
+ Model: &models.CreateTenant{
+ Name: "Jon Snow",
+ Email: "jonsnow",
+ LegalAgreement: true,
+ },
+ }
result := action.Validate(nil, services)
ExpectFailed(result, "email", "tenantName", "subdomain")
}
+func TestCreateTenant_NoAgreement(t *testing.T) {
+ RegisterT(t)
+
+ action := actions.CreateTenant{
+ Model: &models.CreateTenant{
+ Name: "Jon",
+ Email: "[email protected]",
+ TenantName: "My Company",
+ Subdomain: "company",
+ LegalAgreement: false,
+ },
+ }
+ result := action.Validate(nil, services)
+ ExpectFailed(result, "legalAgreement")
+}
+
func TestCreateTenant_EmptyName(t *testing.T) {
RegisterT(t)
- action := actions.CreateTenant{Model: &models.CreateTenant{Name: "", Email: "[email protected]"}}
+ action := actions.CreateTenant{
+ Model: &models.CreateTenant{
+ Name: "",
+ Email: "[email protected]",
+ LegalAgreement: true,
+ },
+ }
result := action.Validate(nil, services)
ExpectFailed(result, "name", "tenantName", "subdomain")
}
@@ -63,7 +108,13 @@ func TestCreateTenant_EmptyName(t *testing.T) {
func TestCreateTenant_EmptySubdomain(t *testing.T) {
RegisterT(t)
- action := actions.CreateTenant{Model: &models.CreateTenant{Token: jonSnowToken, TenantName: "My Company"}}
+ action := actions.CreateTenant{
+ Model: &models.CreateTenant{
+ Token: jonSnowToken,
+ TenantName: "My Company",
+ LegalAgreement: true,
+ },
+ }
result := action.Validate(nil, services)
ExpectFailed(result, "subdomain")
}
diff --git a/app/actions/user.go b/app/actions/user.go
index 40c10647e..d77e177b0 100644
--- a/app/actions/user.go
+++ b/app/actions/user.go
@@ -72,7 +72,7 @@ func (input *ChangeUserEmail) Validate(user *models.User, services *app.Services
}
if len(input.Model.Email) > 200 {
- result.AddFieldFailure("email", "Email must be less than 200 characters.")
+ result.AddFieldFailure("email", "Email must have less than 200 characters.")
return result
}
diff --git a/app/cmd/routes.go b/app/cmd/routes.go
index 025bba675..34224de18 100644
--- a/app/cmd/routes.go
+++ b/app/cmd/routes.go
@@ -28,6 +28,8 @@ func routes(r *web.Engine) *web.Engine {
noTenant := r.Group()
{
+ noTenant.Get("/privacy", handlers.LegalPage("Privacy Policy", "privacy.md"))
+ noTenant.Get("/terms", handlers.LegalPage("Terms of Service", "terms.md"))
noTenant.Get("/-/health", handlers.Health())
noTenant.Post("/api/tenants", handlers.CreateTenant())
diff --git a/app/handlers/common.go b/app/handlers/common.go
index 9f8211a30..1465d8661 100644
--- a/app/handlers/common.go
+++ b/app/handlers/common.go
@@ -1,10 +1,13 @@
package handlers
import (
+ "io/ioutil"
+ "net/http"
"time"
"github.com/getfider/fider/app"
"github.com/getfider/fider/app/models"
+ "github.com/getfider/fider/app/pkg/env"
"github.com/getfider/fider/app/pkg/errors"
"github.com/getfider/fider/app/pkg/web"
)
@@ -16,6 +19,23 @@ func Health() web.HandlerFunc {
}
}
+//LegalPage returns a legal page with content from a file
+func LegalPage(title, file string) web.HandlerFunc {
+ return func(c web.Context) error {
+ bytes, err := ioutil.ReadFile(env.Etc(file))
+ if err != nil {
+ return c.NotFound()
+ }
+
+ return c.Render(http.StatusOK, "legal.html", web.Props{
+ Title: title,
+ Data: web.Map{
+ "Content": string(bytes),
+ },
+ })
+ }
+}
+
//Page returns a page without properties
func Page(title, description string) web.HandlerFunc {
return func(c web.Context) error {
diff --git a/app/handlers/common_test.go b/app/handlers/common_test.go
new file mode 100644
index 000000000..b62bca740
--- /dev/null
+++ b/app/handlers/common_test.go
@@ -0,0 +1,50 @@
+package handlers_test
+
+import (
+ "net/http"
+ "testing"
+
+ "github.com/getfider/fider/app/handlers"
+ . "github.com/getfider/fider/app/pkg/assert"
+ "github.com/getfider/fider/app/pkg/mock"
+)
+
+func TestHealthHandler(t *testing.T) {
+ RegisterT(t)
+
+ server, _ := mock.NewServer()
+ code, _ := server.
+ Execute(handlers.Health())
+
+ Expect(code).Equals(http.StatusOK)
+}
+
+func TestPageHandler(t *testing.T) {
+ RegisterT(t)
+
+ server, _ := mock.NewServer()
+ code, _ := server.
+ Execute(handlers.Page("The Title", "The Description"))
+
+ Expect(code).Equals(http.StatusOK)
+}
+
+func TestLegalPageHandler(t *testing.T) {
+ RegisterT(t)
+
+ server, _ := mock.NewServer()
+ code, _ := server.
+ Execute(handlers.LegalPage("Terms of Service", "terms.md"))
+
+ Expect(code).Equals(http.StatusOK)
+}
+
+func TestLegalPageHandler_Invalid(t *testing.T) {
+ RegisterT(t)
+
+ server, _ := mock.NewServer()
+ code, _ := server.
+ Execute(handlers.LegalPage("Some Page", "somepage.md"))
+
+ Expect(code).Equals(http.StatusNotFound)
+}
diff --git a/app/handlers/signup_test.go b/app/handlers/signup_test.go
index 7474fea86..247aafaa0 100644
--- a/app/handlers/signup_test.go
+++ b/app/handlers/signup_test.go
@@ -94,7 +94,12 @@ func TestCreateTenantHandler_WithSocialAccount(t *testing.T) {
})
code, response := server.ExecutePostAsJSON(
handlers.CreateTenant(),
- fmt.Sprintf(`{ "token": "%s", "tenantName": "My Company", "subdomain": "mycompany" }`, token),
+ fmt.Sprintf(`{
+ "token": "%s",
+ "tenantName": "My Company",
+ "subdomain": "mycompany",
+ "legalAgreement": true
+ }`, token),
)
tenant, err := services.Tenants.GetByDomain("mycompany")
@@ -121,7 +126,13 @@ func TestCreateTenantHandler_WithEmailAndName(t *testing.T) {
server, services := mock.NewServer()
code, response := server.ExecutePostAsJSON(
handlers.CreateTenant(),
- `{ "name": "Jon Snow", "email": "[email protected]", "tenantName": "My Company", "subdomain": "mycompany" }`,
+ `{
+ "name": "Jon Snow",
+ "email": "[email protected]",
+ "tenantName": "My Company",
+ "subdomain": "mycompany",
+ "legalAgreement": true
+ }`,
)
Expect(code).Equals(http.StatusOK)
diff --git a/app/models/identity.go b/app/models/identity.go
index ffc783bd5..cc48bfddb 100644
--- a/app/models/identity.go
+++ b/app/models/identity.go
@@ -122,6 +122,7 @@ type CreateTenant struct {
Email string `json:"email" format:"lower"`
VerificationKey string
TenantName string `json:"tenantName"`
+ LegalAgreement bool `json:"legalAgreement"`
Subdomain string `json:"subdomain" format:"lower"`
UserClaims *OAuthClaims
}
diff --git a/app/models/infra.go b/app/models/infra.go
index 724c4a20b..04314e553 100644
--- a/app/models/infra.go
+++ b/app/models/infra.go
@@ -13,6 +13,7 @@ type SystemSettings struct {
GoogleAnalytics string `json:"googleAnalytics"`
Compiler string `json:"compiler"`
Domain string `json:"domain"`
+ HasLegal bool `json:"hasLegal"`
}
// Notification is the system generated notification entity
diff --git a/app/pkg/env/env.go b/app/pkg/env/env.go
index 6da94ad6f..19b83e815 100644
--- a/app/pkg/env/env.go
+++ b/app/pkg/env/env.go
@@ -44,6 +44,19 @@ func IsSingleHostMode() bool {
return Mode() == "single"
}
+var hasLegal *bool
+
+// HasLegal returns true if current instance contains legal documents: privacy.md and terms.md
+func HasLegal() bool {
+ if hasLegal == nil {
+ _, err1 := os.Stat(Etc("privacy.md"))
+ _, err2 := os.Stat(Etc("terms.md"))
+ exists := err1 == nil && err2 == nil
+ hasLegal = &exists
+ }
+ return *hasLegal
+}
+
// MultiTenantDomain returns domain name of current instance for multi tenant hosts
func MultiTenantDomain() string {
if !IsSingleHostMode() {
diff --git a/app/pkg/env/env_test.go b/app/pkg/env/env_test.go
index a4fe4f4e3..3dde7a989 100644
--- a/app/pkg/env/env_test.go
+++ b/app/pkg/env/env_test.go
@@ -82,6 +82,12 @@ func TestMustGet(t *testing.T) {
}).Panics()
}
+func TestHasLegal(t *testing.T) {
+ RegisterT(t)
+
+ Expect(env.HasLegal()).IsTrue()
+}
+
func TestMultiTenantDomain(t *testing.T) {
RegisterT(t)
diff --git a/app/pkg/validate/general.go b/app/pkg/validate/general.go
index faeaf3dea..16df5d545 100644
--- a/app/pkg/validate/general.go
+++ b/app/pkg/validate/general.go
@@ -17,7 +17,7 @@ func Email(email string) *Result {
email = strings.ToLower(email)
if len(email) > 200 {
- return Failed([]string{"Email address must be less than 200 characters."})
+ return Failed([]string{"Email address must have less than 200 characters."})
}
if !emailRegex.MatchString(email) {
diff --git a/app/pkg/validate/subdomain.go b/app/pkg/validate/subdomain.go
index 95d41ab4b..668b00d2b 100644
--- a/app/pkg/validate/subdomain.go
+++ b/app/pkg/validate/subdomain.go
@@ -16,11 +16,11 @@ func Subdomain(tenants storage.Tenant, subdomain string) *Result {
subdomain = strings.ToLower(subdomain)
if len(subdomain) <= 2 {
- return Failed([]string{"Subdomain must be more than 2 characters."})
+ return Failed([]string{"Subdomain must have more than 2 characters."})
}
if len(subdomain) > 40 {
- return Failed([]string{"Subdomain must be less than 40 characters."})
+ return Failed([]string{"Subdomain must have less than 40 characters."})
}
if !domainRegex.MatchString(subdomain) {
diff --git a/app/pkg/web/renderer.go b/app/pkg/web/renderer.go
index 10f4c097e..1121609e4 100644
--- a/app/pkg/web/renderer.go
+++ b/app/pkg/web/renderer.go
@@ -12,6 +12,7 @@ import (
"github.com/getfider/fider/app/pkg/env"
"github.com/getfider/fider/app/pkg/errors"
"github.com/getfider/fider/app/pkg/log"
+ "github.com/getfider/fider/app/pkg/markdown"
"github.com/getfider/fider/app/pkg/md5"
"github.com/getfider/fider/app/pkg/oauth"
)
@@ -20,6 +21,9 @@ var templateFunctions = template.FuncMap{
"md5": func(input string) string {
return md5.Hash(input)
},
+ "markdown": func(input string) template.HTML {
+ return markdown.Parse(input)
+ },
}
//Renderer is the default HTML Render
@@ -41,6 +45,7 @@ func NewRenderer(settings *models.SystemSettings, logger log.Logger) *Renderer {
r.add("index.html")
r.add("not-invited.html")
+ r.add("legal.html")
r.add("403.html")
r.add("404.html")
r.add("410.html")
diff --git a/etc/privacy.md b/etc/privacy.md
new file mode 100644
index 000000000..752558543
--- /dev/null
+++ b/etc/privacy.md
@@ -0,0 +1,3 @@
+# Privacy Policy
+
+THIS IS A PLACEHOLDER FOR PRIVACY POLICY. REPLACE WITH YOUR OWN.
\ No newline at end of file
diff --git a/etc/terms.md b/etc/terms.md
new file mode 100644
index 000000000..849d34220
--- /dev/null
+++ b/etc/terms.md
@@ -0,0 +1,3 @@
+# Terms of Service
+
+THIS IS A PLACEHOLDER FOR TERMS OF SERVICE. REPLACE WITH YOUR OWN.
\ No newline at end of file
diff --git a/main.go b/main.go
index c4c9b1f19..03473dcb0 100644
--- a/main.go
+++ b/main.go
@@ -33,6 +33,7 @@ func main() {
GoogleAnalytics: env.GetEnvOrDefault("GOOGLE_ANALYTICS", ""),
Mode: env.Mode(),
Domain: env.MultiTenantDomain(),
+ HasLegal: env.HasLegal(),
}
args := os.Args[1:]
diff --git a/public/assets/styles/main.scss b/public/assets/styles/main.scss
index e194d0454..1cc8bd688 100644
--- a/public/assets/styles/main.scss
+++ b/public/assets/styles/main.scss
@@ -1,6 +1,7 @@
@import 'variables.scss';
@import 'reset.scss';
@import 'grid.scss';
+@import 'semantic.scss';
/*******************************
Site
@@ -79,6 +80,12 @@ p:last-child {
margin-bottom: 0;
}
+ul {
+ li {
+ line-height: 130%;
+ }
+}
+
/*******************************
Links
*******************************/
@@ -158,7 +165,7 @@ a:hover {
.page {
flex: 1 0 auto;
- margin-top: 30px;
+ margin-top: 10px;
}
.page::after {
@@ -309,6 +316,31 @@ h1, h2, h3, h4, h5 {
}
}
+.legal-page {
+ max-width: 800px !important;
+ padding: 50px 0;
+ h1 {
+ margin-bottom: 30px;
+ }
+ p {
+ line-height: 150%;
+ }
+
+ table {
+ tr {
+ th {
+ padding: 5px;
+ border-bottom: 1px solid $gray;
+ background-color: $gray-lighter;
+ }
+ td {
+ border-bottom: 1px solid $gray;
+ padding: 5px;
+ }
+ }
+ }
+}
+
.c-divider {
display: table;
font-weight: 700;
diff --git a/public/assets/styles/semantic.scss b/public/assets/styles/semantic.scss
new file mode 100644
index 000000000..ba7a9489d
--- /dev/null
+++ b/public/assets/styles/semantic.scss
@@ -0,0 +1,5 @@
+@import 'variables.scss';
+
+.ui.dropdown .menu > .item {
+ font-size: $font-size;
+}
\ No newline at end of file
diff --git a/public/components/SignInModal.tsx b/public/components/SignInModal.tsx
index f07413a20..a83bf3e6a 100644
--- a/public/components/SignInModal.tsx
+++ b/public/components/SignInModal.tsx
@@ -1,5 +1,5 @@
import * as React from "react";
-import { Modal, SignInControl } from "@fider/components/common";
+import { Modal, SignInControl, LegalFooter } from "@fider/components/common";
interface SignInModalProps {
isOpen: boolean;
@@ -59,6 +59,8 @@ export class SignInModal extends React.Component<SignInModalProps, SignInModalSt
<Modal.Header>Sign in to raise your voice</Modal.Header>
<Modal.Content>{content}</Modal.Content>
+
+ <LegalFooter />
</Modal.Window>
);
}
diff --git a/public/components/common/Legal.tsx b/public/components/common/Legal.tsx
new file mode 100644
index 000000000..9d3ce3c68
--- /dev/null
+++ b/public/components/common/Legal.tsx
@@ -0,0 +1,43 @@
+import * as React from "react";
+import { Modal, Field, Checkbox } from "@fider/components/common";
+import { page } from "@fider/services";
+
+const privacy = (
+ <a href="/privacy" target="_blank">
+ privacy policy
+ </a>
+);
+
+const terms = (
+ <a href="/terms" target="_blank">
+ terms of service
+ </a>
+);
+
+interface LegalAgreementProps {
+ onChange: (agrred: boolean) => void;
+}
+
+export const LegalFooter: React.StatelessComponent<{}> = () => {
+ if (page.systemSettings().hasLegal) {
+ return (
+ <Modal.Footer align="center">
+ <p className="info">
+ By signing in, you agree to the {privacy} and {terms}.
+ </p>
+ </Modal.Footer>
+ );
+ }
+ return null;
+};
+
+export const LegalAgreement: React.StatelessComponent<LegalAgreementProps> = props => {
+ if (page.systemSettings().hasLegal) {
+ return (
+ <Checkbox field="legalAgreement" onChange={props.onChange}>
+ I have read and agree to the {privacy} and {terms}.
+ </Checkbox>
+ );
+ }
+ return null;
+};
diff --git a/public/components/common/Modal.scss b/public/components/common/Modal.scss
index 4ff48bf3f..722474b41 100644
--- a/public/components/common/Modal.scss
+++ b/public/components/common/Modal.scss
@@ -63,6 +63,14 @@
background: #f9fafb;
padding: 10px;
border-top: 1px solid rgba(34,36,38,.15);
- text-align: right;
+ &.m-right {
+ text-align: right;
+ }
+ &.m-center {
+ text-align: center;
+ }
+ &.m-left {
+ text-align: left;
+ }
}
}
\ No newline at end of file
diff --git a/public/components/common/Modal.tsx b/public/components/common/Modal.tsx
index fc2d6b583..8fd44a480 100644
--- a/public/components/common/Modal.tsx
+++ b/public/components/common/Modal.tsx
@@ -17,6 +17,11 @@ interface ModalWindowState {
isOpen: boolean;
}
+interface ModalFooterProps {
+ align?: "left" | "center" | "right";
+ children?: React.ReactNode;
+}
+
class ModalWindow extends React.Component<ModalWindowProps, ModalWindowState> {
private root?: HTMLElement;
@@ -107,7 +112,12 @@ export const Modal = {
Content: (props: { children: React.ReactNode }) => {
return <div className="c-modal-content">{props.children}</div>;
},
- Footer: (props: { children: React.ReactNode }) => {
- return <div className="c-modal-footer">{props.children}</div>;
+ Footer: (props: ModalFooterProps) => {
+ const align = props.align || "right";
+ const className = classSet({
+ "c-modal-footer": true,
+ [`m-${align}`]: true
+ });
+ return <div className={className}>{props.children}</div>;
}
};
diff --git a/public/components/common/SignInControl.tsx b/public/components/common/SignInControl.tsx
index b8f117254..b4be889e1 100644
--- a/public/components/common/SignInControl.tsx
+++ b/public/components/common/SignInControl.tsx
@@ -50,7 +50,7 @@ export class SignInControl extends React.Component<SignInControlProps, SignInCon
public render() {
const google = this.settings.providers.google && (
- <div className="col-md-4 l-social-col">
+ <div className="col-sm l-social-col">
<SocialSignInButton
oauthEndpoint={this.settings.endpoint}
provider="google"
@@ -59,7 +59,7 @@ export class SignInControl extends React.Component<SignInControlProps, SignInCon
</div>
);
const facebook = this.settings.providers.facebook && (
- <div className="col-md-4 l-social-col">
+ <div className="col-sm l-social-col">
<SocialSignInButton
oauthEndpoint={this.settings.endpoint}
provider="facebook"
@@ -68,7 +68,7 @@ export class SignInControl extends React.Component<SignInControlProps, SignInCon
</div>
);
const github = this.settings.providers.github && (
- <div className="col-md-4 l-social-col">
+ <div className="col-sm l-social-col">
<SocialSignInButton
oauthEndpoint={this.settings.endpoint}
provider="github"
@@ -87,7 +87,7 @@ export class SignInControl extends React.Component<SignInControlProps, SignInCon
{google}
{github}
</div>
- <p className="info">We'll never post to any of your accounts</p>
+ <p className="info">We will never post to these accounts on your behalf.</p>
<div className="c-divider">OR</div>
</div>
)}
diff --git a/public/components/common/form/Checkbox.tsx b/public/components/common/form/Checkbox.tsx
new file mode 100644
index 000000000..37b61e500
--- /dev/null
+++ b/public/components/common/form/Checkbox.tsx
@@ -0,0 +1,57 @@
+import * as React from "react";
+import { Failure, classSet } from "@fider/services";
+import { DisplayError, ValidationContext, hasError } from "../";
+import { ECANCELED } from "constants";
+
+interface CheckboxProps {
+ field: string;
+ checked?: boolean;
+ onChange: (checked: boolean) => void;
+}
+
+interface CheckboxState {
+ checked: boolean;
+}
+
+export class Checkbox extends React.Component<CheckboxProps, CheckboxState> {
+ constructor(props: CheckboxProps) {
+ super(props);
+ this.state = {
+ checked: props.checked || false
+ };
+ }
+
+ private onChange = (e: React.FormEvent<HTMLInputElement>) => {
+ this.setState({ checked: e.currentTarget.checked }, () => {
+ if (this.props.onChange) {
+ this.props.onChange(this.state.checked);
+ }
+ });
+ };
+
+ public render() {
+ return (
+ <ValidationContext.Consumer>
+ {ctx => (
+ <div
+ className={classSet({
+ "c-form-field m-checkbox": true,
+ "m-error": hasError(this.props.field, ctx.error)
+ })}
+ >
+ <label htmlFor={`input-${this.props.field}`}>
+ <input
+ id={`input-${this.props.field}`}
+ type="checkbox"
+ defaultChecked={this.props.checked}
+ onChange={this.onChange}
+ />
+ {this.props.children}
+ </label>
+ <DisplayError fields={[this.props.field]} error={ctx.error} />
+ </div>
+ )}
+ </ValidationContext.Consumer>
+ );
+ }
+}
diff --git a/public/components/common/form/Form.scss b/public/components/common/form/Form.scss
index a8868776d..3b0ba8a34 100644
--- a/public/components/common/form/Form.scss
+++ b/public/components/common/form/Form.scss
@@ -18,6 +18,20 @@
clear: both;
margin: 0 0 10px;
+ &:last-child {
+ margin-bottom: 0;
+ }
+
+ &.m-checkbox {
+ label {
+ font-weight: initial;
+ }
+ input[type=checkbox] {
+ vertical-align: middle;
+ margin: 0 5px 3px 0;
+ }
+ }
+
label {
display: block;
margin: 0 0 5px;
@@ -56,6 +70,7 @@
opacity: .45;
cursor: not-allowed;
}
+
& + .icon {
pointer-events: none;
cursor: default;
diff --git a/public/components/common/index.tsx b/public/components/common/index.tsx
index 4f1359500..f7ac117b1 100644
--- a/public/components/common/index.tsx
+++ b/public/components/common/index.tsx
@@ -6,6 +6,7 @@ export * from "./form/RadioButton";
export * from "./form/DisplayError";
export * from "./form/Select";
export * from "./form/Field";
+export * from "./form/Checkbox";
export * from "./MultiLineText";
export * from "./EnvironmentInfo";
export * from "./Gravatar";
@@ -13,6 +14,7 @@ export * from "./Message";
export * from "./Footer";
export * from "./Header";
export * from "./Heading";
+export * from "./Legal";
export * from "./SocialSignInButton";
export * from "./SignInControl";
export * from "./Segment";
diff --git a/public/models/settings.ts b/public/models/settings.ts
index 5080a6b38..d7b8b90bd 100644
--- a/public/models/settings.ts
+++ b/public/models/settings.ts
@@ -7,6 +7,7 @@ export interface SystemSettings {
googleAnalytics: string;
compiler: string;
domain: string;
+ hasLegal: boolean;
}
export interface AuthSettings {
diff --git a/public/pages/CompleteSignInProfile/CompleteSignInProfile.page.tsx b/public/pages/CompleteSignInProfile/CompleteSignInProfile.page.tsx
index 9ff33eb73..9b92b4912 100644
--- a/public/pages/CompleteSignInProfile/CompleteSignInProfile.page.tsx
+++ b/public/pages/CompleteSignInProfile/CompleteSignInProfile.page.tsx
@@ -1,7 +1,7 @@
import * as React from "react";
import { HomePage, HomePageProps, SignInPage } from "../";
-import { Modal, Button, Form, Input } from "@fider/components";
+import { Modal, Button, Form, Input, LegalFooter } from "@fider/components";
import { page, actions, Failure } from "@fider/services";
interface CompleteSignInProfilePageState {
@@ -35,13 +35,13 @@ export class CompleteSignInProfilePage extends React.Component<HomePageProps, Co
<Modal.Window canClose={false} isOpen={true}>
<Modal.Header>Complete your profile</Modal.Header>
<Modal.Content>
- <p>Because this is your first sign in, please input your display name.</p>
+ <p>Because this is your first sign in, please enter your name.</p>
<Form error={this.state.error}>
<Input
field="name"
onChange={name => this.setState({ name })}
maxLength={100}
- placeholder="Your display name"
+ placeholder="Name"
suffix={
<Button onClick={() => this.submit()} color="positive" disabled={this.state.name === ""}>
Submit
@@ -50,6 +50,7 @@ export class CompleteSignInProfilePage extends React.Component<HomePageProps, Co
/>
</Form>
</Modal.Content>
+ <LegalFooter />
</Modal.Window>
{this.props.tenant.isPrivate
? React.createElement(SignInPage, this.props)
diff --git a/public/pages/SignUp/SignUp.page.scss b/public/pages/SignUp/SignUp.page.scss
index d8c3f1178..d8566e3b6 100644
--- a/public/pages/SignUp/SignUp.page.scss
+++ b/public/pages/SignUp/SignUp.page.scss
@@ -8,7 +8,7 @@
display: block;
}
- .ui.basic.red.label {
- width: auto;
+ .c-button.m-positive {
+ margin-top: 20px;
}
}
\ No newline at end of file
diff --git a/public/pages/SignUp/SignUp.page.tsx b/public/pages/SignUp/SignUp.page.tsx
index 4aceca204..67a0721bc 100644
--- a/public/pages/SignUp/SignUp.page.tsx
+++ b/public/pages/SignUp/SignUp.page.tsx
@@ -1,7 +1,7 @@
import "./SignUp.page.scss";
import * as React from "react";
-import { SignInControl, Modal, Button, DisplayError, Form, Input, Message } from "@fider/components";
+import { SignInControl, Modal, Button, DisplayError, Form, Input, Message, LegalAgreement } from "@fider/components";
import { SystemSettings } from "@fider/models";
import { jwt, page, actions, Failure } from "@fider/services";
@@ -20,6 +20,7 @@ interface SignUpPageProps {
interface SignUpPageState {
submitted: boolean;
tenantName: string;
+ legalAgreement: boolean;
error?: Failure;
name?: string;
email?: string;
@@ -37,6 +38,7 @@ export class SignUpPage extends React.Component<SignUpPageProps, SignUpPageState
super(props);
this.state = {
submitted: false,
+ legalAgreement: false,
tenantName: "",
subdomain: { available: false }
};
@@ -57,6 +59,7 @@ export class SignUpPage extends React.Component<SignUpPageProps, SignUpPageState
private async confirm() {
const result = await actions.createTenant({
token: this.user && this.user.token,
+ legalAgreement: this.state.legalAgreement,
tenantName: this.state.tenantName,
subdomain: this.state.subdomain.value,
name: this.state.name,
@@ -95,6 +98,10 @@ export class SignUpPage extends React.Component<SignUpPageProps, SignUpPageState
});
}
+ private onAgree = (agreed: boolean): void => {
+ this.setState({ legalAgreement: agreed });
+ };
+
public render() {
const modal = (
<Modal.Window canClose={false} isOpen={this.state.submitted}>
@@ -125,13 +132,8 @@ export class SignUpPage extends React.Component<SignUpPageProps, SignUpPageState
<p>We need to identify you to setup your new Fider account.</p>
<SignInControl useEmail={false} />
<Form error={this.state.error}>
- <Input field="name" maxLength={100} onChange={name => this.setState({ name })} placeholder="your name" />
- <Input
- field="email"
- maxLength={200}
- onChange={email => this.setState({ email })}
- placeholder="[email protected]"
- />
+ <Input field="name" maxLength={100} onChange={name => this.setState({ name })} placeholder="Name" />
+ <Input field="email" maxLength={200} onChange={email => this.setState({ email })} placeholder="Email" />
</Form>
</>
)}
@@ -159,9 +161,13 @@ export class SignUpPage extends React.Component<SignUpPageProps, SignUpPageState
)}
</Form>
- <h3>3. Review and continue</h3>
+ <h3>3. Review</h3>
+
+ <p>Make sure information provided above is correct.</p>
- <p>Make sure information provided above is correct before proceeding.</p>
+ <Form error={this.state.error}>
+ <LegalAgreement onChange={this.onAgree} />
+ </Form>
<Button color="positive" size="large" onClick={() => this.confirm()}>
Confirm
diff --git a/public/services/actions/tenant.ts b/public/services/actions/tenant.ts
index 073f1f7b0..13d598d2b 100644
--- a/public/services/actions/tenant.ts
+++ b/public/services/actions/tenant.ts
@@ -6,6 +6,7 @@ export interface CheckAvailabilityResponse {
}
export interface CreateTenantRequest {
+ legalAgreement: boolean;
tenantName: string;
subdomain?: string;
name?: string;
diff --git a/views/legal.html b/views/legal.html
new file mode 100644
index 000000000..1c8d7a0ee
--- /dev/null
+++ b/views/legal.html
@@ -0,0 +1,7 @@
+{{define "javascript"}}{{end}}
+
+{{define "content"}}
+ <div class="container legal-page">
+ {{ .Content | markdown }}
+ </div>
+{{end}}
\ No newline at end of file