Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Allow administrators to use custom domain names (#151)

Guilherme Oenningdab273b8ff20
diff --git a/app/actions/tenant.go b/app/actions/tenant.go
index 515d070ab..cc1211e67 100644
--- a/app/actions/tenant.go
+++ b/app/actions/tenant.go
@@ -50,10 +50,6 @@ func (input *CreateTenant) Validate(services *app.Services) *validate.Result {
}
}
- if len(input.Model.Email) > 200 {
- result.AddFieldFailure("email", "E-mail must be less than 200 characters.")
- }
-
if input.Model.Name == "" {
result.AddFieldFailure("name", "Name is required.")
}
@@ -110,5 +106,11 @@ func (input *UpdateTenantSettings) Validate(services *app.Services) *validate.Re
result.AddFieldFailure("invitation", "Invitation must have less than 60 characters.")
}
+ if input.Model.CNAME != "" {
+ if cnameResult := validate.CNAME(services.Tenants, input.Model.CNAME); !cnameResult.Ok {
+ result.AddFieldFailure("cname", cnameResult.Messages...)
+ }
+ }
+
return result
}
diff --git a/app/actions/tenant_test.go b/app/actions/tenant_test.go
index 11386f343..1f34df7d0 100644
--- a/app/actions/tenant_test.go
+++ b/app/actions/tenant_test.go
@@ -65,6 +65,19 @@ func TestCreateTenant_EmptySubdomain(t *testing.T) {
result := action.Validate(services)
ExpectFailed(result, "subdomain")
}
+func TestUpdateTenantSettings_Unauthorized(t *testing.T) {
+ RegisterTestingT(t)
+
+ admin := &models.User{ID: 1, Role: models.RoleAdministrator}
+ collaborator := &models.User{ID: 2, Role: models.RoleCollaborator}
+
+ action := actions.UpdateTenantSettings{}
+ action.Initialize()
+
+ Expect(action.IsAuthorized(admin)).To(BeTrue())
+ Expect(action.IsAuthorized(collaborator)).To(BeFalse())
+ Expect(action.IsAuthorized(nil)).To(BeFalse())
+}
func TestUpdateTenantSettings_EmptyTitle(t *testing.T) {
RegisterTestingT(t)
@@ -74,6 +87,14 @@ func TestUpdateTenantSettings_EmptyTitle(t *testing.T) {
ExpectFailed(result, "title")
}
+func TestUpdateTenantSettings_InvalidCNAME(t *testing.T) {
+ RegisterTestingT(t)
+
+ action := actions.UpdateTenantSettings{Model: &models.UpdateTenantSettings{Title: "Ok", CNAME: "bla"}}
+ result := action.Validate(services)
+ ExpectFailed(result, "cname")
+}
+
func TestUpdateTenantSettings_LargeTitle(t *testing.T) {
RegisterTestingT(t)
diff --git a/app/models/identity.go b/app/models/identity.go
index 163bc7402..a3d6f5d50 100644
--- a/app/models/identity.go
+++ b/app/models/identity.go
@@ -106,6 +106,7 @@ type UpdateTenantSettings struct {
Title string `json:"title"`
Invitation string `json:"invitation"`
WelcomeMessage string `json:"welcomeMessage"`
+ CNAME string `json:"cname" format:"lower"`
UserClaims *OAuthClaims
}
diff --git a/app/pkg/env/env.go b/app/pkg/env/env.go
index 31a2805de..5eeca9205 100644
--- a/app/pkg/env/env.go
+++ b/app/pkg/env/env.go
@@ -47,8 +47,13 @@ func IsSingleHostMode() bool {
func MultiTenantDomain() string {
if !IsSingleHostMode() {
endpoint := MustGet("AUTH_ENDPOINT")
- if idx := strings.Index(endpoint, "."); idx != -1 {
- return endpoint[idx:]
+ firstIdx := strings.Index(endpoint, ".")
+ if firstIdx != -1 {
+ lastIdx := strings.LastIndex(endpoint, ":")
+ if lastIdx != -1 && lastIdx > firstIdx {
+ return endpoint[firstIdx:lastIdx]
+ }
+ return endpoint[firstIdx:]
}
panic(fmt.Sprintf("Could not extract domain from %s", endpoint))
}
diff --git a/app/pkg/env/env_test.go b/app/pkg/env/env_test.go
index 62cd2c2dd..2892c8700 100644
--- a/app/pkg/env/env_test.go
+++ b/app/pkg/env/env_test.go
@@ -55,3 +55,16 @@ func TestMustGet(t *testing.T) {
env.MustGet("THIS_DOES_NOT_EXIST")
}).To(Panic())
}
+
+func TestMultiTenantDomain(t *testing.T) {
+ RegisterTestingT(t)
+
+ os.Setenv("AUTH_ENDPOINT", "https://login.test.fider.io:3000")
+ Expect(env.MultiTenantDomain()).To(Equal(".test.fider.io"))
+
+ os.Setenv("AUTH_ENDPOINT", "https://login.test.fider.io")
+ Expect(env.MultiTenantDomain()).To(Equal(".test.fider.io"))
+
+ os.Setenv("HOST_MODE", "single")
+ Expect(env.MultiTenantDomain()).To(Equal(""))
+}
diff --git a/app/pkg/validate/email_test.go b/app/pkg/validate/email_test.go
deleted file mode 100644
index f9d8398ae..000000000
--- a/app/pkg/validate/email_test.go
+++ /dev/null
@@ -1,45 +0,0 @@
-package validate_test
-
-import (
- "testing"
-
- "github.com/getfider/fider/app/pkg/validate"
- . "github.com/onsi/gomega"
-)
-
-func TestInvalidEmail(t *testing.T) {
- RegisterTestingT(t)
-
- for _, email := range []string{
- "hello",
- "",
- "my@company",
- "my @company.com",
- "my+company.com",
- "@gmail.com",
- "abc12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890@gmail.com",
- } {
- result := validate.Email(email)
- Expect(result.Ok).To(BeFalse())
- Expect(len(result.Messages) > 0).To(BeTrue())
- Expect(result.Error).To(BeNil())
- }
-}
-
-func TestValidEmail(t *testing.T) {
- RegisterTestingT(t)
-
- for _, email := range []string{
- } {
- result := validate.Email(email)
- Expect(result.Ok).To(BeTrue())
- Expect(len(result.Messages)).To(Equal(0))
- Expect(result.Error).To(BeNil())
- }
-}
diff --git a/app/pkg/validate/email.go b/app/pkg/validate/general.go
similarity index 60%
rename from app/pkg/validate/email.go
rename to app/pkg/validate/general.go
index 21838824c..8db6b84fc 100644
--- a/app/pkg/validate/email.go
+++ b/app/pkg/validate/general.go
@@ -1,11 +1,16 @@
package validate
import (
+ "fmt"
"regexp"
"strings"
+
+ "github.com/getfider/fider/app/pkg/env"
+ "github.com/getfider/fider/app/storage"
)
var emailRegex = regexp.MustCompile("^(((([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+(\\.([a-zA-Z]|\\d|[!#\\$%&'\\*\\+\\-\\/=\\?\\^_`{\\|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|\\.|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.)+(([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-zA-Z]|\\d|-|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-zA-Z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.?$")
+var hostnameRegex = regexp.MustCompile(`^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$`)
//Email validates given email address
func Email(email string) *Result {
@@ -21,3 +26,34 @@ func Email(email string) *Result {
return Success()
}
+
+//CNAME validates given cname
+func CNAME(tenants storage.Tenant, cname string) *Result {
+ cname = strings.ToLower(cname)
+
+ if !env.IsSingleHostMode() {
+ domain := env.MultiTenantDomain()
+ if strings.HasSuffix(cname, domain) || cname == domain[1:] {
+ return Failed([]string{fmt.Sprintf("'%s' is not a valid custom domain.", cname)})
+ }
+ }
+
+ if len(cname) > 100 {
+ return Failed([]string{"Custom domain name must have less than 100 characters."})
+ }
+
+ if !hostnameRegex.MatchString(cname) || strings.Index(cname, ".") == -1 {
+ return Failed([]string{fmt.Sprintf("'%s' is not a valid custom domain.", cname)})
+ }
+
+ available, err := tenants.IsCNAMEAvailable(cname)
+ if err != nil {
+ return Error(err)
+ }
+
+ if !available {
+ return Failed([]string{"This custom domain is already in use by someone else."})
+ }
+
+ return Success()
+}
diff --git a/app/pkg/validate/general_test.go b/app/pkg/validate/general_test.go
new file mode 100644
index 000000000..cf9d1fcf3
--- /dev/null
+++ b/app/pkg/validate/general_test.go
@@ -0,0 +1,115 @@
+package validate_test
+
+import (
+ "testing"
+
+ "github.com/getfider/fider/app/models"
+ "github.com/getfider/fider/app/pkg/validate"
+ "github.com/getfider/fider/app/storage/inmemory"
+ . "github.com/onsi/gomega"
+)
+
+func TestInvalidEmail(t *testing.T) {
+ RegisterTestingT(t)
+
+ for _, email := range []string{
+ "hello",
+ "",
+ "my@company",
+ "my @company.com",
+ "my+company.com",
+ "@gmail.com",
+ "abc12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890@gmail.com",
+ } {
+ result := validate.Email(email)
+ Expect(result.Ok).To(BeFalse())
+ Expect(len(result.Messages) > 0).To(BeTrue())
+ Expect(result.Error).To(BeNil())
+ }
+}
+
+func TestValidEmail(t *testing.T) {
+ RegisterTestingT(t)
+
+ for _, email := range []string{
+ } {
+ result := validate.Email(email)
+ Expect(result.Ok).To(BeTrue())
+ Expect(len(result.Messages)).To(Equal(0))
+ Expect(result.Error).To(BeNil())
+ }
+}
+
+func TestInvalidCNAME(t *testing.T) {
+ RegisterTestingT(t)
+
+ for _, cname := range []string{
+ "hello",
+ "hellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohellohello.com",
+ "",
+ "my",
+ "name.com/abc",
+ "feedback.test.fider.io",
+ "test.fider.io",
+ "@google.com",
+ } {
+ result := validate.CNAME(&inmemory.TenantStorage{}, cname)
+ Expect(result.Ok).To(BeFalse())
+ Expect(len(result.Messages) > 0).To(BeTrue())
+ Expect(result.Error).To(BeNil())
+ }
+}
+
+func TestValidHostname(t *testing.T) {
+ RegisterTestingT(t)
+ for _, cname := range []string{
+ "google.com",
+ "feedback.fider.io",
+ "my.super.domain.com",
+ "jon-snow.got.com",
+ "got.com",
+ "hi.m",
+ } {
+ result := validate.CNAME(&inmemory.TenantStorage{}, cname)
+ Expect(result.Ok).To(BeTrue())
+ Expect(len(result.Messages)).To(Equal(0))
+ Expect(result.Error).To(BeNil())
+ }
+}
+
+func TestValidCNAME_Availability(t *testing.T) {
+ RegisterTestingT(t)
+ tenants := &inmemory.TenantStorage{}
+ tenant, _ := tenants.Add("Footbook", "footbook", models.TenantActive)
+ tenant.CNAME = "footbook.com"
+ tenant, _ = tenants.Add("Your Company", "yourcompany", models.TenantActive)
+ tenant.CNAME = "fider.yourcompany.com"
+ tenant, _ = tenants.Add("New York", "newyork", models.TenantActive)
+ tenant.CNAME = "feedback.newyork.com"
+ for _, cname := range []string{
+ "footbook.com",
+ "fider.yourcompany.com",
+ "feedback.newyork.com",
+ } {
+ result := validate.CNAME(tenants, cname)
+ Expect(result.Ok).To(BeFalse())
+ Expect(len(result.Messages) > 0).To(BeTrue())
+ Expect(result.Error).To(BeNil())
+ }
+ for _, cname := range []string{
+ "fider.footbook.com",
+ "yourcompany.com",
+ "anything.com",
+ } {
+ result := validate.CNAME(tenants, cname)
+ Expect(result.Ok).To(BeTrue())
+ Expect(len(result.Messages)).To(Equal(0))
+ Expect(result.Error).To(BeNil())
+ }
+}
diff --git a/app/pkg/validate/domain.go b/app/pkg/validate/subdomain.go
similarity index 100%
rename from app/pkg/validate/domain.go
rename to app/pkg/validate/subdomain.go
diff --git a/app/pkg/validate/domain_test.go b/app/pkg/validate/subdomain_test.go
similarity index 100%
rename from app/pkg/validate/domain_test.go
rename to app/pkg/validate/subdomain_test.go
diff --git a/app/storage/inmemory/tenant.go b/app/storage/inmemory/tenant.go
index d54778a02..794ab456f 100644
--- a/app/storage/inmemory/tenant.go
+++ b/app/storage/inmemory/tenant.go
@@ -59,6 +59,16 @@ func (s *TenantStorage) IsSubdomainAvailable(subdomain string) (bool, error) {
return true, nil
}
+// IsCNAMEAvailable returns true if cname is available to use
+func (s *TenantStorage) IsCNAMEAvailable(cname string) (bool, error) {
+ for _, tenant := range s.tenants {
+ if tenant.CNAME == cname {
+ return false, nil
+ }
+ }
+ return true, nil
+}
+
// UpdateSettings of given tenant
func (s *TenantStorage) UpdateSettings(settings *models.UpdateTenantSettings) error {
for _, tenant := range s.tenants {
@@ -66,6 +76,7 @@ func (s *TenantStorage) UpdateSettings(settings *models.UpdateTenantSettings) er
tenant.Invitation = settings.Invitation
tenant.WelcomeMessage = settings.WelcomeMessage
tenant.Name = settings.Title
+ tenant.CNAME = settings.CNAME
return nil
}
}
diff --git a/app/storage/postgres/tenant.go b/app/storage/postgres/tenant.go
index c33673162..cb96dab49 100644
--- a/app/storage/postgres/tenant.go
+++ b/app/storage/postgres/tenant.go
@@ -119,8 +119,8 @@ func (s *TenantStorage) GetByDomain(domain string) (*models.Tenant, error) {
// UpdateSettings of given tenant
func (s *TenantStorage) UpdateSettings(settings *models.UpdateTenantSettings) error {
- query := "UPDATE tenants SET name = $1, invitation = $2, welcome_message = $3 WHERE id = $4"
- return s.trx.Execute(query, settings.Title, settings.Invitation, settings.WelcomeMessage, s.current.ID)
+ query := "UPDATE tenants SET name = $1, invitation = $2, welcome_message = $3, cname = $4 WHERE id = $5"
+ return s.trx.Execute(query, settings.Title, settings.Invitation, settings.WelcomeMessage, settings.CNAME, s.current.ID)
}
// IsSubdomainAvailable returns true if subdomain is available to use
@@ -129,6 +129,12 @@ func (s *TenantStorage) IsSubdomainAvailable(subdomain string) (bool, error) {
return !exists, err
}
+// IsCNAMEAvailable returns true if cname is available to use
+func (s *TenantStorage) IsCNAMEAvailable(cname string) (bool, error) {
+ exists, err := s.trx.Exists("SELECT id FROM tenants WHERE cname = $1 AND id <> $2", cname, s.current.ID)
+ return !exists, err
+}
+
// Activate given tenant
func (s *TenantStorage) Activate(id int) error {
query := "UPDATE tenants SET status = $1 WHERE id = $2"
diff --git a/app/storage/postgres/tenant_test.go b/app/storage/postgres/tenant_test.go
index 1d91b237f..7906e5d91 100644
--- a/app/storage/postgres/tenant_test.go
+++ b/app/storage/postgres/tenant_test.go
@@ -165,6 +165,7 @@ func TestTenantStorage_UpdateSettings(t *testing.T) {
Title: "New Demonstration",
Invitation: "Leave us your suggestion",
WelcomeMessage: "Welcome!",
+ CNAME: "demo.company.com",
}
err := tenants.UpdateSettings(settings)
Expect(err).To(BeNil())
@@ -175,6 +176,7 @@ func TestTenantStorage_UpdateSettings(t *testing.T) {
Expect(tenant.Name).To(Equal("New Demonstration"))
Expect(tenant.Invitation).To(Equal("Leave us your suggestion"))
Expect(tenant.WelcomeMessage).To(Equal("Welcome!"))
+ Expect(tenant.CNAME).To(Equal("demo.company.com"))
}
func TestTenantStorage_SaveFindSet_VerificationKey(t *testing.T) {
diff --git a/app/storage/storage.go b/app/storage/storage.go
index 52d36f1d8..dc9ebaf09 100644
--- a/app/storage/storage.go
+++ b/app/storage/storage.go
@@ -41,6 +41,7 @@ type Tenant interface {
GetByDomain(domain string) (*models.Tenant, error)
UpdateSettings(settings *models.UpdateTenantSettings) error
IsSubdomainAvailable(subdomain string) (bool, error)
+ IsCNAMEAvailable(cname string) (bool, error)
SaveVerificationKey(key string, duration time.Duration, email, name string) error
FindVerificationByKey(key string) (*models.SignInRequest, error)
SetKeyAsVerified(key string) error
diff --git a/public/models/identity.ts b/public/models/identity.ts
index db267a313..7dbd468f5 100644
--- a/public/models/identity.ts
+++ b/public/models/identity.ts
@@ -1,7 +1,8 @@
export interface Tenant {
id: number;
name: string;
- domain: string;
+ cname: string;
+ subdomain: string;
invitation: string;
welcomeMessage: string;
}
diff --git a/public/pages/admin/AdminHomePage.tsx b/public/pages/admin/AdminHomePage.tsx
index 36a0e97f8..7858290bd 100644
--- a/public/pages/admin/AdminHomePage.tsx
+++ b/public/pages/admin/AdminHomePage.tsx
@@ -12,6 +12,7 @@ interface AdminHomePageState {
title: string;
welcomeMessage: string;
invitation: string;
+ cname: string;
error?: Failure;
}
@@ -31,6 +32,7 @@ export class AdminHomePage extends React.Component<{}, AdminHomePageState> {
this.state = {
title: this.tenant.name,
+ cname: this.tenant.cname,
welcomeMessage: this.tenant.welcomeMessage,
invitation: this.tenant.invitation
};
@@ -39,7 +41,12 @@ export class AdminHomePage extends React.Component<{}, AdminHomePageState> {
}
private async confirm() {
- const result = await this.service.updateSettings(this.state.title, this.state.invitation, this.state.welcomeMessage);
+ const result = await this.service.updateSettings(
+ this.state.title,
+ this.state.invitation,
+ this.state.welcomeMessage,
+ this.state.cname,
+ );
if (result.ok) {
location.href = `/`;
} else if (result.error) {
@@ -67,7 +74,6 @@ export class AdminHomePage extends React.Component<{}, AdminHomePageState> {
<label htmlFor="title">Title</label>
<input id="title"
type="text"
- placeholder="Title"
maxLength={60}
disabled={ !this.session.isAdmin() }
value={ this.state.title }
@@ -80,7 +86,6 @@ export class AdminHomePage extends React.Component<{}, AdminHomePageState> {
<div className="field">
<label htmlFor="welcome-message">Welcome Message</label>
<Textarea id="welcome-message"
- placeholder="Welcome Message"
disabled={ !this.session.isAdmin() }
onChange={(e) => this.setState({ welcomeMessage: e.currentTarget.value })}
value={ this.state.welcomeMessage } />
@@ -95,7 +100,6 @@ export class AdminHomePage extends React.Component<{}, AdminHomePageState> {
<label htmlFor="invitation">Invitation</label>
<input id="invitation"
type="text"
- placeholder="Invitation"
maxLength={60}
disabled={ !this.session.isAdmin() }
value={ this.state.invitation }
@@ -104,6 +108,33 @@ export class AdminHomePage extends React.Component<{}, AdminHomePageState> {
<p>This is your customized message to invite visitors to share their ideas and suggestions.</p>
</div>
</div>
+ {
+ !this.session.isSingleHostMode() && [
+ <DisplayError key={1} fields={['cname']} error={this.state.error} />,
+ <div key={2} className="field">
+ <label htmlFor="cname">Custom Domain</label>
+ <input id="cname"
+ type="text"
+ placeholder="feedback.yourcompany.com"
+ maxLength={100}
+ disabled={ !this.session.isAdmin() }
+ value={ this.state.cname }
+ onChange={(e) => this.setState({ cname: e.currentTarget.value })}/>
+ <div className="info">
+ {
+ this.state.cname ? [
+ <p key={0}>Input following record into your domain DNS zone records:</p>,
+ <p key={1}><strong>{ this.state.cname }</strong> CNAME <strong>{ this.session.getCurrentTenant().subdomain }{ this.session.getAppSettings().domain }</strong></p>,
+ <div key={2} className="ui negative message">
+ <p>Custom Domain is a <strong>experimental feature</strong> and you're invited to test it. In case of any issue, feedback or question, please contact us at <a href="mailto:[email protected]">[email protected]</a>.</p>
+ </div>
+ ] :
+ <p>Custom domains allow you to access your app via your own domain name (for example, <code>feedback.yourcomany.com</code>).</p>
+ }
+ </div>
+ </div>
+ ]
+ }
{
this.session.isAdmin() &&
<div className="field">
diff --git a/public/pages/signup/SignUpPage.tsx b/public/pages/signup/SignUpPage.tsx
index ec9ecf98a..e4c31eada 100644
--- a/public/pages/signup/SignUpPage.tsx
+++ b/public/pages/signup/SignUpPage.tsx
@@ -88,7 +88,12 @@ export class SignUpPage extends React.Component<{}, SignUpPageState> {
if (this.session.isSingleHostMode()) {
location.reload();
} else {
- location.href = `${location.protocol}//${this.state.subdomain.value}${this.settings.domain}?token=${result.data.token}`;
+ let baseUrl = `${location.protocol}//${this.state.subdomain.value}${this.settings.domain}`;
+ if (location.port) {
+ baseUrl = `${baseUrl}:${location.port}`;
+ }
+
+ location.href = `${baseUrl}?token=${result.data.token}`;
}
} else {
this.setState({ submitted: true });
diff --git a/public/services/TenantService.ts b/public/services/TenantService.ts
index 08e6a6c79..863a2b843 100644
--- a/public/services/TenantService.ts
+++ b/public/services/TenantService.ts
@@ -4,7 +4,7 @@ import { Tenant, UserRole } from '@fider/models';
export interface TenantService {
create(request: CreateTenantRequest): Promise<Result<CreateTenantResponse>>;
- updateSettings(title: string, invitation: string, welcomeMessage: string): Promise<Result>;
+ updateSettings(title: string, invitation: string, welcomeMessage: string, cname: string): Promise<Result>;
checkAvailability(subdomain: string): Promise<Result<CheckAvailabilityResponse>>;
signIn(email: string): Promise<Result>;
completeProfile(key: string, name: string): Promise<Result>;
@@ -33,9 +33,9 @@ export class HttpTenantService implements TenantService {
return await post<CreateTenantResponse>('/api/tenants', request);
}
- public async updateSettings(title: string, invitation: string, welcomeMessage: string): Promise<Result> {
+ public async updateSettings(title: string, invitation: string, welcomeMessage: string, cname: string): Promise<Result> {
return await post('/api/admin/settings', {
- title, invitation, welcomeMessage,
+ title, invitation, welcomeMessage, cname
});
}