mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-21 17:26:29 -05:00
Email sign in (#13)
polished via-email component used state to track email and password. explicitly did not put email and password in value of the appropriate input fields because that is not necessary nor do we want to write the clear text password into the dom Signed-off-by: Philip Molares <philip.molares@udo.edu> (cherry picked from commit c5f5956b8d8bb02553f85443f8b04acbf0c31f2b)
This commit is contained in:
parent
93ce059577
commit
41f969fda6
7 changed files with 71 additions and 24 deletions
|
@ -10,7 +10,7 @@
|
||||||
"google": false,
|
"google": false,
|
||||||
"saml": false,
|
"saml": false,
|
||||||
"oauth2": false,
|
"oauth2": false,
|
||||||
"email": false
|
"email": true
|
||||||
},
|
},
|
||||||
"specialLinks": {
|
"specialLinks": {
|
||||||
"privacy": "test",
|
"privacy": "test",
|
||||||
|
|
|
@ -118,5 +118,9 @@
|
||||||
"poweredBy": "Betrieben mit <0></0>",
|
"poweredBy": "Betrieben mit <0></0>",
|
||||||
"Help us translating": "Hilf uns beim Übersetzen",
|
"Help us translating": "Hilf uns beim Übersetzen",
|
||||||
"Join the community": "Tritt der Community bei",
|
"Join the community": "Tritt der Community bei",
|
||||||
"imprint": "Impressum"
|
"imprint": "Impressum",
|
||||||
|
"errorEmailLogin": "E-Mail oder Passwort nicht korrekt",
|
||||||
|
"errorLdapLogin": "Benutzername oder Passwort nicht korrekt",
|
||||||
|
"email": "E-Mail",
|
||||||
|
"password": "Passwort"
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,5 +118,9 @@
|
||||||
"poweredBy": "Powered by <0></0>",
|
"poweredBy": "Powered by <0></0>",
|
||||||
"Help us translating": "Help us translating",
|
"Help us translating": "Help us translating",
|
||||||
"Join the community": "Join the community",
|
"Join the community": "Join the community",
|
||||||
"imprint": "Imprint"
|
"imprint": "Imprint",
|
||||||
|
"errorEmailLogin": "Invalid email or password",
|
||||||
|
"errorLdapLogin": "Invalid username or password",
|
||||||
|
"email": "Email",
|
||||||
|
"password": "Password"
|
||||||
}
|
}
|
||||||
|
|
10
public/me
10
public/me
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"id": "mockUser",
|
"id": "mockUser",
|
||||||
"photo": "https://robohash.org/testy.png",
|
"photo": "https://robohash.org/testy.png",
|
||||||
"name": "Test",
|
"name": "Test",
|
||||||
"status": "ok"
|
"status": "ok"
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,5 +17,11 @@ export const postEmailLogin = async (email: string, password: string) => {
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
})
|
})
|
||||||
});
|
}).then(response => {
|
||||||
|
if (response.status !== 200) {
|
||||||
|
return Promise.reject("Response code not 200");
|
||||||
|
} else {
|
||||||
|
return response.json();
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,9 @@ import {getMe} from "../../api/user";
|
||||||
import {setUser} from "../../redux/user/actions";
|
import {setUser} from "../../redux/user/actions";
|
||||||
import {LoginStatus, UserState} from "../../redux/user/types";
|
import {LoginStatus, UserState} from "../../redux/user/types";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
|
import {Dispatch} from "redux";
|
||||||
|
|
||||||
const InitializeUserStateFromApi: React.FC = () => {
|
export const getAndSetUser = (dispatch: Dispatch<any>) => {
|
||||||
const dispatch = useDispatch();
|
|
||||||
getMe()
|
getMe()
|
||||||
.then((me) => {
|
.then((me) => {
|
||||||
if (me.status === 200) {
|
if (me.status === 200) {
|
||||||
|
@ -23,6 +23,11 @@ const InitializeUserStateFromApi: React.FC = () => {
|
||||||
photo: user.photo,
|
photo: user.photo,
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const InitializeUserStateFromApi: React.FC = () => {
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
getAndSetUser(dispatch);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,33 +1,61 @@
|
||||||
import {Trans, useTranslation} from "react-i18next";
|
import {Trans, useTranslation} from "react-i18next";
|
||||||
import {Button, Form} from "react-bootstrap";
|
import {Button, Form, Alert} from "react-bootstrap";
|
||||||
import React, { Fragment } from "react";
|
import React, {Fragment, useState} from "react";
|
||||||
|
import {postEmailLogin} from "../../../../../api/user";
|
||||||
import {useDispatch} from "react-redux";
|
import {useDispatch} from "react-redux";
|
||||||
import {setUser} from "../../../../../redux/user/actions";
|
import {getAndSetUser} from "../../../../initialize/initialize-user-state-from-api";
|
||||||
import {LoginStatus} from "../../../../../redux/user/types";
|
|
||||||
|
|
||||||
const ViaEMail: React.FC = () => {
|
const ViaEMail: React.FC = () => {
|
||||||
useTranslation();
|
const {t} = useTranslation();
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const login = () => {
|
const [email, setEmail] = useState("");
|
||||||
dispatch(setUser({photo: "https://robohash.org/testy.png", name: "Test", status: LoginStatus.ok}));
|
const [password, setPassword] = useState("");
|
||||||
|
const [error, setError] = useState(false);
|
||||||
|
const login = (event: any) => {
|
||||||
|
postEmailLogin(email, password)
|
||||||
|
.then(loginJson => {
|
||||||
|
console.log(loginJson)
|
||||||
|
getAndSetUser(dispatch);
|
||||||
|
}).catch(_reason => {
|
||||||
|
setError(true);
|
||||||
|
})
|
||||||
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fragment>
|
<Fragment>
|
||||||
<h5 className="center">
|
<h5 className="center">
|
||||||
<Trans i18nKey="signInVia" values={{service: "E-Mail"}}/>
|
<Trans i18nKey="signInVia" values={{service: "E-Mail"}}/>
|
||||||
</h5>
|
</h5>
|
||||||
<Form>
|
<Form onSubmit={login}>
|
||||||
<Form.Group controlId="formBasicEmail">
|
<Form.Group controlId="email">
|
||||||
<Form.Control type="email" size="sm" placeholder="E-Mail" />
|
<Form.Control
|
||||||
|
isInvalid={error}
|
||||||
|
type="email"
|
||||||
|
size="sm"
|
||||||
|
placeholder={t("email")}
|
||||||
|
onChange={(event) => setEmail(event.currentTarget.value)}
|
||||||
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
|
|
||||||
<Form.Group controlId="formBasicPassword">
|
<Form.Group controlId="password">
|
||||||
<Form.Control type="password" size="sm" placeholder="Password" />
|
<Form.Control
|
||||||
|
isInvalid={error}
|
||||||
|
type="password"
|
||||||
|
size="sm"
|
||||||
|
placeholder={t("password")}
|
||||||
|
onChange={(event) => setPassword(event.currentTarget.value)}
|
||||||
|
/>
|
||||||
</Form.Group>
|
</Form.Group>
|
||||||
|
|
||||||
|
<Alert className="small" show={error} variant="danger">
|
||||||
|
<Trans i18nKey="errorEmailLogin"/>
|
||||||
|
</Alert>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
type="submit"
|
||||||
size="sm"
|
size="sm"
|
||||||
variant="primary"
|
variant="primary"
|
||||||
onClick={login}
|
|
||||||
>
|
>
|
||||||
<Trans i18nKey="signIn"/>
|
<Trans i18nKey="signIn"/>
|
||||||
</Button>
|
</Button>
|
||||||
|
|
Loading…
Reference in a new issue