fixed many small problems, login now seems to work

This commit is contained in:
Daniel Schick 2024-03-19 11:22:30 +01:00
parent c7b0c26ee5
commit 5d3e484cce
6 changed files with 17 additions and 15 deletions

View File

@ -13,6 +13,7 @@
"react-router-dom": "^6.22.3",
"react-scripts": "^5.0.1",
"react-validation": "^3.0.7",
"html-react-parser": "^5.1.9",
"validator": "^13.11.0",
"web-vitals": "^2.1.4"
},

View File

@ -97,7 +97,7 @@ class App extends Component {
<div className="navbar-nav ml-auto">
<li className="nav-item">
<Link to={"/profile"} className="nav-link">
{currentUser.username}
{currentUser.user_name}
</Link>
</li>
<li className="nav-item">

View File

@ -1,21 +1,24 @@
import React, { Component } from 'react';
import UserService from '../services/user.service';
import parse from 'html-react-parser';
export default class Home extends Component {
constructor(props) {
super(props);
this.state = {
content: ""
content: "",
};
}
componentDidMount() {
UserService.getPublicContent().then(
response => {
var bodyHtml = /<body.*?>([\s\S]*)<\/body>/.exec(response.data)[1];
this.setState({
content: response.data
content: bodyHtml
});
},
error => {
this.setState({
@ -32,8 +35,10 @@ export default class Home extends Component {
return (
<div className="container">
<header className="jumbotron">
<h2>lala</h2>
<h3>{this.state.content}</h3>
<h2>Default home page</h2>
<div name="contentDiv">
{parse(this.state.content)}
</div>
</header>
</div>
);

View File

@ -59,7 +59,7 @@ class Login extends Component {
if (this.checkBtn.context._errors.length === 0) {
AuthService.login(this.state.username, this.state.password).then(
() => {
this.props.navigate('/profile');
this.props.router.navigate('/profile');
window.location.reload();
},
error => {

View File

@ -9,7 +9,7 @@ export default class Profile extends Component {
this.state = {
redirect: null,
userReady: false,
currentUser: {username: ""}
currentUser: {username: "", token: "", id: "", email: ""}
};
}
@ -31,7 +31,6 @@ export default class Profile extends Component {
const { currentUser } = this.state;
return (
<Component>
<div className="container">
<header className="jumbotron">
<h3>
@ -39,7 +38,7 @@ export default class Profile extends Component {
</h3>
</header>
<p>
<strong>Token:</strong>{ currentUser.accessToken.substring(0, 20) } { currentUser.accessToken.substr(currentUser.accessToken.length - 20) }
<strong>Token:</strong> { currentUser.token }
</p>
<p>
<strong>Id:</strong>{ currentUser.id }
@ -47,12 +46,8 @@ export default class Profile extends Component {
<p>
<strong>Email:</strong>{ currentUser.email }
</p>
<strong>Authorities:</strong>
<ul>
{currentUser.roles && currentUser.roles.map((role, index) => <li key={index}>{role}</li>)}
</ul>
</div>
</Component>
);
}

View File

@ -28,4 +28,5 @@ class UserService {
}
export default new UserService();
const userService = new UserService();
export default userService;