2021-10-01 14:19:47 +00:00
|
|
|
import { Options, passwordStrength } from "check-password-strength";
|
2023-04-03 13:28:56 +00:00
|
|
|
import { NoOptionI18nKeys } from "i18next";
|
2021-09-19 20:31:17 +00:00
|
|
|
import { Component, linkEvent } from "inferno";
|
|
|
|
import { T } from "inferno-i18next-dess";
|
|
|
|
import {
|
2022-06-21 21:42:29 +00:00
|
|
|
CaptchaResponse,
|
2021-09-19 20:31:17 +00:00
|
|
|
GetCaptchaResponse,
|
|
|
|
GetSiteResponse,
|
|
|
|
LoginResponse,
|
|
|
|
Register,
|
2023-01-04 16:56:24 +00:00
|
|
|
RegistrationMode,
|
2021-09-19 20:31:17 +00:00
|
|
|
SiteView,
|
|
|
|
UserOperation,
|
2022-06-21 21:42:29 +00:00
|
|
|
wsJsonToRes,
|
|
|
|
wsUserOp,
|
2021-09-19 20:31:17 +00:00
|
|
|
} from "lemmy-js-client";
|
|
|
|
import { Subscription } from "rxjs";
|
|
|
|
import { i18n } from "../../i18next";
|
|
|
|
import { UserService, WebSocketService } from "../../services";
|
|
|
|
import {
|
|
|
|
isBrowser,
|
|
|
|
joinLemmyUrl,
|
2021-12-30 15:26:45 +00:00
|
|
|
mdToHtml,
|
2021-09-19 20:31:17 +00:00
|
|
|
setIsoData,
|
|
|
|
toast,
|
|
|
|
validEmail,
|
|
|
|
wsClient,
|
|
|
|
wsSubscribe,
|
|
|
|
} from "../../utils";
|
|
|
|
import { HtmlTags } from "../common/html-tags";
|
|
|
|
import { Icon, Spinner } from "../common/icon";
|
2021-12-30 15:26:45 +00:00
|
|
|
import { MarkdownTextArea } from "../common/markdown-textarea";
|
2021-09-19 20:31:17 +00:00
|
|
|
|
|
|
|
const passwordStrengthOptions: Options<string> = [
|
|
|
|
{
|
|
|
|
id: 0,
|
2021-10-18 01:43:45 +00:00
|
|
|
value: "very_weak",
|
2021-09-19 20:31:17 +00:00
|
|
|
minDiversity: 0,
|
|
|
|
minLength: 0,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
value: "weak",
|
|
|
|
minDiversity: 2,
|
|
|
|
minLength: 10,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
value: "medium",
|
|
|
|
minDiversity: 3,
|
|
|
|
minLength: 12,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 3,
|
|
|
|
value: "strong",
|
|
|
|
minDiversity: 4,
|
|
|
|
minLength: 14,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
interface State {
|
2023-01-04 16:56:24 +00:00
|
|
|
form: {
|
|
|
|
username?: string;
|
|
|
|
email?: string;
|
|
|
|
password?: string;
|
|
|
|
password_verify?: string;
|
|
|
|
show_nsfw: boolean;
|
|
|
|
captcha_uuid?: string;
|
|
|
|
captcha_answer?: string;
|
|
|
|
honeypot?: string;
|
|
|
|
answer?: string;
|
|
|
|
};
|
2021-09-19 20:31:17 +00:00
|
|
|
registerLoading: boolean;
|
2023-01-04 16:56:24 +00:00
|
|
|
captcha?: GetCaptchaResponse;
|
2021-09-19 20:31:17 +00:00
|
|
|
captchaPlaying: boolean;
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: GetSiteResponse;
|
2021-09-19 20:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export class Signup extends Component<any, State> {
|
|
|
|
private isoData = setIsoData(this.context);
|
2023-01-04 16:56:24 +00:00
|
|
|
private subscription?: Subscription;
|
|
|
|
private audio?: HTMLAudioElement;
|
|
|
|
|
|
|
|
state: State = {
|
|
|
|
form: {
|
2021-09-19 20:31:17 +00:00
|
|
|
show_nsfw: false,
|
2023-01-04 16:56:24 +00:00
|
|
|
},
|
2021-09-19 20:31:17 +00:00
|
|
|
registerLoading: false,
|
|
|
|
captchaPlaying: false,
|
2022-06-21 21:42:29 +00:00
|
|
|
siteRes: this.isoData.site_res,
|
2021-09-19 20:31:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
|
2021-12-30 15:26:45 +00:00
|
|
|
this.handleAnswerChange = this.handleAnswerChange.bind(this);
|
2021-09-19 20:31:17 +00:00
|
|
|
|
|
|
|
this.parseMessage = this.parseMessage.bind(this);
|
|
|
|
this.subscription = wsSubscribe(this.parseMessage);
|
|
|
|
|
|
|
|
if (isBrowser()) {
|
|
|
|
WebSocketService.Instance.send(wsClient.getCaptcha());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
if (isBrowser()) {
|
2023-01-04 16:56:24 +00:00
|
|
|
this.subscription?.unsubscribe();
|
2021-09-19 20:31:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
get documentTitle(): string {
|
2022-11-09 19:53:07 +00:00
|
|
|
let siteView = this.state.siteRes.site_view;
|
|
|
|
return `${this.titleName(siteView)} - ${siteView.site.name}`;
|
2021-12-30 15:26:45 +00:00
|
|
|
}
|
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
titleName(siteView: SiteView): string {
|
2022-11-09 19:53:07 +00:00
|
|
|
return i18n.t(
|
|
|
|
siteView.local_site.private_instance ? "apply_to_join" : "sign_up"
|
|
|
|
);
|
2021-09-19 20:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get isLemmyMl(): boolean {
|
|
|
|
return isBrowser() && window.location.hostname == "lemmy.ml";
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2022-10-03 18:16:36 +00:00
|
|
|
<div className="container-lg">
|
2021-09-19 20:31:17 +00:00
|
|
|
<HtmlTags
|
|
|
|
title={this.documentTitle}
|
|
|
|
path={this.context.router.route.match.url}
|
|
|
|
/>
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-12 col-lg-6 offset-lg-3">
|
|
|
|
{this.registerForm()}
|
|
|
|
</div>
|
2021-09-19 20:31:17 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
registerForm() {
|
2022-11-09 19:53:07 +00:00
|
|
|
let siteView = this.state.siteRes.site_view;
|
|
|
|
return (
|
|
|
|
<form onSubmit={linkEvent(this, this.handleRegisterSubmit)}>
|
|
|
|
<h5>{this.titleName(siteView)}</h5>
|
2021-09-19 20:31:17 +00:00
|
|
|
|
2022-11-09 19:53:07 +00:00
|
|
|
{this.isLemmyMl && (
|
|
|
|
<div className="form-group row">
|
|
|
|
<div className="mt-2 mb-0 alert alert-warning" role="alert">
|
|
|
|
<T i18nKey="lemmy_ml_registration_message">
|
|
|
|
#<a href={joinLemmyUrl}>#</a>
|
|
|
|
</T>
|
2022-01-27 18:44:08 +00:00
|
|
|
</div>
|
2022-11-09 19:53:07 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<div className="form-group row">
|
|
|
|
<label
|
|
|
|
className="col-sm-2 col-form-label"
|
|
|
|
htmlFor="register-username"
|
|
|
|
>
|
|
|
|
{i18n.t("username")}
|
|
|
|
</label>
|
|
|
|
|
|
|
|
<div className="col-sm-10">
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
id="register-username"
|
|
|
|
className="form-control"
|
2023-01-04 16:56:24 +00:00
|
|
|
value={this.state.form.username}
|
2022-11-09 19:53:07 +00:00
|
|
|
onInput={linkEvent(this, this.handleRegisterUsernameChange)}
|
|
|
|
required
|
|
|
|
minLength={3}
|
|
|
|
pattern="[a-zA-Z0-9_]+"
|
|
|
|
title={i18n.t("community_reqs")}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-09-19 20:31:17 +00:00
|
|
|
|
2022-11-09 19:53:07 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<label className="col-sm-2 col-form-label" htmlFor="register-email">
|
|
|
|
{i18n.t("email")}
|
|
|
|
</label>
|
|
|
|
<div className="col-sm-10">
|
|
|
|
<input
|
|
|
|
type="email"
|
|
|
|
id="register-email"
|
|
|
|
className="form-control"
|
|
|
|
placeholder={
|
|
|
|
siteView.local_site.require_email_verification
|
|
|
|
? i18n.t("required")
|
|
|
|
: i18n.t("optional")
|
|
|
|
}
|
2023-01-04 16:56:24 +00:00
|
|
|
value={this.state.form.email}
|
2022-11-09 19:53:07 +00:00
|
|
|
autoComplete="email"
|
|
|
|
onInput={linkEvent(this, this.handleRegisterEmailChange)}
|
|
|
|
required={siteView.local_site.require_email_verification}
|
|
|
|
minLength={3}
|
|
|
|
/>
|
|
|
|
{!siteView.local_site.require_email_verification &&
|
2023-01-04 16:56:24 +00:00
|
|
|
this.state.form.email &&
|
|
|
|
!validEmail(this.state.form.email) && (
|
2022-11-09 19:53:07 +00:00
|
|
|
<div className="mt-2 mb-0 alert alert-warning" role="alert">
|
|
|
|
<Icon icon="alert-triangle" classes="icon-inline mr-2" />
|
|
|
|
{i18n.t("no_password_reset")}
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-09-19 20:31:17 +00:00
|
|
|
|
2022-11-09 19:53:07 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<label
|
|
|
|
className="col-sm-2 col-form-label"
|
|
|
|
htmlFor="register-password"
|
|
|
|
>
|
|
|
|
{i18n.t("password")}
|
|
|
|
</label>
|
|
|
|
<div className="col-sm-10">
|
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
id="register-password"
|
2023-01-04 16:56:24 +00:00
|
|
|
value={this.state.form.password}
|
2022-11-09 19:53:07 +00:00
|
|
|
autoComplete="new-password"
|
|
|
|
onInput={linkEvent(this, this.handleRegisterPasswordChange)}
|
|
|
|
minLength={10}
|
|
|
|
maxLength={60}
|
|
|
|
className="form-control"
|
|
|
|
required
|
|
|
|
/>
|
2023-01-04 16:56:24 +00:00
|
|
|
{this.state.form.password && (
|
2022-11-09 19:53:07 +00:00
|
|
|
<div className={this.passwordColorClass}>
|
2023-04-03 13:28:56 +00:00
|
|
|
{i18n.t(this.passwordStrength as NoOptionI18nKeys)}
|
2022-11-09 19:53:07 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2021-09-19 20:31:17 +00:00
|
|
|
</div>
|
2022-11-09 19:53:07 +00:00
|
|
|
</div>
|
2021-09-19 20:31:17 +00:00
|
|
|
|
2022-11-09 19:53:07 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<label
|
|
|
|
className="col-sm-2 col-form-label"
|
|
|
|
htmlFor="register-verify-password"
|
|
|
|
>
|
|
|
|
{i18n.t("verify_password")}
|
|
|
|
</label>
|
|
|
|
<div className="col-sm-10">
|
|
|
|
<input
|
|
|
|
type="password"
|
|
|
|
id="register-verify-password"
|
2023-01-04 16:56:24 +00:00
|
|
|
value={this.state.form.password_verify}
|
2022-11-09 19:53:07 +00:00
|
|
|
autoComplete="new-password"
|
|
|
|
onInput={linkEvent(this, this.handleRegisterPasswordVerifyChange)}
|
|
|
|
maxLength={60}
|
|
|
|
className="form-control"
|
|
|
|
required
|
|
|
|
/>
|
2021-09-19 20:31:17 +00:00
|
|
|
</div>
|
2022-11-09 19:53:07 +00:00
|
|
|
</div>
|
2021-09-19 20:31:17 +00:00
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
{siteView.local_site.registration_mode ==
|
|
|
|
RegistrationMode.RequireApplication && (
|
2022-11-09 19:53:07 +00:00
|
|
|
<>
|
|
|
|
<div className="form-group row">
|
|
|
|
<div className="offset-sm-2 col-sm-10">
|
|
|
|
<div className="mt-2 alert alert-warning" role="alert">
|
|
|
|
<Icon icon="alert-triangle" classes="icon-inline mr-2" />
|
|
|
|
{i18n.t("fill_out_application")}
|
2021-12-30 15:26:45 +00:00
|
|
|
</div>
|
2023-01-04 16:56:24 +00:00
|
|
|
{siteView.local_site.application_question && (
|
|
|
|
<div
|
|
|
|
className="md-div"
|
|
|
|
dangerouslySetInnerHTML={mdToHtml(
|
|
|
|
siteView.local_site.application_question
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
)}
|
2022-11-09 19:53:07 +00:00
|
|
|
</div>
|
2021-12-30 15:26:45 +00:00
|
|
|
</div>
|
|
|
|
|
2022-11-09 19:53:07 +00:00
|
|
|
<div className="form-group row">
|
|
|
|
<label
|
|
|
|
className="col-sm-2 col-form-label"
|
|
|
|
htmlFor="application_answer"
|
|
|
|
>
|
|
|
|
{i18n.t("answer")}
|
|
|
|
</label>
|
|
|
|
<div className="col-sm-10">
|
|
|
|
<MarkdownTextArea
|
|
|
|
onContentChange={this.handleAnswerChange}
|
|
|
|
hideNavigationWarnings
|
|
|
|
allLanguages={[]}
|
2022-12-19 15:57:29 +00:00
|
|
|
siteLanguages={[]}
|
2022-11-09 19:53:07 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
{this.state.captcha && (
|
2022-09-22 15:03:35 +00:00
|
|
|
<div className="form-group row">
|
2022-11-09 19:53:07 +00:00
|
|
|
<label className="col-sm-2" htmlFor="register-captcha">
|
|
|
|
<span className="mr-2">{i18n.t("enter_code")}</span>
|
|
|
|
<button
|
|
|
|
type="button"
|
|
|
|
className="btn btn-secondary"
|
|
|
|
onClick={linkEvent(this, this.handleRegenCaptcha)}
|
|
|
|
aria-label={i18n.t("captcha")}
|
|
|
|
>
|
|
|
|
<Icon icon="refresh-cw" classes="icon-refresh-cw" />
|
|
|
|
</button>
|
2021-09-19 20:31:17 +00:00
|
|
|
</label>
|
2022-11-09 19:53:07 +00:00
|
|
|
{this.showCaptcha()}
|
|
|
|
<div className="col-sm-6">
|
2021-09-19 20:31:17 +00:00
|
|
|
<input
|
2022-11-09 19:53:07 +00:00
|
|
|
type="text"
|
|
|
|
className="form-control"
|
|
|
|
id="register-captcha"
|
2023-01-04 16:56:24 +00:00
|
|
|
value={this.state.form.captcha_answer}
|
2021-09-19 20:31:17 +00:00
|
|
|
onInput={linkEvent(
|
|
|
|
this,
|
2022-11-09 19:53:07 +00:00
|
|
|
this.handleRegisterCaptchaAnswerChange
|
2021-09-19 20:31:17 +00:00
|
|
|
)}
|
|
|
|
required
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-11-09 19:53:07 +00:00
|
|
|
)}
|
|
|
|
{siteView.local_site.enable_nsfw && (
|
|
|
|
<div className="form-group row">
|
|
|
|
<div className="col-sm-10">
|
|
|
|
<div className="form-check">
|
|
|
|
<input
|
|
|
|
className="form-check-input"
|
|
|
|
id="register-show-nsfw"
|
|
|
|
type="checkbox"
|
2023-01-04 16:56:24 +00:00
|
|
|
checked={this.state.form.show_nsfw}
|
2022-11-09 19:53:07 +00:00
|
|
|
onChange={linkEvent(this, this.handleRegisterShowNsfwChange)}
|
|
|
|
/>
|
2022-06-21 21:42:29 +00:00
|
|
|
<label
|
2022-11-09 19:53:07 +00:00
|
|
|
className="form-check-label"
|
|
|
|
htmlFor="register-show-nsfw"
|
2022-06-21 21:42:29 +00:00
|
|
|
>
|
2022-11-09 19:53:07 +00:00
|
|
|
{i18n.t("show_nsfw")}
|
2022-06-21 21:42:29 +00:00
|
|
|
</label>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-09-19 20:31:17 +00:00
|
|
|
</div>
|
2022-11-09 19:53:07 +00:00
|
|
|
)}
|
|
|
|
<input
|
|
|
|
tabIndex={-1}
|
|
|
|
autoComplete="false"
|
|
|
|
name="a_password"
|
|
|
|
type="text"
|
|
|
|
className="form-control honeypot"
|
|
|
|
id="register-honey"
|
2023-01-04 16:56:24 +00:00
|
|
|
value={this.state.form.honeypot}
|
2022-11-09 19:53:07 +00:00
|
|
|
onInput={linkEvent(this, this.handleHoneyPotChange)}
|
|
|
|
/>
|
|
|
|
<div className="form-group row">
|
|
|
|
<div className="col-sm-10">
|
|
|
|
<button type="submit" className="btn btn-secondary">
|
|
|
|
{this.state.registerLoading ? (
|
|
|
|
<Spinner />
|
|
|
|
) : (
|
|
|
|
this.titleName(siteView)
|
|
|
|
)}
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
);
|
2021-09-19 20:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
showCaptcha() {
|
2023-01-04 16:56:24 +00:00
|
|
|
let captchaRes = this.state.captcha?.ok;
|
|
|
|
return captchaRes ? (
|
|
|
|
<div className="col-sm-4">
|
|
|
|
<>
|
|
|
|
<img
|
|
|
|
className="rounded-top img-fluid"
|
|
|
|
src={this.captchaPngSrc(captchaRes)}
|
|
|
|
style="border-bottom-right-radius: 0; border-bottom-left-radius: 0;"
|
|
|
|
alt={i18n.t("captcha")}
|
|
|
|
/>
|
|
|
|
{captchaRes.wav && (
|
|
|
|
<button
|
|
|
|
className="rounded-bottom btn btn-sm btn-secondary btn-block"
|
|
|
|
style="border-top-right-radius: 0; border-top-left-radius: 0;"
|
|
|
|
title={i18n.t("play_captcha_audio")}
|
|
|
|
onClick={linkEvent(this, this.handleCaptchaPlay)}
|
|
|
|
type="button"
|
|
|
|
disabled={this.state.captchaPlaying}
|
|
|
|
>
|
|
|
|
<Icon icon="play" classes="icon-play" />
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
</div>
|
|
|
|
) : (
|
|
|
|
<></>
|
|
|
|
);
|
2021-09-19 20:31:17 +00:00
|
|
|
}
|
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
get passwordStrength(): string | undefined {
|
|
|
|
let password = this.state.form.password;
|
|
|
|
return password
|
|
|
|
? passwordStrength(password, passwordStrengthOptions).value
|
|
|
|
: undefined;
|
2021-09-19 20:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
get passwordColorClass(): string {
|
|
|
|
let strength = this.passwordStrength;
|
|
|
|
|
2023-01-04 16:56:24 +00:00
|
|
|
if (strength && ["weak", "medium"].includes(strength)) {
|
2021-09-19 20:31:17 +00:00
|
|
|
return "text-warning";
|
|
|
|
} else if (strength == "strong") {
|
|
|
|
return "text-success";
|
|
|
|
} else {
|
|
|
|
return "text-danger";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleRegisterSubmit(i: Signup, event: any) {
|
|
|
|
event.preventDefault();
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ registerLoading: true });
|
2023-01-04 16:56:24 +00:00
|
|
|
let cForm = i.state.form;
|
|
|
|
if (cForm.username && cForm.password && cForm.password_verify) {
|
|
|
|
let form: Register = {
|
|
|
|
username: cForm.username,
|
|
|
|
password: cForm.password,
|
|
|
|
password_verify: cForm.password_verify,
|
|
|
|
email: cForm.email,
|
|
|
|
show_nsfw: cForm.show_nsfw,
|
|
|
|
captcha_uuid: cForm.captcha_uuid,
|
|
|
|
captcha_answer: cForm.captcha_answer,
|
|
|
|
honeypot: cForm.honeypot,
|
|
|
|
answer: cForm.answer,
|
|
|
|
};
|
|
|
|
WebSocketService.Instance.send(wsClient.register(form));
|
|
|
|
}
|
2021-09-19 20:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleRegisterUsernameChange(i: Signup, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.state.form.username = event.target.value;
|
2021-09-19 20:31:17 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleRegisterEmailChange(i: Signup, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.state.form.email = event.target.value;
|
|
|
|
if (i.state.form.email == "") {
|
|
|
|
i.state.form.email = undefined;
|
2021-09-19 20:31:17 +00:00
|
|
|
}
|
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleRegisterPasswordChange(i: Signup, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.state.form.password = event.target.value;
|
2021-09-19 20:31:17 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleRegisterPasswordVerifyChange(i: Signup, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.state.form.password_verify = event.target.value;
|
2021-09-19 20:31:17 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleRegisterShowNsfwChange(i: Signup, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.state.form.show_nsfw = event.target.checked;
|
2021-09-19 20:31:17 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
|
|
|
handleRegisterCaptchaAnswerChange(i: Signup, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.state.form.captcha_answer = event.target.value;
|
2021-09-19 20:31:17 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2021-12-30 15:26:45 +00:00
|
|
|
handleAnswerChange(val: string) {
|
2023-01-04 16:56:24 +00:00
|
|
|
this.setState(s => ((s.form.answer = val), s));
|
2021-12-30 15:26:45 +00:00
|
|
|
}
|
|
|
|
|
2021-10-01 14:19:47 +00:00
|
|
|
handleHoneyPotChange(i: Signup, event: any) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.state.form.honeypot = event.target.value;
|
2021-10-01 14:19:47 +00:00
|
|
|
i.setState(i.state);
|
|
|
|
}
|
|
|
|
|
2021-09-19 20:31:17 +00:00
|
|
|
handleRegenCaptcha(i: Signup) {
|
2023-01-04 16:56:24 +00:00
|
|
|
i.audio = undefined;
|
2022-09-22 15:03:35 +00:00
|
|
|
i.setState({ captchaPlaying: false });
|
2021-09-19 20:31:17 +00:00
|
|
|
WebSocketService.Instance.send(wsClient.getCaptcha());
|
|
|
|
}
|
|
|
|
|
|
|
|
handleCaptchaPlay(i: Signup) {
|
|
|
|
// This was a bad bug, it should only build the new audio on a new file.
|
|
|
|
// Replays would stop prematurely if this was rebuilt every time.
|
2023-01-04 16:56:24 +00:00
|
|
|
let captchaRes = i.state.captcha?.ok;
|
|
|
|
if (captchaRes) {
|
|
|
|
if (!i.audio) {
|
|
|
|
let base64 = `data:audio/wav;base64,${captchaRes.wav}`;
|
|
|
|
i.audio = new Audio(base64);
|
|
|
|
i.audio.play();
|
|
|
|
|
|
|
|
i.setState({ captchaPlaying: true });
|
|
|
|
|
|
|
|
i.audio.addEventListener("ended", () => {
|
|
|
|
if (i.audio) {
|
|
|
|
i.audio.currentTime = 0;
|
|
|
|
i.setState({ captchaPlaying: false });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2021-09-19 20:31:17 +00:00
|
|
|
}
|
|
|
|
|
2022-06-21 21:42:29 +00:00
|
|
|
captchaPngSrc(captcha: CaptchaResponse) {
|
|
|
|
return `data:image/png;base64,${captcha.png}`;
|
2021-09-19 20:31:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parseMessage(msg: any) {
|
|
|
|
let op = wsUserOp(msg);
|
|
|
|
console.log(msg);
|
|
|
|
if (msg.error) {
|
|
|
|
toast(i18n.t(msg.error), "danger");
|
2023-01-04 16:56:24 +00:00
|
|
|
this.setState(s => ((s.form.captcha_answer = undefined), s));
|
2021-09-19 20:31:17 +00:00
|
|
|
// Refetch another captcha
|
2021-11-22 20:04:20 +00:00
|
|
|
// WebSocketService.Instance.send(wsClient.getCaptcha());
|
2021-09-19 20:31:17 +00:00
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (op == UserOperation.Register) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<LoginResponse>(msg);
|
2021-12-30 15:26:45 +00:00
|
|
|
// Only log them in if a jwt was set
|
2023-01-04 16:56:24 +00:00
|
|
|
if (data.jwt) {
|
2021-12-30 15:26:45 +00:00
|
|
|
UserService.Instance.login(data);
|
|
|
|
this.props.history.push("/communities");
|
2022-11-09 19:53:07 +00:00
|
|
|
location.reload();
|
2021-12-30 15:26:45 +00:00
|
|
|
} else {
|
|
|
|
if (data.verify_email_sent) {
|
|
|
|
toast(i18n.t("verify_email_sent"));
|
|
|
|
}
|
|
|
|
if (data.registration_created) {
|
|
|
|
toast(i18n.t("registration_application_sent"));
|
|
|
|
}
|
|
|
|
this.props.history.push("/");
|
|
|
|
}
|
2021-09-19 20:31:17 +00:00
|
|
|
} else if (op == UserOperation.GetCaptcha) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<GetCaptchaResponse>(msg);
|
|
|
|
if (data.ok) {
|
|
|
|
this.setState({ captcha: data });
|
|
|
|
this.setState(s => ((s.form.captcha_uuid = data.ok?.uuid), s));
|
|
|
|
}
|
2021-09-19 20:31:17 +00:00
|
|
|
} else if (op == UserOperation.PasswordReset) {
|
|
|
|
toast(i18n.t("reset_password_mail_sent"));
|
|
|
|
} else if (op == UserOperation.GetSite) {
|
2023-01-04 16:56:24 +00:00
|
|
|
let data = wsJsonToRes<GetSiteResponse>(msg);
|
2022-09-22 15:03:35 +00:00
|
|
|
this.setState({ siteRes: data });
|
2021-09-19 20:31:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|