Open platform to collect and prioritize feedback
feature: upload site logo (#380)
Guilherme Oenningea0314a05b18
diff --git a/app/actions/tenant.go b/app/actions/tenant.goindex f19566ae6..111860fe5 100644--- a/app/actions/tenant.go+++ b/app/actions/tenant.go@@ -4,6 +4,7 @@ import ("github.com/getfider/fider/app""github.com/getfider/fider/app/models""github.com/getfider/fider/app/pkg/env"+ "github.com/getfider/fider/app/pkg/img""github.com/getfider/fider/app/pkg/jwt""github.com/getfider/fider/app/pkg/validate")@@ -91,6 +92,25 @@ func (input *UpdateTenantSettings) IsAuthorized(user *models.User, services *appfunc (input *UpdateTenantSettings) Validate(user *models.User, services *app.Services) *validate.Result {result := validate.Success()+ if input.Model.Logo != nil && input.Model.Logo.Upload != nil && len(input.Model.Logo.Upload.Content) > 0 {+ logo, err := img.Parse(input.Model.Logo.Upload.Content)+ if err != nil {+ if err == img.ErrNotSupported {+ result.AddFieldFailure("logo", "This file format not supported.")+ } else {+ return validate.Error(err)+ }+ } else {+ if logo.Width > 200 || logo.Height > 200 {+ result.AddFieldFailure("logo", "The image must be smaller than 200x200 pixels in dimension.")+ }++ if logo.Size > 51200 {+ result.AddFieldFailure("logo", "The image size must be smaller than 50KB.")+ }+ }+ }+if input.Model.Title == "" {result.AddFieldFailure("title", "Title is required.")}diff --git a/app/actions/tenant_test.go b/app/actions/tenant_test.goindex 8714dd2a0..b6cab471b 100644--- a/app/actions/tenant_test.go+++ b/app/actions/tenant_test.go@@ -1,12 +1,14 @@package actions_testimport (+ "io/ioutil""testing""github.com/getfider/fider/app/actions""github.com/getfider/fider/app/models". "github.com/getfider/fider/app/pkg/assert"+ "github.com/getfider/fider/app/pkg/env")func TestCreateTenant_ShouldHaveVerificationKey(t *testing.T) {@@ -110,3 +112,40 @@ func TestUpdateTenantSettings_LargeInvitation(t *testing.T) {result := action.Validate(nil, services)ExpectFailed(result, "invitation")}++func TestUpdateTenantSettings_LargeLogo(t *testing.T) {+ RegisterT(t)++ var testCases = []struct {+ fileName string+ valid bool+ }{+ {"/app/pkg/img/testdata/logo1.png", false},+ {"/app/pkg/img/testdata/logo2.jpg", false},+ {"/app/pkg/img/testdata/logo3.gif", false},+ {"/app/pkg/img/testdata/logo4.png", true},+ {"/README.md", false},+ {"/favicon.ico", false},+ }++ for _, testCase := range testCases {+ logo, _ := ioutil.ReadFile(env.Path(testCase.fileName))++ action := actions.UpdateTenantSettings{+ Model: &models.UpdateTenantSettings{+ Title: "Hello World",+ Logo: &models.UpdateTenantSettingsLogo{+ Upload: &models.UpdateTenantSettingsLogoUpload{+ Content: logo,+ },+ },+ },+ }+ result := action.Validate(nil, services)+ if testCase.valid {+ ExpectSuccess(result)+ } else {+ ExpectFailed(result, "logo")+ }+ }+}diff --git a/app/cmd/routes.go b/app/cmd/routes.goindex 1e7bf77ad..5b2bf1ce4 100644--- a/app/cmd/routes.go+++ b/app/cmd/routes.go@@ -47,6 +47,7 @@ func routes(r *web.Engine) *web.Engine {{avatar.Use(middlewares.ClientCache(72 * time.Hour))avatar.Get("/avatars/:size/:id/:name", handlers.Avatar())+ avatar.Get("/logo/:id", handlers.Logo())}open := r.Group()@@ -125,5 +126,6 @@ func routes(r *web.Engine) *web.Engine {private.Post("/api/admin/users/:user_id/role", handlers.ChangeUserRole())}}+return r}diff --git a/app/handlers/avatar.go b/app/handlers/images.gosimilarity index 80%rename from app/handlers/avatar.gorename to app/handlers/images.goindex 8e24393a2..dc2dce3d4 100644--- a/app/handlers/avatar.go+++ b/app/handlers/images.go@@ -56,3 +56,20 @@ func Avatar() web.HandlerFunc {return c.Blob(http.StatusOK, "image/png", buf.Bytes())}}++//Logo returns current tenant logo+func Logo() web.HandlerFunc {+ return func(c web.Context) error {+ id, err := c.ParamAsInt("id")+ if err != nil {+ return c.Failure(err)+ }++ logo, err := c.Services().Tenants.GetLogo(id)+ if err != nil {+ return c.Failure(err)+ }++ return c.Blob(http.StatusOK, logo.ContentType, logo.Content)+ }+}diff --git a/app/handlers/avatar_test.go b/app/handlers/images_test.gosimilarity index 100%rename from app/handlers/avatar_test.gorename to app/handlers/images_test.godiff --git a/app/models/identity.go b/app/models/identity.goindex d2977f19a..b357a7d09 100644--- a/app/models/identity.go+++ b/app/models/identity.go@@ -18,6 +18,7 @@ type Tenant struct {CNAME string `json:"cname"`Status int `json:"-"`IsPrivate bool `json:"isPrivate"`+ LogoID int `json:"logoId"`}var (@@ -27,6 +28,13 @@ var (TenantInactive = 2)+//Upload represents a file that has been uploaded to Fider+type Upload struct {+ ContentType string `db:"content_type"`+ Size int `db:"size"`+ Content []byte `db:"file"`+}+//User represents an user inside our applicationtype User struct {ID int `json:"id"`@@ -139,10 +147,23 @@ func (e *CreateTenant) GetKind() EmailVerificationKind {//UpdateTenantSettings is the input model used to update tenant general settingstype UpdateTenantSettings struct {- Title string `json:"title"`- Invitation string `json:"invitation"`- WelcomeMessage string `json:"welcomeMessage"`- CNAME string `json:"cname" format:"lower"`+ Logo *UpdateTenantSettingsLogo `json:"logo"`+ Title string `json:"title"`+ Invitation string `json:"invitation"`+ WelcomeMessage string `json:"welcomeMessage"`+ CNAME string `json:"cname" format:"lower"`+}++//UpdateTenantSettingsLogo is the input model used to update logo+type UpdateTenantSettingsLogo struct {+ Upload *UpdateTenantSettingsLogoUpload `json:"upload"`+ Remove bool `json:"remove"`+}++//UpdateTenantSettingsLogoUpload is the input model used to uploade a new logo+type UpdateTenantSettingsLogoUpload struct {+ ContentType string `json:"contentType"`+ Content []byte `json:"content"`}//UpdateTenantPrivacy is the input model used to update tenant privacy settingsdiff --git a/app/pkg/img/img.go b/app/pkg/img/img.gonew file mode 100644index 000000000..f94c880b6--- /dev/null+++ b/app/pkg/img/img.go@@ -0,0 +1,39 @@+package img++import (+ "bytes"+ "image"++ // These are the supported image formats+ _ "image/gif"+ _ "image/jpeg"+ _ "image/png"++ stdError "errors"+)++//ErrNotSupported returned by Parse when given file is not in a supported format+var ErrNotSupported = stdError.New("File not supported")++//File is an image supported by Fider+type File struct {+ Width int+ Height int+ Size int+}++//Parse returns the a img.File if it's supported by fider+func Parse(file []byte) (*File, error) {+ reader := bytes.NewReader(file)++ image, _, err := image.DecodeConfig(reader)+ if err != nil {+ return nil, ErrNotSupported+ }++ return &File{+ Size: len(file),+ Width: image.Width,+ Height: image.Height,+ }, nil+}diff --git a/app/pkg/img/img_test.go b/app/pkg/img/img_test.gonew file mode 100644index 000000000..ebb69a488--- /dev/null+++ b/app/pkg/img/img_test.go@@ -0,0 +1,43 @@+package img_test++import (+ "io/ioutil"+ "testing"++ . "github.com/getfider/fider/app/pkg/assert"+ "github.com/getfider/fider/app/pkg/env"+ "github.com/getfider/fider/app/pkg/img"+)++var testCases = []struct {+ fileName string+ width int+ height int+ supported bool+}{+ {"/app/pkg/img/testdata/logo1.png", 300, 300, true},+ {"/app/pkg/img/testdata/logo2.jpg", 2624, 2184, true},+ {"/app/pkg/img/testdata/logo3.gif", 1165, 822, true},+ {"/app/pkg/img/testdata/logo4.png", 150, 150, true},+ {"/favicon.ico", 0, 0, false},+}++func TestImageParse(t *testing.T) {+ RegisterT(t)++ for _, testCase := range testCases {+ bytes, err := ioutil.ReadFile(env.Path(testCase.fileName))+ Expect(err).IsNil()++ file, err := img.Parse(bytes)+ if testCase.supported {+ Expect(err).IsNil()+ Expect(file.Width).Equals(testCase.width)+ Expect(file.Height).Equals(testCase.height)+ Expect(file.Size).Equals(len(bytes))+ } else {+ Expect(err).Equals(img.ErrNotSupported)+ Expect(file).IsNil()+ }+ }+}diff --git a/app/pkg/img/testdata/logo1.png b/app/pkg/img/testdata/logo1.pngnew file mode 100644index 000000000..b461aae69Binary files /dev/null and b/app/pkg/img/testdata/logo1.png differdiff --git a/app/pkg/img/testdata/logo2.jpg b/app/pkg/img/testdata/logo2.jpgnew file mode 100644index 000000000..9603d09cbBinary files /dev/null and b/app/pkg/img/testdata/logo2.jpg differdiff --git a/app/pkg/img/testdata/logo3.gif b/app/pkg/img/testdata/logo3.gifnew file mode 100644index 000000000..65daf12bdBinary files /dev/null and b/app/pkg/img/testdata/logo3.gif differdiff --git a/app/pkg/img/testdata/logo4.png b/app/pkg/img/testdata/logo4.pngnew file mode 100644index 000000000..8f9958525Binary files /dev/null and b/app/pkg/img/testdata/logo4.png differdiff --git a/app/pkg/web/binder_test.go b/app/pkg/web/binder_test.goindex 6141480af..1dc73bed7 100644--- a/app/pkg/web/binder_test.go+++ b/app/pkg/web/binder_test.go@@ -1,9 +1,13 @@package web_testimport (+ "encoding/base64"+ "fmt"+ "io/ioutil""testing". "github.com/getfider/fider/app/pkg/assert"+ "github.com/getfider/fider/app/pkg/env""github.com/getfider/fider/app/pkg/web")@@ -51,6 +55,52 @@ func TestDefaultBinder_TrimSpaces(t *testing.T) {Expect(u.Other).Equals("")}+func TestDefaultBinder_Base64ToBytes(t *testing.T) {+ RegisterT(t)++ resume, _ := ioutil.ReadFile(env.Path("./README.md"))+ resumeBase64 := base64.StdEncoding.EncodeToString(resume)++ type user struct {+ Name string `json:"name"`+ Resume []byte `json:"resume"`+ }++ params := make(web.StringMap, 0)+ body := fmt.Sprintf(`{ "name": "Jon Snow", "resume": "%s" }`, resumeBase64)+ ctx := newBodyContext("POST", params, body, "application/json")+ u := new(user)+ err := binder.Bind(u, ctx)+ Expect(err).IsNil()+ Expect(u.Name).Equals("Jon Snow")+ Expect(u.Resume).Equals(resume)+}++func TestDefaultBinder_NestedJson(t *testing.T) {+ RegisterT(t)++ resume, _ := ioutil.ReadFile(env.Path("./README.md"))+ resumeBase64 := base64.StdEncoding.EncodeToString(resume)++ type user struct {+ Name string `json:"name"`+ Resume struct {+ FileName string `json:"fileName"`+ File []byte `json:"file"`+ }+ }++ params := make(web.StringMap, 0)+ body := fmt.Sprintf(`{ "name": "Jon Snow", "resume": { "fileName": "README.md", "file": "%s" } }`, resumeBase64)+ ctx := newBodyContext("POST", params, body, "application/json")+ u := new(user)+ err := binder.Bind(u, ctx)+ Expect(err).IsNil()+ Expect(u.Name).Equals("Jon Snow")+ Expect(u.Resume.FileName).Equals("README.md")+ Expect(u.Resume.File).Equals(resume)+}+func TestDefaultBinder_Array_TrimSpaces(t *testing.T) {RegisterT(t)diff --git a/app/pkg/web/engine.go b/app/pkg/web/engine.goindex 38e6eee44..9ce064938 100644--- a/app/pkg/web/engine.go+++ b/app/pkg/web/engine.go@@ -24,8 +24,8 @@ import (var (cspBase = "base-uri 'self'"cspDefault = "default-src 'self'"- cspStyle = "style-src 'self' https://fonts.googleapis.com"- cspScript = "script-src 'self' 'nonce-%s' https://cdn.polyfill.io https://www.google-analytics.com"+ cspStyle = "style-src 'self' 'nonce-%[1]s' https://fonts.googleapis.com"+ cspScript = "script-src 'self' 'nonce-%[1]s' https://cdn.polyfill.io https://www.google-analytics.com"cspFont = "font-src 'self' https://fonts.gstatic.com data:"cspImage = "img-src 'self' https: data:"cspObject = "object-src 'none'"diff --git a/app/pkg/web/renderer.go b/app/pkg/web/renderer.goindex ccc39250a..809d493d0 100644--- a/app/pkg/web/renderer.go+++ b/app/pkg/web/renderer.go@@ -88,7 +88,14 @@ func (r *Renderer) Render(w io.Writer, name string, data interface{}, ctx *Contem["__JavaScriptBundle"] = r.jsBundlem["__StyleBundle"] = r.cssBundlem["__ContextID"] = ctx.ContextID()-+ if ctx.Tenant() != nil && ctx.Tenant().LogoID > 0 {+ m["__logo"] = fmt.Sprintf("/logo/%d", ctx.Tenant().LogoID)+ m["__favicon"] = m["__logo"]+ } else {+ m["__logo"] = "https://getfider.com/images/logo-100x100.png"+ m["__favicon"] = "/favicon.ico"+ }+m["system"] = r.settingsm["baseURL"] = ctx.BaseURL()m["tenant"] = ctx.Tenant()diff --git a/app/storage/inmemory/tenant.go b/app/storage/inmemory/tenant.goindex 3833ccfd9..188aa9d6e 100644--- a/app/storage/inmemory/tenant.go+++ b/app/storage/inmemory/tenant.go@@ -1,6 +1,7 @@package inmemoryimport (+ "net/http""strings""time"@@ -12,10 +13,12 @@ import (// TenantStorage contains read and write operations for tenantstype TenantStorage struct {lastID int+ lastLogoID inttenants []*models.Tenantcurrent *models.Tenantuser *models.Userverifications []*models.EmailVerification+ tenantLogos map[int]*models.Upload}// SetCurrentTenant tenant@@ -80,6 +83,20 @@ func (s *TenantStorage) IsCNAMEAvailable(cname string) (bool, error) {func (s *TenantStorage) UpdateSettings(settings *models.UpdateTenantSettings) error {for _, tenant := range s.tenants {if tenant.ID == s.current.ID {++ if settings.Logo != nil && settings.Logo.Upload != nil && len(settings.Logo.Upload.Content) > 0 {+ s.lastLogoID = s.lastLogoID + 1+ if s.tenantLogos == nil {+ s.tenantLogos = make(map[int]*models.Upload, 0)+ }+ tenant.LogoID = s.lastLogoID+ s.tenantLogos[s.lastLogoID] = &models.Upload{+ Content: settings.Logo.Upload.Content,+ Size: len(settings.Logo.Upload.Content),+ ContentType: http.DetectContentType(settings.Logo.Upload.Content),+ }+ }+tenant.Invitation = settings.Invitationtenant.WelcomeMessage = settings.WelcomeMessagetenant.Name = settings.Title@@ -152,6 +169,18 @@ func (s *TenantStorage) SetKeyAsVerified(key string) error {return nil}+// GetLogo returns tenant logo by id+func (s *TenantStorage) GetLogo(id int) (*models.Upload, error) {+ if s.tenantLogos != nil {+ logo, ok := s.tenantLogos[id]+ if !ok {+ return nil, app.ErrNotFound+ }+ return logo, nil+ }+ return nil, app.ErrNotFound+}+func extractSubdomain(hostname string) string {domain := env.MultiTenantDomain()if domain == "" {diff --git a/app/storage/postgres/tenant.go b/app/storage/postgres/tenant.goindex 1c5c0df4d..a1dcfa3a9 100644--- a/app/storage/postgres/tenant.go+++ b/app/storage/postgres/tenant.go@@ -1,9 +1,12 @@package postgresimport (+ "database/sql"+ "net/http""strings""time"+ "github.com/getfider/fider/app""github.com/getfider/fider/app/models""github.com/getfider/fider/app/pkg/dbx""github.com/getfider/fider/app/pkg/env"@@ -11,14 +14,15 @@ import ()type dbTenant struct {- ID int `db:"id"`- Name string `db:"name"`- Subdomain string `db:"subdomain"`- CNAME string `db:"cname"`- Invitation string `db:"invitation"`- WelcomeMessage string `db:"welcome_message"`- Status int `db:"status"`- IsPrivate bool `db:"is_private"`+ ID int `db:"id"`+ Name string `db:"name"`+ Subdomain string `db:"subdomain"`+ CNAME string `db:"cname"`+ Invitation string `db:"invitation"`+ WelcomeMessage string `db:"welcome_message"`+ Status int `db:"status"`+ IsPrivate bool `db:"is_private"`+ LogoID dbx.NullInt `db:"logo_id"`}func (t *dbTenant) toModel() *models.Tenant {@@ -26,7 +30,7 @@ func (t *dbTenant) toModel() *models.Tenant {return nil}- return &models.Tenant{+ tenant := &models.Tenant{ID: t.ID,Name: t.Name,Subdomain: t.Subdomain,@@ -36,6 +40,12 @@ func (t *dbTenant) toModel() *models.Tenant {Status: t.Status,IsPrivate: t.IsPrivate,}++ if t.LogoID.Valid {+ tenant.LogoID = int(t.LogoID.Int64)+ }++ return tenant}type dbEmailVerification struct {@@ -112,7 +122,7 @@ func (s *TenantStorage) Add(name string, subdomain string, status int) (*models.func (s *TenantStorage) First() (*models.Tenant, error) {tenant := dbTenant{}- err := s.trx.Get(&tenant, "SELECT id, name, subdomain, cname, invitation, welcome_message, status, is_private FROM tenants ORDER BY id LIMIT 1")+ err := s.trx.Get(&tenant, "SELECT id, name, subdomain, cname, invitation, welcome_message, status, is_private, logo_id FROM tenants ORDER BY id LIMIT 1")if err != nil {return nil, errors.Wrap(err, "failed to get first tenant")}@@ -124,7 +134,7 @@ func (s *TenantStorage) First() (*models.Tenant, error) {func (s *TenantStorage) GetByDomain(domain string) (*models.Tenant, error) {tenant := dbTenant{}- err := s.trx.Get(&tenant, "SELECT id, name, subdomain, cname, invitation, welcome_message, status, is_private FROM tenants WHERE subdomain = $1 OR cname = $2 ORDER BY cname DESC", extractSubdomain(domain), domain)+ err := s.trx.Get(&tenant, "SELECT id, name, subdomain, cname, invitation, welcome_message, status, is_private, logo_id FROM tenants WHERE subdomain = $1 OR cname = $2 ORDER BY cname DESC", extractSubdomain(domain), domain)if err != nil {return nil, errors.Wrap(err, "failed to get tenant with domain '%s'", domain)}@@ -139,6 +149,42 @@ func (s *TenantStorage) UpdateSettings(settings *models.UpdateTenantSettings) erif err != nil {return errors.Wrap(err, "failed update tenant settings")}++ s.current.Name = settings.Title+ s.current.Invitation = settings.Invitation+ s.current.CNAME = settings.CNAME+ s.current.WelcomeMessage = settings.WelcomeMessage++ if settings.Logo != nil {+ var newLogoID sql.NullInt64++ if !settings.Logo.Remove && len(settings.Logo.Upload.Content) > 0 {+ err := s.trx.Get(&newLogoID, `+ INSERT INTO uploads (tenant_id, size, content_type, file, created_on)+ VALUES ($1, $2, $3, $4, $5) RETURNING id+ `, s.current.ID, len(settings.Logo.Upload.Content), http.DetectContentType(settings.Logo.Upload.Content), settings.Logo.Upload.Content, time.Now(),+ )+ if err != nil {+ return errors.Wrap(err, "failed to upload new tenant logo")+ }+ }++ query := "UPDATE tenants SET logo_id = $1 WHERE id = $2"+ _, err = s.trx.Execute(query, newLogoID, s.current.ID)+ if err != nil {+ return errors.Wrap(err, "failed update tenant logo")+ }++ if s.current.LogoID > 0 {+ query := "DELETE FROM uploads WHERE id = $1 AND tenant_id = $2"+ _, err = s.trx.Execute(query, s.current.LogoID, s.current.ID)+ if err != nil {+ return errors.Wrap(err, "failed delete old tenant logo")+ }+ }+ s.current.LogoID = int(newLogoID.Int64)+ }+return nil}@@ -218,6 +264,25 @@ func (s *TenantStorage) SetKeyAsVerified(key string) error {return nil}+// GetLogo returns tenant logo by id+func (s *TenantStorage) GetLogo(id int) (*models.Upload, error) {+ upload := &models.Upload{}+ err := s.trx.Get(upload, `+ SELECT content_type, size, file FROM tenants+ INNER JOIN uploads+ ON uploads.tenant_id = tenants.id+ AND uploads.id = tenants.logo_id+ WHERE tenants.id = $1 AND uploads.id = $2+ `, s.current.ID, id)+ if err == app.ErrNotFound {+ return nil, app.ErrNotFound+ }+ if err != nil {+ return nil, errors.Wrap(err, "failed to get logo from tenant")+ }+ return upload, nil+}+func extractSubdomain(hostname string) string {domain := env.MultiTenantDomain()if domain == "" {diff --git a/app/storage/postgres/tenant_test.go b/app/storage/postgres/tenant_test.goindex ed0d9eab3..c809e7d55 100644--- a/app/storage/postgres/tenant_test.go+++ b/app/storage/postgres/tenant_test.go@@ -1,12 +1,14 @@package postgres_testimport (+ "io/ioutil""os""testing""time""github.com/getfider/fider/app/models". "github.com/getfider/fider/app/pkg/assert"+ "github.com/getfider/fider/app/pkg/env""github.com/getfider/fider/app/pkg/errors""github.com/getfider/fider/app"@@ -150,6 +152,96 @@ func TestTenantStorage_UpdateSettings(t *testing.T) {Expect(tenant.Invitation).Equals("Leave us your suggestion")Expect(tenant.WelcomeMessage).Equals("Welcome!")Expect(tenant.CNAME).Equals("demo.company.com")+ Expect(tenant.LogoID).Equals(0)+}++func TestTenantStorage_UpdateSettings_WithLogo(t *testing.T) {+ SetupDatabaseTest(t)+ defer TeardownDatabaseTest()++ tenant, _ := tenants.GetByDomain("demo")+ tenants.SetCurrentTenant(tenant)++ logo, _ := ioutil.ReadFile(env.Path("./favicon.ico"))++ settings := &models.UpdateTenantSettings{+ Logo: &models.UpdateTenantSettingsLogo{+ Upload: &models.UpdateTenantSettingsLogoUpload{+ Content: logo,+ },+ },+ Title: "New Demonstration",+ Invitation: "Leave us your suggestion",+ WelcomeMessage: "Welcome!",+ CNAME: "demo.company.com",+ }+ err := tenants.UpdateSettings(settings)+ Expect(err).IsNil()++ upload, err := tenants.GetLogo(tenant.LogoID)+ Expect(err).IsNil()+ Expect(upload.Content).Equals(logo)+ Expect(upload.Size).Equals(len(logo))+ Expect(upload.ContentType).Equals("image/vnd.microsoft.icon")++ //Remove Logo+ settings.Logo.Upload = nil+ settings.Logo.Remove = true+ err = tenants.UpdateSettings(settings)+ Expect(err).IsNil()++ tenant, err = tenants.GetByDomain("demo")+ Expect(err).IsNil()+ Expect(tenant.LogoID).Equals(0)+}++func TestTenantStorage_UpdateSettings_ReplaceLogo(t *testing.T) {+ SetupDatabaseTest(t)+ defer TeardownDatabaseTest()++ tenant, _ := tenants.GetByDomain("demo")+ tenants.SetCurrentTenant(tenant)++ logo, _ := ioutil.ReadFile(env.Path("./favicon.ico"))++ settings := &models.UpdateTenantSettings{+ Logo: &models.UpdateTenantSettingsLogo{+ Upload: &models.UpdateTenantSettingsLogoUpload{+ Content: logo,+ },+ },+ Title: "New Demonstration",+ Invitation: "Leave us your suggestion",+ WelcomeMessage: "Welcome!",+ CNAME: "demo.company.com",+ }+ err := tenants.UpdateSettings(settings)+ Expect(err).IsNil()++ firstLogoID := tenant.LogoID+ upload, err := tenants.GetLogo(firstLogoID)+ Expect(err).IsNil()+ Expect(upload.Content).Equals(logo)+ Expect(upload.Size).Equals(len(logo))+ Expect(upload.ContentType).Equals("image/vnd.microsoft.icon")++ //Replace logo with a new one+ newLogo, _ := ioutil.ReadFile(env.Path("./README.md"))+ settings.Logo.Upload.Content = newLogo+ err = tenants.UpdateSettings(settings)+ Expect(err).IsNil()++ Expect(tenant.LogoID).NotEquals(firstLogoID)++ upload, err = tenants.GetLogo(tenant.LogoID)+ Expect(err).IsNil()+ Expect(upload.Content).Equals(newLogo)+ Expect(upload.Size).Equals(len(newLogo))+ Expect(upload.ContentType).Equals("text/html; charset=utf-8")++ upload, err = tenants.GetLogo(firstLogoID)+ Expect(err).Equals(app.ErrNotFound)+ Expect(upload).IsNil()}func TestTenantStorage_SaveFindSet_VerificationKey(t *testing.T) {diff --git a/app/storage/storage.go b/app/storage/storage.goindex 683b1dc2d..dad23bd59 100644--- a/app/storage/storage.go+++ b/app/storage/storage.go@@ -69,6 +69,7 @@ type Tenant interface {SaveVerificationKey(key string, duration time.Duration, request models.NewEmailVerification) errorFindVerificationByKey(kind models.EmailVerificationKind, key string) (*models.EmailVerification, error)SetKeyAsVerified(key string) error+ GetLogo(id int) (*models.Upload, error)}// Tag contains read and write operations for tagsdiff --git a/migrations/201805070759_add_logo_id.up.sql b/migrations/201805070759_add_logo_id.up.sqlnew file mode 100644index 000000000..61390801b--- /dev/null+++ b/migrations/201805070759_add_logo_id.up.sql@@ -0,0 +1,8 @@+CREATE UNIQUE INDEX upload_tenant_key ON uploads (id, tenant_id);++ALTER TABLE tenants ADD logo_id INT NULL;++ALTER TABLE tenants+ ADD CONSTRAINT tenants_logo_id_fkey+ FOREIGN KEY (logo_id, id)+ REFERENCES uploads(id, tenant_id);diff --git a/public/assets/styles/main.scss b/public/assets/styles/main.scssindex 111d50cee..c71639309 100644--- a/public/assets/styles/main.scss+++ b/public/assets/styles/main.scss@@ -11,6 +11,7 @@}[type=reset], [type=submit], button, html [type=button] {+ appearance: button;-webkit-appearance: button;}@@ -62,8 +63,16 @@ body, h1, h2, h3, h4, h5, .ui, input {}.title {- font-size: 18px;- margin: 0 0 0 0;+ img {+ margin-right: 10px;+ width: auto;+ height: auto;+ max-height: 36px;+ }+ span {+ font-size: 18px;+ margin: 0 0 0 0;+ }}div, a {diff --git a/public/components/common/Header.tsx b/public/components/common/Header.tsxindex 21bd06c0d..5ed4d2171 100644--- a/public/components/common/Header.tsx+++ b/public/components/common/Header.tsx@@ -2,7 +2,7 @@ import "./Header.scss";import * as React from "react";import { SystemSettings, CurrentUser, Tenant } from "@fider/models";-import { SignInModal, SignInControl, EnvironmentInfo, Gravatar } from "@fider/components";+import { SignInModal, SignInControl, EnvironmentInfo, Gravatar, Logo } from "@fider/components";import { page, actions } from "@fider/services";interface HeaderProps {@@ -82,8 +82,9 @@ export class Header extends React.Component<HeaderProps, HeaderState> {<SignInModal isOpen={this.state.showSignIn} /><div id="menu" className="ui small borderless menu"><div className="ui container">- <a href="/" className="header item">- <span className="title">{this.props.tenant.name}</span>+ <a href="/" className="header item title">+ <Logo tenant={this.props.tenant} />+ <span>{this.props.tenant.name}</span></a>{showRightMenu && (<divdiff --git a/public/components/common/Logo.tsx b/public/components/common/Logo.tsxnew file mode 100644index 000000000..2ea6dceb9--- /dev/null+++ b/public/components/common/Logo.tsx@@ -0,0 +1,17 @@+import * as React from "react";+import { Tenant } from "@fider/models";++interface LogoProps {+ url?: string;+ tenant?: Tenant;+}++export const Logo = (props: LogoProps) => {+ if (props.url) {+ return <img src={props.url} />;+ }+ if (props.tenant && props.tenant.logoId > 0) {+ return <img src={`/logo/${props.tenant.logoId}`} alt={props.tenant.name} />;+ }+ return null;+};diff --git a/public/components/common/index.tsx b/public/components/common/index.tsxindex 4ed6e6f5d..ccc884461 100644--- a/public/components/common/index.tsx+++ b/public/components/common/index.tsx@@ -12,6 +12,7 @@ export * from "./Moment";export * from "./UserName";export * from "./Modal";export * from "./Loader";+export * from "./Logo";export * from "./Toggle";export * from "./FiderVersion";import Textarea from "react-textarea-autosize";diff --git a/public/index.tsx b/public/index.tsxindex 589ff4f99..1805ecb23 100644--- a/public/index.tsx+++ b/public/index.tsx@@ -48,7 +48,7 @@ document.addEventListener("DOMContentLoaded", () => {<ToastContainer position="top-right" toastClassName="c-toast" />{config.showHeader && React.createElement(Header, w.props)}{React.createElement(config.component, w.props)}- {React.createElement(Footer, w.props)}+ {config.showHeader && React.createElement(Footer, w.props)}</>,root);diff --git a/public/models/identity.ts b/public/models/identity.tsindex 6d6c0cc16..156ee1e97 100644--- a/public/models/identity.ts+++ b/public/models/identity.ts@@ -6,6 +6,7 @@ export interface Tenant {invitation: string;welcomeMessage: string;isPrivate: boolean;+ logoId: number;}export interface User {diff --git a/public/pages/Administration/pages/GeneralSettings.page.scss b/public/pages/Administration/pages/GeneralSettings.page.scssnew file mode 100644index 000000000..1fabc20c8--- /dev/null+++ b/public/pages/Administration/pages/GeneralSettings.page.scss@@ -0,0 +1,17 @@+@import '~@fider/assets/styles/variables.scss';++input[type='file'] {+ display: none;+}++.field.logo {+ img {+ background-color: $white;+ padding: 10px;+ border: 1px solid rgba(34, 36, 38, 0.15);+ border-radius: 3px;+ max-width: 200px;+ min-width: 200px;+ margin-right: 10px;+ }+}\ No newline at end of filediff --git a/public/pages/Administration/pages/GeneralSettings.page.tsx b/public/pages/Administration/pages/GeneralSettings.page.tsxindex cad4b6391..5e88cda52 100644--- a/public/pages/Administration/pages/GeneralSettings.page.tsx+++ b/public/pages/Administration/pages/GeneralSettings.page.tsx@@ -1,8 +1,10 @@+import "./GeneralSettings.page.scss";+import * as React from "react";import { SystemSettings, CurrentUser, Tenant } from "@fider/models";-import { Button, ButtonClickEvent, Textarea, DisplayError } from "@fider/components/common";-import { actions, page, Failure } from "@fider/services";+import { Button, ButtonClickEvent, Textarea, DisplayError, Logo } from "@fider/components/common";+import { actions, page, Failure, fileToBase64 } from "@fider/services";import { AdminBasePage } from "../components";interface GeneralSettingsPageProps {@@ -13,14 +15,23 @@ interface GeneralSettingsPageProps {}interface GeneralSettingsPageState {+ logo?: {+ upload?: {+ content?: string;+ contentType?: string;+ };+ remove: boolean;+ };title: string;- welcomeMessage: string;invitation: string;+ welcomeMessage: string;cname: string;error?: Failure;}export class GeneralSettingsPage extends AdminBasePage<GeneralSettingsPageProps, GeneralSettingsPageState> {+ private fileSelector?: HTMLInputElement | null;+public id = "p-admin-general";public name = "general";public icon = "settings";@@ -41,12 +52,7 @@ export class GeneralSettingsPage extends AdminBasePage<GeneralSettingsPageProps,}private async save(e: ButtonClickEvent) {- const result = await actions.updateTenantSettings(- this.state.title,- this.state.invitation,- this.state.welcomeMessage,- this.state.cname- );+ const result = await actions.updateTenantSettings(this.state);if (result.ok) {e.preventEnable();location.href = `/`;@@ -55,6 +61,39 @@ export class GeneralSettingsPage extends AdminBasePage<GeneralSettingsPageProps,}}+ public fileChanged = async (e: React.ChangeEvent<HTMLInputElement>) => {+ if (e.target.files && e.target.files[0]) {+ const file = e.target.files[0];+ const base64 = await fileToBase64(file);+ this.setState({+ logo: {+ upload: {+ content: base64,+ contentType: file.type,+ action: "upload"+ },+ ignore: false,+ remove: false+ }+ });+ }+ };++ public removeFile = async (e: ButtonClickEvent) => {+ this.setState({+ logo: {+ ignore: false,+ remove: true+ }+ });+ };++ public selectFile = async (e: ButtonClickEvent) => {+ if (this.fileSelector) {+ this.fileSelector.click();+ }+ };+public dnsInstructions(): JSX.Element {const isApex = this.state.cname.split(".").length === 2;const recordType = isApex ? "A" : "CNAME";@@ -68,6 +107,14 @@ export class GeneralSettingsPage extends AdminBasePage<GeneralSettingsPageProps,}public content() {+ const isRemoving = this.state.logo ? this.state.logo.remove : false;+ const isUploading = this.state.logo ? !!this.state.logo.upload : false;+ const hasFile = (this.props.tenant.logoId > 0 && !isRemoving) || isUploading;+ const previewUrl =+ isUploading && this.state.logo && this.state.logo.upload+ ? `data:${this.state.logo.upload.contentType};base64,${this.state.logo.upload.content}`+ : undefined;+return (<div className="ui form"><DisplayError fields={["title"]} error={this.state.error} />@@ -81,10 +128,8 @@ export class GeneralSettingsPage extends AdminBasePage<GeneralSettingsPageProps,value={this.state.title}onChange={e => this.setState({ title: e.currentTarget.value })}/>- <div className="info">- <p>Use this field to change the title that is shown on the top of your page.</p>- </div></div>+<DisplayError fields={["welcomeMessage"]} error={this.state.error} /><div className="field"><label htmlFor="welcome-message">Welcome Message</label>@@ -94,20 +139,14 @@ export class GeneralSettingsPage extends AdminBasePage<GeneralSettingsPageProps,onChange={e => this.setState({ welcomeMessage: e.currentTarget.value })}value={this.state.welcomeMessage}/>- <div className="info">- <p>Use this space to change message of your initial page.</p>- <p>- Common use case for this area is a brief description of what is your company/product, why you created this- space and how the visitors can collaborate.- </p>- <p>- This field is powered by CommonMark. You can style and add links to your message. Learn more at{" "}- <a target="_blank" href="http://commonmark.org/help/">- {"http://commonmark.org/help/"}- </a>.- </p>- </div>+ <p className="info">+ You can style and add links to your message, learn more at{" "}+ <a target="_blank" href="http://commonmark.org/help/">+ {"http://commonmark.org/help/"}+ </a>.+ </p></div>+<DisplayError fields={["invitation"]} error={this.state.error} /><div className="field"><label htmlFor="invitation">Invitation</label>@@ -119,10 +158,29 @@ export class GeneralSettingsPage extends AdminBasePage<GeneralSettingsPageProps,value={this.state.invitation}onChange={e => this.setState({ invitation: e.currentTarget.value })}/>- <div className="info">- <p>This is your customized message to invite visitors to share their ideas and suggestions.</p>+ <p className="info">+ This is your customized message to invite visitors to share their ideas and suggestions.+ </p>+ </div>++ <DisplayError fields={["logo"]} error={this.state.error} />+ <div className="field logo">+ <label htmlFor="logo">Logo</label>+ {hasFile && <Logo tenant={this.props.tenant} url={previewUrl} />}+ <input ref={e => (this.fileSelector = e)} type="file" name="logo" onChange={this.fileChanged} />+ <div>+ <Button size="mini" onClick={this.selectFile} disabled={!this.props.user.isAdministrator}>+ {hasFile ? "Change" : "Upload"}+ </Button>+ {hasFile && (+ <Button onClick={this.removeFile} size="mini" disabled={!this.props.user.isAdministrator}>+ Remove+ </Button>+ )}</div>+ <p className="info">We accept JPG, GIF and PNG images, smaller than 50KB and 200x200 pixels in dimension.</p></div>+{!page.isSingleHostMode() && [<DisplayError key={1} fields={["cname"]} error={this.state.error} />,<div key={2} className="field">diff --git a/public/pages/SignIn/SignIn.page.scss b/public/pages/SignIn/SignIn.page.scssindex 4589a6360..d44199cd0 100644--- a/public/pages/SignIn/SignIn.page.scss+++ b/public/pages/SignIn/SignIn.page.scss@@ -9,6 +9,10 @@text-align: center;margin: 0 auto;margin-bottom: 20px;+ img {+ max-height: 100px;+ margin-bottom: 10px;+ }.welcome {font-size: $font-size-big;}diff --git a/public/pages/SignIn/SignIn.page.tsx b/public/pages/SignIn/SignIn.page.tsxindex 83fb4601c..e320010fe 100644--- a/public/pages/SignIn/SignIn.page.tsx+++ b/public/pages/SignIn/SignIn.page.tsx@@ -1,7 +1,7 @@import "./SignIn.page.scss";import * as React from "react";-import { SignInControl } from "@fider/components/common";+import { SignInControl, Logo } from "@fider/components/common";import { page, notify } from "@fider/services";import { Tenant } from "@fider/models";@@ -29,6 +29,7 @@ export class SignInPage extends React.Component<SignInPageProps, {}> {return (<div id="p-signin" className="page ui container"><div className="message">+ <Logo tenant={this.props.tenant} /><p className="welcome"><strong>{this.props.tenant.name}</strong> is a private space and requires an invitation to join it.</p>diff --git a/public/pages/SignUp/SignUp.page.scss b/public/pages/SignUp/SignUp.page.scssindex d3e450792..3c4a29ad3 100644--- a/public/pages/SignUp/SignUp.page.scss+++ b/public/pages/SignUp/SignUp.page.scss@@ -7,7 +7,9 @@}.logo {- height: 100px;+ max-height: 100px;+ margin: 0 auto;+ display: block;}.ui.basic.red.label {diff --git a/public/router.tsx b/public/router.tsxindex cc7bbdc5c..1db667ed5 100644--- a/public/router.tsx+++ b/public/router.tsx@@ -41,7 +41,7 @@ const pathRegex = [route("/admin/export", ExportPage),route("/admin/invitations", InvitationsPage),route("/admin", GeneralSettingsPage),- route("/signin", SignInPage),+ route("/signin", SignInPage, false),route("/signup", SignUpPage, false),route("/signin/verify", CompleteSignInProfilePage),route("/invite/verify", CompleteSignInProfilePage),diff --git a/public/services/actions/tenant.ts b/public/services/actions/tenant.tsindex 38ac5daf7..2540ab49d 100644--- a/public/services/actions/tenant.ts+++ b/public/services/actions/tenant.ts@@ -21,18 +21,22 @@ export const createTenant = async (request: CreateTenantRequest): Promise<Resultreturn await http.post<CreateTenantResponse>("/api/tenants", request);};-export const updateTenantSettings = async (- title: string,- invitation: string,- welcomeMessage: string,- cname: string-): Promise<Result> => {- return await http.post("/api/admin/settings/general", {- title,- invitation,- welcomeMessage,- cname- });+export interface UpdateTenantSettingsRequest {+ logo?: {+ upload?: {+ content?: string;+ contentType?: string;+ };+ remove: boolean;+ };+ title: string;+ invitation: string;+ welcomeMessage: string;+ cname: string;+}++export const updateTenantSettings = async (request: UpdateTenantSettingsRequest): Promise<Result> => {+ return await http.post("/api/admin/settings/general", request);};export const updateTenantPrivacy = async (isPrivate: boolean): Promise<Result> => {diff --git a/public/services/utils.spec.ts b/public/services/utils.spec.tsindex b2a40e95f..0b579633b 100644--- a/public/services/utils.spec.ts+++ b/public/services/utils.spec.ts@@ -1,4 +1,5 @@-import { classSet, formatDate, timeSince } from "./utils";+import { classSet, formatDate, timeSince, fileToBase64 } from "./utils";+import { readFileSync } from "fs";[{ input: null, expected: "" },@@ -59,3 +60,12 @@ import { classSet, formatDate, timeSince } from "./utils";expect(result).toEqual(x.expected);});});++test("Can convert file to base64", async () => {+ const content = readFileSync("./favicon.ico");+ const favicon = new File([content], "favicon.ico");+ const base64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wFn//8BZ///AWf//xVa9/82Q+r/NkPq/3J78P/+/v7/cnJyagAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAd3d3AOTv//8Nbv//AWf//wFn//8BZ///AWb+/ypL7v87SOr/4uT8//T09PBqampiZmZmYGZmZmBmZmZgZmZmYGZmZmBmZmZgZmZmYGZmZmBmZmZgZmZmYGZmZmBmZmZgZmZmYGZmZmBmZmZgZmZmYGZmZmBaWlpUCwsLCgAAAAB3d3cAXZ7//wFn//8BZ///AWf//wFn//8BZ///DGD6/5Sc9P/////////////////////////////////////////////////////////////////////////////////////////////////////////////////AwMC4AQEBAnd3dwBCpf7/A4v+/wOL/v8Di/7/A4v+/wOL/v8EkP3/GeL9/xz9//8c/f//HP3//xz9//8c/f//K/rx/+uwS//1klX/9ZJV//WSVf/1klX/9ZJV/++SU/9opDf/ZbFJ/2WxSf9lsUn/ZbFJ/2WxSf9ksUr/dN61//////9aWlpSd3d3AM/o/v8Cj/7/AI///wCP//8Aj///AI7//wOt/P8Fwvv/Afn+/wH9//8B/f//Af3//wH9//+N33b//sIF//SKPP/0hUH/9IVB//SFQf/0hUH/l4oi/zaQAv9PpS7/U6g0/1OoNP9TqDT/U6g0/zG5X/8B0Zr/xPTn/+Tk5OCGhoYO/////2i7/v8Aj///AI///wCP//8Bmv3/Bbv7/wW8+/8E2fz/Af3//wH9//8B/f//KfTZ//nIB///xwH/+qwb//SFQf/0hUH/9IVB/9+GOv88jgL/NY8A/z+XEf9TqDT/U6g0/1OoNP9Nqzz/Bs6T/wDRmv8z2q7//P7+//Dw8Ib///+06/X+/xKW/v8Aj///AI/+/wS0+/8FvPv/Bbz7/wW9+/8C8/7/Af3//wH8/v+51kr//8cB///HAf/+xgH/9pI1//SFQf/0hUH/dosX/zWPAP81jwD/NY8A/0uhJ/9TqDT/U6g0/yLAcf8A0Zr/ANGa/wDRmv+Y7Nb/////9sbGxir6+vr4k87+/wCP//8Cov3/Bbz7/wW8+/8FvPv/Bbz7/wTO/P8B/f7/Tuy1///GAf//xwH//8cB///HAf/8txD/9IVA/8WHMf81jgD/NY8A/zWPAP81jwD/OpMJ/1KnM/9DsEj/AdCZ/wDRmv8A0Zr/ANGa/xPUof/s+/f/mZmZAI+Pj4j7/f7/LqX+/wS5+/8FvPv/Bbz7/wW8+/8FvPv/Bbz7/wvo9//czib//8cB///HAf//xwH//8cB///HAP/1nCr/WY0M/zWPAP81jwD/NY8A/zWPAP81jwD/Rp0f/xPHg/8A0Zr/ANGa/wDRmv8A0Zr/ANGa/2vkxP/j4+MAyMjIDv///+jk9v7/yPD+/8jw/v/I8P7/yPD+/8jw/v/I8P7/1vLx///zx///88f///PH///zx///88f///PH//bvyf/T5sf/0+bH/9Pmx//T5sf/0+bH/9Pmx//R6c3/x/Xp/8f16f/H9en/x/Xp/8f16f/H9en/y/Xq///4////8P////B////gP///wD///8Af//+AH///gB///wAf//8AP//+AH///AAD//wAAf/4AAD/+AAA//AAAH/gAAB/4AAAP8AAAD/AAAA/gAAAfwAf//8AP///AD///wAAAAMAAAADAAAAAQAAAAAAAAAAgAAAAIAAAADAAAAA"+ );+});diff --git a/public/services/utils.ts b/public/services/utils.tsindex 82fb9c1e8..bc664c586 100644--- a/public/services/utils.ts+++ b/public/services/utils.ts@@ -85,3 +85,27 @@ export const timeSince = (now: Date, date: Date): string => {template("years", years)) + " ago");};++export const fileToBase64 = async (file: File): Promise<string> => {+ return new Promise<string>((resolve, reject) => {+ const reader = new FileReader();+ reader.addEventListener(+ "load",+ () => {+ const parts = (reader.result as string).split("base64,");+ resolve(parts[1]);+ },+ false+ );++ reader.addEventListener(+ "error",+ () => {+ reject(reader.error);+ },+ false+ );++ reader.readAsDataURL(file);+ });+};diff --git a/views/403.html b/views/403.htmlindex 70b84069e..153b9f5bd 100644--- a/views/403.html+++ b/views/403.html@@ -7,7 +7,7 @@ Not Authorized · Fider{{define "content"}}<div class="ui middle aligned center aligned grid failure-page"><div class="column">- <img src="https://getfider.com/images/logo-100x100.png"/>+ <img src="{{.__logo}}"/><h1>NOT AUTHORIZED</h1><p>You are not authorized to view this page.diff --git a/views/404.html b/views/404.htmlindex 420cc5c2a..2cb9ec877 100644--- a/views/404.html+++ b/views/404.html@@ -7,7 +7,7 @@{{define "content"}}<div class="ui middle aligned center aligned grid failure-page"><div class="column">- <img src="https://getfider.com/images/logo-100x100.png"/>+ <img src="{{.__logo}}"/><h1>PAGE NOT FOUND</h1><p>The link you clicked may be broken or <br />diff --git a/views/410.html b/views/410.htmlindex 51da3a8fd..5f7604a22 100644--- a/views/410.html+++ b/views/410.html@@ -7,7 +7,7 @@{{define "content"}}<div class="ui middle aligned center aligned grid failure-page"><div class="column">- <img src="https://getfider.com/images/logo-100x100.png"/>+ <img src="{{.__logo}}"/><h1>EXPIRED</h1><p>The link you clicked has expired.</p>diff --git a/views/500.html b/views/500.htmlindex 28c4760d9..469ec6f66 100644--- a/views/500.html+++ b/views/500.html@@ -7,7 +7,7 @@{{define "content"}}<div class="ui middle aligned center aligned grid failure-page"><div class="column">- <img src="https://getfider.com/images/logo-100x100.png"/>+ <img src="{{.__logo}}"/><h1>Shoot! Well, this is unexpected…</h1><p>An error has occurred and we're working to fix the problem! </br> We’ll be up and running shortly.</p>diff --git a/views/base.html b/views/base.htmlindex 0b2d82b57..aa0e625ef 100644--- a/views/base.html+++ b/views/base.html@@ -3,14 +3,14 @@<head><meta charset="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">- <link rel="icon" type="image/x-icon" href="/favicon.ico">+ <link rel="icon" type="image/x-icon" href="{{ .__favicon }}"><link rel="stylesheet" href="/assets/css/{{ .__StyleBundle }}" /><title>{{ template "title" .}}</title><meta property="og:title" content="{{template "title" .}}" /><meta property="og:description" content="We'd love to hear what you're thinking about. What can we do better? This is the place for you to vote, discuss and share ideas." /><meta property="og:type" content="website" /><meta property="og:url" content="{{ .baseURL }}" />- <meta property="og:image" content="https://getfider.com/images/logo-small.png">+ <meta property="og:image" content="{{ .__logo }}"></head><body><noscript class="ui container">diff --git a/views/not-invited.html b/views/not-invited.htmlindex a330c2b8d..355af237f 100644--- a/views/not-invited.html+++ b/views/not-invited.html@@ -7,7 +7,7 @@ Not Invited · Fider{{define "content"}}<div class="ui middle aligned center aligned grid failure-page"><div class="column">- <img src="https://getfider.com/images/logo-100x100.png"/>+ <img src="{{.__logo}}"/><h1>NOT INVITED</h1><p>We couldn't find your account for your email address.