// Copyright 2021 The casbin 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, Divider, Form, Select, Input, Row, 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 { CountDownInput } from "../component/CountDownInput"; import * as UserBackend from "../backend/UserBackend"; import { CheckCircleOutlined, KeyOutlined, LockOutlined, SolutionOutlined, UserOutlined, } from "@ant-design/icons"; const { Step } = Steps; const { Option } = Select; class ForgetPage extends React.Component { constructor(props) { super(props); this.state = { classes: props, account: props.account, applicationName: props.applicationName !== undefined ? props.applicationName : props.match === undefined ? null : props.match.params.applicationName, application: null, msg: null, userId: "", username: "", email: "", token: "", phone: "", emailCode: "", phoneCode: "", verifyType: "", // "email" or "phone" current: 0, }; } UNSAFE_componentWillMount() { if (this.state.applicationName !== undefined) { this.getApplication(); } else { Util.showMessage( "error", i18next.t(`forget:Unknown forgot type: `) + this.state.type ); } } getApplication() { if (this.state.applicationName === null) { return; } ApplicationBackend.getApplication("admin", this.state.applicationName).then( (application) => { this.setState({ application: application, }); } ); } getApplicationObj() { if (this.props.application !== undefined) { return this.props.application; } else { return this.state.application; } } onFinishStep1(values) { AuthBackend.getEmailAndPhone(values).then((res) => { if (res.status === "ok") { this.setState({ username: values.username, phone: res.data.toString(), email: res.data2.toString(), current: 1, }); } else { Setting.showMessage("error", i18next.t(`signup:${res.msg}`)); } }); } onFinishStep2(values) { values.phonePrefix = this.state.application?.organizationObj.phonePrefix; values.username = this.state.username; values.type = "login" const oAuthParams = Util.getOAuthGetParameters(); AuthBackend.login(values, oAuthParams).then(res => { if (res.status === "ok") { this.setState({current: 2, userId: res.data}) } else { Setting.showMessage("error", i18next.t(`signup:${res.msg}`)); } }) } onFinish(values) { values.username = this.state.username; values.userOwner = this.state.application?.organizationObj.name UserBackend.setPassword(values.userOwner, values.username, "", values?.newPassword).then(res => { if (res.status === "ok") { Setting.goToLogin(this, this.state.application); } else { Setting.showMessage("error", i18next.t(`signup:${res.msg}`)); } }) } onFinishFailed(values, errorFields) {} onChange = (current) => { this.setState({ current: current }); }; renderForm(application) { return ( <> {/* STEP 1: input username -> get email & phone */}