]> Untitled Git - lemmy-ui.git/blobdiff - src/shared/components/home/login.tsx
component classes v2
[lemmy-ui.git] / src / shared / components / home / login.tsx
index 3ddb4bc1d2c126126f142818757d0368c9379c5f..4ea69456d2a43bf176112886439411abeb28a56d 100644 (file)
@@ -49,7 +49,7 @@ export class Login extends Component<any, State> {
 
   render() {
     return (
-      <div className="container-lg">
+      <div className="login container-lg">
         <HtmlTags
           title={this.documentTitle}
           path={this.context.router.route.match.url}
@@ -66,7 +66,7 @@ export class Login extends Component<any, State> {
       <div>
         <form onSubmit={linkEvent(this, this.handleLoginSubmit)}>
           <h5>{i18n.t("login")}</h5>
-          <div className="form-group row">
+          <div className="mb-3 row">
             <label
               className="col-sm-2 col-form-label"
               htmlFor="login-email-or-username"
@@ -86,7 +86,7 @@ export class Login extends Component<any, State> {
               />
             </div>
           </div>
-          <div className="form-group row">
+          <div className="mb-3 row">
             <label className="col-sm-2 col-form-label" htmlFor="login-password">
               {i18n.t("password")}
             </label>
@@ -116,7 +116,7 @@ export class Login extends Component<any, State> {
             </div>
           </div>
           {this.state.showTotp && (
-            <div className="form-group row">
+            <div className="mb-3 row">
               <label
                 className="col-sm-6 col-form-label"
                 htmlFor="login-totp-token"
@@ -137,7 +137,7 @@ export class Login extends Component<any, State> {
               </div>
             </div>
           )}
-          <div className="form-group row">
+          <div className="mb-3 row">
             <div className="col-sm-10">
               <button type="submit" className="btn btn-secondary">
                 {this.state.loginRes.state == "loading" ? (
@@ -160,42 +160,38 @@ export class Login extends Component<any, State> {
     if (username_or_email && password) {
       i.setState({ loginRes: { state: "loading" } });
 
-      try {
-        const loginRes = await HttpService.client.login({
-          username_or_email,
-          password,
-          totp_2fa_token,
-        });
-        switch (loginRes.state) {
-          case "failed": {
-            if (loginRes.msg === "missing_totp_token") {
-              i.setState({ showTotp: true });
-              toast(i18n.t("enter_two_factor_code"), "info");
-            }
-
-            i.setState({ loginRes: { state: "empty" } });
-            break;
+      const loginRes = await HttpService.client.login({
+        username_or_email,
+        password,
+        totp_2fa_token,
+      });
+      switch (loginRes.state) {
+        case "failed": {
+          if (loginRes.msg === "missing_totp_token") {
+            i.setState({ showTotp: true });
+            toast(i18n.t("enter_two_factor_code"), "info");
           }
 
-          case "success": {
-            UserService.Instance.login(loginRes.data);
-            const site = await HttpService.client.getSite({
-              auth: myAuth(),
-            });
-
-            if (site.state === "success") {
-              UserService.Instance.myUserInfo = site.data.my_user;
-            }
+          i.setState({ loginRes: { state: "failed", msg: loginRes.msg } });
+          break;
+        }
 
-            i.props.history.action === "PUSH"
-              ? i.props.history.back()
-              : i.props.history.replace("/");
+        case "success": {
+          UserService.Instance.login(loginRes.data);
+          const site = await HttpService.client.getSite({
+            auth: myAuth(),
+          });
 
-            break;
+          if (site.state === "success") {
+            UserService.Instance.myUserInfo = site.data.my_user;
           }
+
+          i.props.history.action === "PUSH"
+            ? i.props.history.back()
+            : i.props.history.replace("/");
+
+          break;
         }
-      } catch (error) {
-        i.setState({ loginRes: { state: "failed", msg: error.message } });
       }
     }
   }