X-Git-Url: http://these/git/?a=blobdiff_plain;f=src%2Fshared%2Fcomponents%2Fhome%2Fsignup.tsx;h=bb1e1f1142be867fd69c742914f90aa2b70d5ab6;hb=c3ab9e74f8775f4b811866d2675b00f9702bde3d;hp=aecba9f9c873036fce671a66cd0569a6c581927e;hpb=e947549cdccddf9fae0d8ac2b1a32ed90837940b;p=lemmy-ui.git diff --git a/src/shared/components/home/signup.tsx b/src/shared/components/home/signup.tsx index aecba9f..bb1e1f1 100644 --- a/src/shared/components/home/signup.tsx +++ b/src/shared/components/home/signup.tsx @@ -1,3 +1,6 @@ +import { myAuth, setIsoData } from "@utils/app"; +import { isBrowser } from "@utils/browser"; +import { validEmail } from "@utils/helpers"; import { Options, passwordStrength } from "check-password-strength"; import { NoOptionI18nKeys } from "i18next"; import { Component, linkEvent } from "inferno"; @@ -7,26 +10,13 @@ import { GetCaptchaResponse, GetSiteResponse, LoginResponse, - Register, - RegistrationMode, SiteView, - UserOperation, - wsJsonToRes, - wsUserOp, } from "lemmy-js-client"; -import { Subscription } from "rxjs"; -import { i18n } from "../../i18next"; -import { UserService, WebSocketService } from "../../services"; -import { - isBrowser, - joinLemmyUrl, - mdToHtml, - setIsoData, - toast, - validEmail, - wsClient, - wsSubscribe, -} from "../../utils"; +import { joinLemmyUrl } from "../../config"; +import { mdToHtml } from "../../markdown"; +import { I18NextService, UserService } from "../../services"; +import { HttpService, RequestState } from "../../services/HttpService"; +import { toast } from "../../toast"; import { HtmlTags } from "../common/html-tags"; import { Icon, Spinner } from "../common/icon"; import { MarkdownTextArea } from "../common/markdown-textarea"; @@ -59,6 +49,8 @@ const passwordStrengthOptions: Options = [ ]; interface State { + registerRes: RequestState; + captchaRes: RequestState; form: { username?: string; email?: string; @@ -70,22 +62,20 @@ interface State { honeypot?: string; answer?: string; }; - registerLoading: boolean; - captcha?: GetCaptchaResponse; captchaPlaying: boolean; siteRes: GetSiteResponse; } export class Signup extends Component { private isoData = setIsoData(this.context); - private subscription?: Subscription; private audio?: HTMLAudioElement; state: State = { + registerRes: { state: "empty" }, + captchaRes: { state: "empty" }, form: { show_nsfw: false, }, - registerLoading: false, captchaPlaying: false, siteRes: this.isoData.site_res, }; @@ -94,28 +84,35 @@ export class Signup extends Component { super(props, context); this.handleAnswerChange = this.handleAnswerChange.bind(this); + } - this.parseMessage = this.parseMessage.bind(this); - this.subscription = wsSubscribe(this.parseMessage); - - if (isBrowser()) { - WebSocketService.Instance.send(wsClient.getCaptcha()); + async componentDidMount() { + if (this.state.siteRes.site_view.local_site.captcha_enabled) { + await this.fetchCaptcha(); } } - componentWillUnmount() { - if (isBrowser()) { - this.subscription?.unsubscribe(); - } + async fetchCaptcha() { + this.setState({ captchaRes: { state: "loading" } }); + this.setState({ + captchaRes: await HttpService.client.getCaptcha({}), + }); + + this.setState(s => { + if (s.captchaRes.state == "success") { + s.form.captcha_uuid = s.captchaRes.data.ok?.uuid; + } + return s; + }); } get documentTitle(): string { - let siteView = this.state.siteRes.site_view; + const siteView = this.state.siteRes.site_view; return `${this.titleName(siteView)} - ${siteView.site.name}`; } titleName(siteView: SiteView): string { - return i18n.t( + return I18NextService.i18n.t( siteView.local_site.private_instance ? "apply_to_join" : "sign_up" ); } @@ -126,7 +123,7 @@ export class Signup extends Component { render() { return ( -
+
{ } registerForm() { - let siteView = this.state.siteRes.site_view; + const siteView = this.state.siteRes.site_view; return ( -
-
{this.titleName(siteView)}
+ +

{this.titleName(siteView)}

{this.isLemmyMl && ( -
+
## @@ -156,12 +156,12 @@ export class Signup extends Component {
)} -
+
@@ -174,14 +174,14 @@ export class Signup extends Component { required minLength={3} pattern="[a-zA-Z0-9_]+" - title={i18n.t("community_reqs")} + title={I18NextService.i18n.t("community_reqs")} />
-
+
{ className="form-control" placeholder={ siteView.local_site.require_email_verification - ? i18n.t("required") - : i18n.t("optional") + ? I18NextService.i18n.t("required") + : I18NextService.i18n.t("optional") } value={this.state.form.email} autoComplete="email" @@ -203,19 +203,19 @@ export class Signup extends Component { this.state.form.email && !validEmail(this.state.form.email) && (
- - {i18n.t("no_password_reset")} + + {I18NextService.i18n.t("no_password_reset")}
)}
-
+
{ /> {this.state.form.password && (
- {i18n.t(this.passwordStrength as NoOptionI18nKeys)} + {I18NextService.i18n.t( + this.passwordStrength as NoOptionI18nKeys + )}
)}
-
+
{
- {siteView.local_site.registration_mode == - RegistrationMode.RequireApplication && ( + {siteView.local_site.registration_mode == "RequireApplication" && ( <> -
+
- - {i18n.t("fill_out_application")} + + {I18NextService.i18n.t("fill_out_application")}
{siteView.local_site.application_question && (
{
-
+
{
)} - - {this.state.captcha && ( -
- - {this.showCaptcha()} -
+ {this.renderCaptcha()} +
+
+
+
- )} - {siteView.local_site.enable_nsfw && ( -
-
-
- - -
-
-
- )} +
{ value={this.state.form.honeypot} onInput={linkEvent(this, this.handleHoneyPotChange)} /> -
+
+ + {this.showCaptcha(res)} +
+ +
+
+ ); + } + } + } + + showCaptcha(res: GetCaptchaResponse) { + const captchaRes = res?.ok; return captchaRes ? (
<> @@ -381,13 +390,13 @@ export class Signup extends Component { className="rounded-top img-fluid" src={this.captchaPngSrc(captchaRes)} style="border-bottom-right-radius: 0; border-bottom-left-radius: 0;" - alt={i18n.t("captcha")} + alt={I18NextService.i18n.t("captcha")} /> {captchaRes.wav && (