feat(web): add lint (#875)

* feat: add lint

* feat: fix lint error

* chore: add ignore file

* chore: close indent
This commit is contained in:
キリサメ qianxi
2022-07-10 15:45:55 +08:00
committed by GitHub
parent 475b6da35a
commit 503d244166
121 changed files with 17023 additions and 16815 deletions

View File

@ -39,7 +39,7 @@ import BaiduLoginButton from "./BaiduLoginButton";
import AlipayLoginButton from "./AlipayLoginButton";
import CasdoorLoginButton from "./CasdoorLoginButton";
import InfoflowLoginButton from "./InfoflowLoginButton";
import AppleLoginButton from "./AppleLoginButton"
import AppleLoginButton from "./AppleLoginButton";
import AzureADLoginButton from "./AzureADLoginButton";
import SlackLoginButton from "./SlackLoginButton";
import SteamLoginButton from "./SteamLoginButton";
@ -49,8 +49,6 @@ import CustomGithubCorner from "../CustomGithubCorner";
import {CountDownInput} from "../common/CountDownInput";
import BilibiliLoginButton from "./BilibiliLoginButton";
/* eslint-disable jsx-a11y/anchor-is-valid */
class LoginPage extends React.Component {
constructor(props) {
super(props);
@ -69,8 +67,8 @@ class LoginPage extends React.Component {
validPhone: false,
};
if (this.state.type === "cas" && props.match?.params.casApplicationName !== undefined) {
this.state.owner = props.match?.params.owner
this.state.applicationName = props.match?.params.casApplicationName
this.state.owner = props.match?.params.owner;
this.state.applicationName = props.match?.params.casApplicationName;
}
}
@ -79,7 +77,7 @@ class LoginPage extends React.Component {
this.getApplication();
} else if (this.state.type === "code") {
this.getApplicationLogin();
} else if (this.state.type === "saml"){
} else if (this.state.type === "saml") {
this.getSamlApplication();
} else {
Util.showMessage("error", `Unknown authentication type: ${this.state.type}`);
@ -117,8 +115,8 @@ class LoginPage extends React.Component {
});
}
getSamlApplication(){
if (this.state.applicationName === null){
getSamlApplication() {
if (this.state.applicationName === null) {
return;
}
ApplicationBackend.getApplication(this.state.owner, this.state.applicationName)
@ -127,7 +125,7 @@ class LoginPage extends React.Component {
application: application,
});
}
);
);
}
getApplicationObj() {
@ -152,7 +150,7 @@ class LoginPage extends React.Component {
const casParams = Util.getCasParameters();
values["type"] = this.state.type;
AuthBackend.loginCas(values, casParams).then((res) => {
if (res.status === 'ok') {
if (res.status === "ok") {
let msg = "Logged in successfully. ";
if (casParams.service === "") {
// If service was not specified, Casdoor must display a message notifying the client that it has successfully initiated a single sign-on session.
@ -169,7 +167,7 @@ class LoginPage extends React.Component {
} else {
Util.showMessage("error", `Failed to log in: ${res.msg}`);
}
})
});
} else {
// OAuth
const oAuthParams = Util.getOAuthGetParameters();
@ -185,21 +183,21 @@ class LoginPage extends React.Component {
}
if (values["samlRequest"] != null && values["samlRequest"] !== "") {
values["type"] = "saml";
values["type"] = "saml";
}
AuthBackend.login(values, oAuthParams)
.then((res) => {
if (res.status === 'ok') {
if (res.status === "ok") {
const responseType = values["type"];
if (responseType === "login") {
Util.showMessage("success", `Logged in successfully`);
Util.showMessage("success", "Logged in successfully");
const link = Setting.getFromLink();
Setting.goToLink(link);
} else if (responseType === "code") {
const code = res.data;
const concatChar = oAuthParams?.redirectUri?.includes('?') ? '&' : '?';
const concatChar = oAuthParams?.redirectUri?.includes("?") ? "&" : "?";
if (Setting.hasPromptPage(application)) {
AuthBackend.getAccount("")
@ -237,59 +235,59 @@ class LoginPage extends React.Component {
Util.showMessage("error", `Failed to log in: ${res.msg}`);
}
});
}
};
}
}
getSigninButton(type) {
const text = i18next.t("login:Sign in with {type}").replace("{type}", type);
if (type === "GitHub") {
return <GithubLoginButton text={text} align={"center"} />
return <GithubLoginButton text={text} align={"center"} />;
} else if (type === "Google") {
return <GoogleLoginButton text={text} align={"center"} />
return <GoogleLoginButton text={text} align={"center"} />;
} else if (type === "QQ") {
return <QqLoginButton text={text} align={"center"} />
return <QqLoginButton text={text} align={"center"} />;
} else if (type === "Facebook") {
return <FacebookLoginButton text={text} align={"center"} />
return <FacebookLoginButton text={text} align={"center"} />;
} else if (type === "Weibo") {
return <WeiboLoginButton text={text} align={"center"} />
return <WeiboLoginButton text={text} align={"center"} />;
} else if (type === "Gitee") {
return <GiteeLoginButton text={text} align={"center"} />
return <GiteeLoginButton text={text} align={"center"} />;
} else if (type === "WeChat") {
return <WechatLoginButton text={text} align={"center"} />
return <WechatLoginButton text={text} align={"center"} />;
} else if (type === "DingTalk") {
return <DingTalkLoginButton text={text} align={"center"} />
} else if (type === "LinkedIn"){
return <LinkedInLoginButton text={text} align={"center"} />
return <DingTalkLoginButton text={text} align={"center"} />;
} else if (type === "LinkedIn") {
return <LinkedInLoginButton text={text} align={"center"} />;
} else if (type === "WeCom") {
return <WeComLoginButton text={text} align={"center"} />
return <WeComLoginButton text={text} align={"center"} />;
} else if (type === "Lark") {
return <LarkLoginButton text={text} align={"center"} />
return <LarkLoginButton text={text} align={"center"} />;
} else if (type === "GitLab") {
return <GitLabLoginButton text={text} align={"center"} />
return <GitLabLoginButton text={text} align={"center"} />;
} else if (type === "Adfs") {
return <AdfsLoginButton text={text} align={"center"} />
return <AdfsLoginButton text={text} align={"center"} />;
} else if (type === "Casdoor") {
return <CasdoorLoginButton text={text} align={"center"} />
return <CasdoorLoginButton text={text} align={"center"} />;
} else if (type === "Baidu") {
return <BaiduLoginButton text={text} align={"center"} />
return <BaiduLoginButton text={text} align={"center"} />;
} else if (type === "Alipay") {
return <AlipayLoginButton text={text} align={"center"} />
return <AlipayLoginButton text={text} align={"center"} />;
} else if (type === "Infoflow") {
return <InfoflowLoginButton text={text} align={"center"} />
return <InfoflowLoginButton text={text} align={"center"} />;
} else if (type === "Apple") {
return <AppleLoginButton text={text} align={"center"} />
return <AppleLoginButton text={text} align={"center"} />;
} else if (type === "AzureAD") {
return <AzureADLoginButton text={text} align={"center"} />
return <AzureADLoginButton text={text} align={"center"} />;
} else if (type === "Slack") {
return <SlackLoginButton text={text} align={"center"} />
return <SlackLoginButton text={text} align={"center"} />;
} else if (type === "Steam") {
return <SteamLoginButton text={text} align={"center"} />
return <SteamLoginButton text={text} align={"center"} />;
} else if (type === "Bilibili") {
return <BilibiliLoginButton text={text} align={"center"} />
return <BilibiliLoginButton text={text} align={"center"} />;
} else if (type === "Okta") {
return <OktaLoginButton text={text} align={"center"} />
return <OktaLoginButton text={text} align={"center"} />;
} else if (type === "Douyin") {
return <DouyinLoginButton text={text} align={"center"} />
return <DouyinLoginButton text={text} align={"center"} />;
}
return text;
@ -305,9 +303,9 @@ class LoginPage extends React.Component {
let relayState = `${clientId}&${application}&${providerName}&${realRedirectUri}&${redirectUri}`;
AuthBackend.getSamlLogin(`${provider.owner}/${providerName}`, btoa(relayState)).then((res) => {
if (res.data2 === "POST") {
document.write(res.data)
document.write(res.data);
} else {
window.location.href = res.data
window.location.href = res.data;
}
});
}
@ -319,15 +317,15 @@ class LoginPage extends React.Component {
<a key={provider.displayName} href={Provider.getAuthUrl(application, provider, "signup")}>
<img width={width} height={width} src={Setting.getProviderLogoURL(provider)} alt={provider.displayName} style={{margin: margin}} />
</a>
)
);
} else if (provider.category === "SAML") {
return (
<a key={provider.displayName} onClick={this.getSamlUrl.bind(this, provider)}>
<img width={width} height={width} src={Setting.getProviderLogoURL(provider)} alt={provider.displayName} style={{margin: margin}} />
</a>
)
);
}
} else {
return (
<div key={provider.displayName} style={{marginBottom: "10px"}}>
@ -337,7 +335,7 @@ class LoginPage extends React.Component {
}
</a>
</div>
)
);
}
}
@ -351,7 +349,7 @@ class LoginPage extends React.Component {
renderForm(application) {
if (this.state.msg !== null) {
return Util.renderMessage(this.state.msg)
return Util.renderMessage(this.state.msg);
}
if (this.state.mode === "signup" && !application.enableSignUp) {
@ -371,7 +369,7 @@ class LoginPage extends React.Component {
]}
>
</Result>
)
);
}
if (application.enablePassword) {
@ -383,7 +381,7 @@ class LoginPage extends React.Component {
application: application.name,
autoSignin: true,
}}
onFinish={(values) => {this.onFinish(values)}}
onFinish={(values) => {this.onFinish(values);}}
style={{width: "300px"}}
size="large"
>
@ -393,7 +391,7 @@ class LoginPage extends React.Component {
rules={[
{
required: true,
message: 'Please input your application!',
message: "Please input your application!",
},
]}
>
@ -404,7 +402,7 @@ class LoginPage extends React.Component {
rules={[
{
required: true,
message: 'Please input your organization!',
message: "Please input your organization!",
},
]}
>
@ -412,33 +410,33 @@ class LoginPage extends React.Component {
<Form.Item
name="username"
rules={[
{
required: true,
message: i18next.t("login:Please input your username, Email or phone!")
},
{
validator: (_, value) => {
if (this.state.isCodeSignin) {
if (this.state.email !== "" && !Setting.isValidEmail(this.state.username) && !Setting.isValidPhone(this.state.username)) {
this.setState({validEmailOrPhone: false});
return Promise.reject(i18next.t("login:The input is not valid Email or Phone!"));
}
{
required: true,
message: i18next.t("login:Please input your username, Email or phone!")
},
{
validator: (_, value) => {
if (this.state.isCodeSignin) {
if (this.state.email !== "" && !Setting.isValidEmail(this.state.username) && !Setting.isValidPhone(this.state.username)) {
this.setState({validEmailOrPhone: false});
return Promise.reject(i18next.t("login:The input is not valid Email or Phone!"));
}
if (Setting.isValidPhone(this.state.username)) {
this.setState({validPhone: true})
}
if (Setting.isValidEmail(this.state.username)) {
this.setState({validEmail: true})
}
this.setState({validEmailOrPhone: true});
return Promise.resolve();
}
if (Setting.isValidPhone(this.state.username)) {
this.setState({validPhone: true});
}
if (Setting.isValidEmail(this.state.username)) {
this.setState({validEmail: true});
}
this.setState({validEmailOrPhone: true});
return Promise.resolve();
}
]}
}
]}
>
<Input
prefix={<UserOutlined className="site-form-item-icon" />}
placeholder={ this.state.isCodeSignin ? i18next.t("login:Email or phone") : i18next.t("login:username, Email or phone") }
placeholder={this.state.isCodeSignin ? i18next.t("login:Email or phone") : i18next.t("login:username, Email or phone")}
disabled={!application.enablePassword}
onChange={e => {
this.setState({
@ -451,7 +449,7 @@ class LoginPage extends React.Component {
this.state.isCodeSignin ? (
<Form.Item
name="code"
rules={[{ required: true, message: i18next.t("login:Please input your code!") }]}
rules={[{required: true, message: i18next.t("login:Please input your code!")}]}
>
<CountDownInput
disabled={this.state.username?.length === 0 || !this.state.validEmailOrPhone}
@ -461,7 +459,7 @@ class LoginPage extends React.Component {
) : (
<Form.Item
name="password"
rules={[{ required: true, message: i18next.t("login:Please input your password!") }]}
rules={[{required: true, message: i18next.t("login:Please input your password!")}]}
>
<Input
prefix={<LockOutlined className="site-form-item-icon" />}
@ -488,7 +486,7 @@ class LoginPage extends React.Component {
<Button
type="primary"
htmlType="submit"
style={{width: "100%", marginBottom: '5px'}}
style={{width: "100%", marginBottom: "5px"}}
disabled={!application.enablePassword}
>
{i18next.t("login:Sign In")}
@ -518,7 +516,7 @@ class LoginPage extends React.Component {
</a>
:
</div>
<br/>
<br />
{
application.providers.filter(providerItem => this.isProviderVisible(providerItem)).map(providerItem => {
return this.renderProviderLogo(providerItem.provider, application, 40, 10, "big");
@ -527,7 +525,7 @@ class LoginPage extends React.Component {
{
!application.enableSignUp ? null : (
<div>
<br/>
<br />
{
this.renderFooter(application)
}
@ -535,7 +533,7 @@ class LoginPage extends React.Component {
)
}
</div>
)
);
}
}
@ -550,7 +548,7 @@ class LoginPage extends React.Component {
{i18next.t("signup:sign in now")}
</Link>
</div>
)
);
} else {
return (
<React.Fragment>
@ -570,14 +568,14 @@ class LoginPage extends React.Component {
<span style={{float: "right"}}>
{i18next.t("login:No account?")}&nbsp;
<a onClick={() => {
sessionStorage.setItem("signinUrl", window.location.href)
sessionStorage.setItem("signinUrl", window.location.href);
Setting.goToSignup(this, application);
}}>
{i18next.t("login:sign up now")}
</a>
</span>
</React.Fragment>
)
);
}
}
@ -585,7 +583,7 @@ class LoginPage extends React.Component {
if (this.props.account === undefined || this.props.account === null) {
return null;
}
let application = this.getApplicationObj()
let application = this.getApplicationObj();
if (this.props.account.owner !== application.organization) {
return null;
}
@ -605,25 +603,25 @@ class LoginPage extends React.Component {
return (
<div>
{/*{*/}
{/* {*/}
{/* JSON.stringify(silentSignin)*/}
{/*}*/}
{/* }*/}
<div style={{fontSize: 16, textAlign: "left"}}>
{i18next.t("login:Continue with")}&nbsp;:
</div>
<br/>
<br />
<SelfLoginButton account={this.props.account} onClick={() => {
let values = {};
values["application"] = this.state.application.name;
this.onFinish(values);
}} />
<br/>
<br/>
<br />
<br />
<div style={{fontSize: 16, textAlign: "left"}}>
{i18next.t("login:Or sign in with another account")}&nbsp;:
</div>
</div>
)
);
}
render() {
@ -634,8 +632,8 @@ class LoginPage extends React.Component {
if (application.signinHtml !== "") {
return (
<div dangerouslySetInnerHTML={{ __html: application.signinHtml}} />
)
<div dangerouslySetInnerHTML={{__html: application.signinHtml}} />
);
}
const visibleOAuthProviderItems = application.providers.filter(providerItem => this.isProviderVisible(providerItem));
@ -645,7 +643,7 @@ class LoginPage extends React.Component {
<div style={{textAlign: "center"}}>
<Spin size="large" tip={i18next.t("login:Signing in...")} style={{paddingTop: "10%"}} />
</div>
)
);
}
return (
@ -659,9 +657,9 @@ class LoginPage extends React.Component {
{
Setting.renderLogo(application)
}
{/*{*/}
{/* {*/}
{/* this.state.clientId !== null ? "Redirect" : null*/}
{/*}*/}
{/* }*/}
{
this.renderSignedInBox()
}
@ -671,7 +669,7 @@ class LoginPage extends React.Component {
</div>
</Col>
</Row>
)
);
}
}