// Copyright 2021 The Casdoor Authors. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. import React from "react"; import {Button, Col, Form, Input, Row, Select, Steps} from "antd"; import * as AuthBackend from "./AuthBackend"; import * as ApplicationBackend from "../backend/ApplicationBackend"; import * as Util from "./Util"; import * as Setting from "../Setting"; import i18next from "i18next"; import {SendCodeInput} from "../common/SendCodeInput"; import * as UserBackend from "../backend/UserBackend"; import {ArrowLeftOutlined, CheckCircleOutlined, KeyOutlined, LockOutlined, SolutionOutlined, UserOutlined} from "@ant-design/icons"; import CustomGithubCorner from "../common/CustomGithubCorner"; import {withRouter} from "react-router-dom"; import * as PasswordChecker from "../common/PasswordChecker"; const {Option} = Select; class ForgetPage extends React.Component { constructor(props) { super(props); this.state = { classes: props, applicationName: props.applicationName ?? props.match.params?.applicationName, msg: null, name: "", username: "", phone: "", email: "", dest: "", isVerifyTypeFixed: false, verifyType: "", // "email", "phone" current: 0, }; this.form = React.createRef(); } componentDidMount() { if (this.getApplicationObj() === undefined) { if (this.state.applicationName !== undefined) { this.getApplication(); } else { Setting.showMessage("error", i18next.t("forget:Unknown forget type") + ": " + this.state.type); } } } getApplication() { if (this.state.applicationName === undefined) { return; } ApplicationBackend.getApplication("admin", this.state.applicationName) .then((res) => { if (res.status === "error") { Setting.showMessage("error", res.msg); return; } this.onUpdateApplication(res.data); }); } getApplicationObj() { return this.props.application; } onUpdateApplication(application) { this.props.onUpdateApplication(application); } onFormFinish(name, info, forms) { switch (name) { case "step1": const username = forms.step1.getFieldValue("username"); AuthBackend.getEmailAndPhone(forms.step1.getFieldValue("organization"), username) .then((res) => { if (res.status === "ok") { const phone = res.data.phone; const email = res.data.email; if (!phone && !email) { Setting.showMessage("error", "no verification method!"); } else { this.setState({ name: res.data.name, phone: phone, email: email, }); const saveFields = (type, dest, fixed) => { this.setState({ verifyType: type, isVerifyTypeFixed: fixed, dest: dest, }); }; switch (res.data2) { case "email": saveFields("email", email, true); break; case "phone": saveFields("phone", phone, true); break; case "username": phone !== "" ? saveFields("phone", phone, false) : saveFields("email", email, false); } this.setState({ current: 1, }); } } else { Setting.showMessage("error", res.msg); } }); break; case "step2": UserBackend.verifyCode({ application: forms.step2.getFieldValue("application"), organization: forms.step2.getFieldValue("organization"), username: forms.step2.getFieldValue("dest"), name: this.state.name, code: forms.step2.getFieldValue("code"), type: "login", }).then(res => { if (res.status === "ok") { this.setState({current: 2, code: forms.step2.getFieldValue("code")}); } else { Setting.showMessage("error", res.msg); } }); break; default: break; } } onFinish(values) { values.username = this.state.name; values.userOwner = this.getApplicationObj()?.organizationObj.name; UserBackend.setPassword(values.userOwner, values.username, "", values?.newPassword, this.state.code).then(res => { if (res.status === "ok") { const linkInStorage = sessionStorage.getItem("signinUrl"); if (linkInStorage !== null && linkInStorage !== "") { Setting.goToLinkSoft(this, linkInStorage); } else { Setting.redirectToLoginPage(this.getApplicationObj(), this.props.history); } } else { Setting.showMessage("error", res.msg); } }); } onFinishFailed(values, errorFields) {} renderOptions() { const options = []; if (this.state.phone !== "") { options.push( ); } if (this.state.email !== "") { options.push( ); } return options; } renderForm(application) { return (