mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-29 16:56:57 +00:00
Adding verify email route.
This commit is contained in:
parent
421b0cfa6f
commit
7313ef0f06
|
@ -72,7 +72,7 @@
|
|||
"husky": "^7.0.4",
|
||||
"import-sort-style-module": "^6.0.0",
|
||||
"iso-639-1": "^2.1.10",
|
||||
"lemmy-js-client": "0.15.0-rc.1",
|
||||
"lemmy-js-client": "0.15.0-rc.3",
|
||||
"lint-staged": "^12.1.2",
|
||||
"mini-css-extract-plugin": "^2.4.5",
|
||||
"node-fetch": "^2.6.1",
|
||||
|
|
|
@ -91,7 +91,11 @@ server.get("/*", async (req, res) => {
|
|||
if (routeData[0] && routeData[0].error) {
|
||||
let errCode = routeData[0].error;
|
||||
console.error(errCode);
|
||||
return res.redirect(`/404?err=${errCode}`);
|
||||
if (errCode == "instance_is_private") {
|
||||
return res.redirect(`/login`);
|
||||
} else {
|
||||
return res.redirect(`/404?err=${errCode}`);
|
||||
}
|
||||
}
|
||||
|
||||
let isoData: IsoData = {
|
||||
|
|
|
@ -239,6 +239,7 @@ export class Home extends Component<any, HomeState> {
|
|||
sort: SortType.Hot,
|
||||
limit: 6,
|
||||
};
|
||||
setOptionalAuth(trendingCommunitiesForm, req.auth);
|
||||
promises.push(req.client.listCommunities(trendingCommunitiesForm));
|
||||
|
||||
return promises;
|
||||
|
|
98
src/shared/components/person/verify-email.tsx
Normal file
98
src/shared/components/person/verify-email.tsx
Normal file
|
@ -0,0 +1,98 @@
|
|||
import { Component } from "inferno";
|
||||
import {
|
||||
LoginResponse,
|
||||
SiteView,
|
||||
UserOperation,
|
||||
VerifyEmail as VerifyEmailForm,
|
||||
} from "lemmy-js-client";
|
||||
import { Subscription } from "rxjs";
|
||||
import { i18n } from "../../i18next";
|
||||
import { UserService, WebSocketService } from "../../services";
|
||||
import {
|
||||
isBrowser,
|
||||
setIsoData,
|
||||
toast,
|
||||
wsClient,
|
||||
wsJsonToRes,
|
||||
wsSubscribe,
|
||||
wsUserOp,
|
||||
} from "../../utils";
|
||||
import { HtmlTags } from "../common/html-tags";
|
||||
|
||||
interface State {
|
||||
verifyEmailForm: VerifyEmailForm;
|
||||
site_view: SiteView;
|
||||
}
|
||||
|
||||
export class VerifyEmail extends Component<any, State> {
|
||||
private isoData = setIsoData(this.context);
|
||||
private subscription: Subscription;
|
||||
|
||||
emptyState: State = {
|
||||
verifyEmailForm: {
|
||||
token: this.props.match.params.token,
|
||||
},
|
||||
site_view: this.isoData.site_res.site_view,
|
||||
};
|
||||
|
||||
constructor(props: any, context: any) {
|
||||
super(props, context);
|
||||
|
||||
this.state = this.emptyState;
|
||||
|
||||
this.parseMessage = this.parseMessage.bind(this);
|
||||
this.subscription = wsSubscribe(this.parseMessage);
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
WebSocketService.Instance.send(
|
||||
wsClient.verifyEmail(this.state.verifyEmailForm)
|
||||
);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
if (isBrowser()) {
|
||||
this.subscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
get documentTitle(): string {
|
||||
return `${i18n.t("verify_email")} - ${this.state.site_view.site.name}`;
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div class="container">
|
||||
<HtmlTags
|
||||
title={this.documentTitle}
|
||||
path={this.context.router.route.match.url}
|
||||
/>
|
||||
<div class="row">
|
||||
<div class="col-12 col-lg-6 offset-lg-3 mb-4">
|
||||
<h5>{i18n.t("verify_email")}</h5>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
parseMessage(msg: any) {
|
||||
let op = wsUserOp(msg);
|
||||
console.log(msg);
|
||||
if (msg.error) {
|
||||
toast(i18n.t(msg.error), "danger");
|
||||
this.setState(this.state);
|
||||
this.props.history.push("/");
|
||||
return;
|
||||
} else if (op == UserOperation.VerifyEmail) {
|
||||
let data = wsJsonToRes<LoginResponse>(msg).data;
|
||||
if (data.jwt) {
|
||||
toast(i18n.t("email_verified"));
|
||||
this.state = this.emptyState;
|
||||
this.setState(this.state);
|
||||
UserService.Instance.login(data);
|
||||
this.props.history.push("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,15 +6,16 @@ import { AdminSettings } from "./components/home/admin-settings";
|
|||
import { Home } from "./components/home/home";
|
||||
import { Instances } from "./components/home/instances";
|
||||
import { Login } from "./components/home/login";
|
||||
import { PasswordChange } from "./components/home/password-change";
|
||||
import { Setup } from "./components/home/setup";
|
||||
import { Signup } from "./components/home/signup";
|
||||
import { Modlog } from "./components/modlog";
|
||||
import { Inbox } from "./components/person/inbox";
|
||||
import { PasswordChange } from "./components/person/password-change";
|
||||
import { Profile } from "./components/person/profile";
|
||||
import { RegistrationApplications } from "./components/person/registration-applications";
|
||||
import { Reports } from "./components/person/reports";
|
||||
import { Settings } from "./components/person/settings";
|
||||
import { VerifyEmail } from "./components/person/verify-email";
|
||||
import { CreatePost } from "./components/post/create-post";
|
||||
import { Post } from "./components/post/post";
|
||||
import { CreatePrivateMessage } from "./components/private_message/create-private-message";
|
||||
|
@ -148,5 +149,9 @@ export const routes: IRoutePropsWithFetch[] = [
|
|||
path: `/password_change/:token`,
|
||||
component: PasswordChange,
|
||||
},
|
||||
{
|
||||
path: `/verify_email/:token`,
|
||||
component: VerifyEmail,
|
||||
},
|
||||
{ path: `/instances`, component: Instances },
|
||||
];
|
||||
|
|
|
@ -4997,10 +4997,10 @@ lcid@^1.0.0:
|
|||
dependencies:
|
||||
invert-kv "^1.0.0"
|
||||
|
||||
lemmy-js-client@0.15.0-rc.1:
|
||||
version "0.15.0-rc.1"
|
||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.15.0-rc.1.tgz#7f5f0f069c76c5377a2a8654ce3a10563f405e14"
|
||||
integrity sha512-Dgq7G2jGLURoswV40DfUNNvxQ/Dg8Jkz9jarwJuOMmBF9MfM/wD1nlaPtvMHlxePXtgDc8Y/Ig84k1OEF8Myqw==
|
||||
lemmy-js-client@0.15.0-rc.3:
|
||||
version "0.15.0-rc.3"
|
||||
resolved "https://registry.yarnpkg.com/lemmy-js-client/-/lemmy-js-client-0.15.0-rc.3.tgz#acc762981f2bbd4381857d12bf576b0d85451c4f"
|
||||
integrity sha512-Yk1Y32ILc2E/eTfnjtvZBoPGwPUqokPKlouOpng7cJohFMqZUWocy8Z3yK+tx81/l0Lss9RT4HaqsRmvmEmfJw==
|
||||
|
||||
levn@^0.4.1:
|
||||
version "0.4.1"
|
||||
|
|
Loading…
Reference in a new issue