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 543fd56116
commit e42b0fb7aa
6 changed files with 17 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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