Use helmet on login, signup pages.

This commit is contained in:
Yang Luo 2021-04-29 21:28:24 +08:00
parent 3065bacad2
commit 785f306c4b
5 changed files with 46 additions and 13 deletions

View File

@ -24,15 +24,16 @@ type Application struct {
Name string `xorm:"varchar(100) notnull pk" json:"name"` Name string `xorm:"varchar(100) notnull pk" json:"name"`
CreatedTime string `xorm:"varchar(100)" json:"createdTime"` CreatedTime string `xorm:"varchar(100)" json:"createdTime"`
DisplayName string `xorm:"varchar(100)" json:"displayName"` DisplayName string `xorm:"varchar(100)" json:"displayName"`
Logo string `xorm:"varchar(100)" json:"logo"` Logo string `xorm:"varchar(100)" json:"logo"`
HomepageUrl string `xorm:"varchar(100)" json:"homepageUrl"` HomepageUrl string `xorm:"varchar(100)" json:"homepageUrl"`
Description string `xorm:"varchar(100)" json:"description"` Description string `xorm:"varchar(100)" json:"description"`
Organization string `xorm:"varchar(100)" json:"organization"` Organization string `xorm:"varchar(100)" json:"organization"`
EnablePassword bool `json:"enablePassword"` EnablePassword bool `json:"enablePassword"`
EnableSignUp bool `json:"enableSignUp"` EnableSignUp bool `json:"enableSignUp"`
Providers []string `xorm:"varchar(100)" json:"providers"` Providers []string `xorm:"varchar(100)" json:"providers"`
ProviderObjs []*Provider `xorm:"-" json:"providerObjs"` ProviderObjs []*Provider `xorm:"-" json:"providerObjs"`
OrganizationObj *Organization `xorm:"-" json:"organizationObj"`
ClientId string `xorm:"varchar(100)" json:"clientId"` ClientId string `xorm:"varchar(100)" json:"clientId"`
ClientSecret string `xorm:"varchar(100)" json:"clientSecret"` ClientSecret string `xorm:"varchar(100)" json:"clientSecret"`
@ -50,7 +51,7 @@ func GetApplications(owner string) []*Application {
return applications return applications
} }
func extendApplication(application *Application) { func extendApplicationWithProviders(application *Application) {
providers := GetProviders(application.Owner) providers := GetProviders(application.Owner)
m := map[string]*Provider{} m := map[string]*Provider{}
for _, provider := range providers { for _, provider := range providers {
@ -65,6 +66,11 @@ func extendApplication(application *Application) {
} }
} }
func extendApplicationWithOrg(application *Application) {
organization := getOrganization(application.Owner, application.Organization)
application.OrganizationObj = organization
}
func getApplication(owner string, name string) *Application { func getApplication(owner string, name string) *Application {
application := Application{Owner: owner, Name: name} application := Application{Owner: owner, Name: name}
existed, err := adapter.engine.Get(&application) existed, err := adapter.engine.Get(&application)
@ -73,7 +79,8 @@ func getApplication(owner string, name string) *Application {
} }
if existed { if existed {
extendApplication(&application) extendApplicationWithProviders(&application)
extendApplicationWithOrg(&application)
return &application return &application
} else { } else {
return nil return nil
@ -89,7 +96,8 @@ func GetDefaultApplication(owner string) *Application {
} }
if existed { if existed {
extendApplication(&application) extendApplicationWithProviders(&application)
extendApplicationWithOrg(&application)
return &application return &application
} else { } else {
return nil return nil
@ -104,7 +112,8 @@ func getApplicationByClientId(clientId string) *Application {
} }
if existed { if existed {
extendApplication(&application) extendApplicationWithProviders(&application)
extendApplicationWithOrg(&application)
return &application return &application
} else { } else {
return nil return nil

View File

@ -19,6 +19,7 @@ import "./i18n";
import i18next from "i18next"; import i18next from "i18next";
import copy from "copy-to-clipboard"; import copy from "copy-to-clipboard";
import {authConfig} from "./auth/Auth"; import {authConfig} from "./auth/Auth";
import {Helmet} from "react-helmet";
export let ServerUrl = ""; export let ServerUrl = "";
@ -210,3 +211,16 @@ export function goToLogin(ths, application) {
goToLink(`${application.homepageUrl}/login`); goToLink(`${application.homepageUrl}/login`);
} }
} }
export function renderHelmet(application) {
if (application === undefined || application === null || application.organizationObj === undefined || application.organizationObj === null ||application.organizationObj === "") {
return null;
}
return (
<Helmet>
<title>{application.organizationObj.displayName}</title>
<link rel="icon" href={application.organizationObj.favicon} />
</Helmet>
)
}

View File

@ -25,6 +25,7 @@ import {GithubLoginButton, GoogleLoginButton} from "react-social-login-buttons";
import QqLoginButton from "./QqLoginButton"; import QqLoginButton from "./QqLoginButton";
import i18next from "i18next"; import i18next from "i18next";
import {authConfig} from "./Auth"; import {authConfig} from "./Auth";
import {Helmet} from "react-helmet";
class LoginPage extends React.Component { class LoginPage extends React.Component {
constructor(props) { constructor(props) {
@ -282,6 +283,9 @@ class LoginPage extends React.Component {
<Row> <Row>
<Col span={24} style={{display: "flex", justifyContent: "center"}}> <Col span={24} style={{display: "flex", justifyContent: "center"}}>
<div style={{marginTop: "80px", textAlign: "center"}}> <div style={{marginTop: "80px", textAlign: "center"}}>
{
Setting.renderHelmet(application)
}
{ {
Setting.renderLogo(application) Setting.renderLogo(application)
} }

View File

@ -56,6 +56,9 @@ class ResultPage extends React.Component {
return ( return (
<div> <div>
{
Setting.renderHelmet(application)
}
<Result <Result
status="success" status="success"
title={i18next.t("signup:Your account has been created!")} title={i18next.t("signup:Your account has been created!")}

View File

@ -294,6 +294,9 @@ class SignupPage extends React.Component {
<Row> <Row>
<Col span={24} style={{display: "flex", justifyContent: "center"}} > <Col span={24} style={{display: "flex", justifyContent: "center"}} >
<div style={{marginTop: "10px", textAlign: "center"}}> <div style={{marginTop: "10px", textAlign: "center"}}>
{
Setting.renderHelmet(application)
}
{ {
Setting.renderLogo(application) Setting.renderLogo(application)
} }