mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 06:55:47 +01:00
Bootstrapped login in UI
This commit is contained in:
@@ -6,22 +6,19 @@ import { withRouter } from "react-router-dom";
|
|||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
login: boolean
|
login: boolean
|
||||||
}
|
};
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { login } = this.props;
|
||||||
|
|
||||||
const { login} = this.props;
|
if (!login) {
|
||||||
|
|
||||||
if(login) {
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Login/>
|
<Login />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return (
|
return (
|
||||||
<div className="App">
|
<div className="App">
|
||||||
<Navigation />
|
<Navigation />
|
||||||
|
|||||||
@@ -1,24 +1,35 @@
|
|||||||
//@flow
|
//@flow
|
||||||
import React from 'react';
|
import React from "react";
|
||||||
import injectSheet from 'react-jss';
|
import injectSheet from "react-jss";
|
||||||
|
import { login } from "../modules/login";
|
||||||
|
import { connect } from "react-redux";
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
wrapper: {
|
wrapper: {
|
||||||
width: '100%',
|
width: "100%",
|
||||||
display: 'flex',
|
display: "flex",
|
||||||
height: '10em'
|
height: "10em"
|
||||||
},
|
},
|
||||||
login: {
|
login: {
|
||||||
margin: 'auto',
|
margin: "auto",
|
||||||
textAlign: 'center'
|
textAlign: "center"
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
type Props = {
|
|
||||||
classes: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Login extends React.Component<Props> {
|
class Login extends React.Component<Props> {
|
||||||
|
state = {};
|
||||||
|
handleUsernameChange(event) {
|
||||||
|
this.setState({ username: event.target.value });
|
||||||
|
}
|
||||||
|
|
||||||
|
handlePasswordChange(event) {
|
||||||
|
this.setState({ password: event.target.value });
|
||||||
|
}
|
||||||
|
|
||||||
|
handleSubmit(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
this.props.login(this.state.username, this.state.password);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { classes } = this.props;
|
const { classes } = this.props;
|
||||||
@@ -26,11 +37,44 @@ class Login extends React.Component<Props> {
|
|||||||
<div className={classes.wrapper}>
|
<div className={classes.wrapper}>
|
||||||
<div className={classes.login}>
|
<div className={classes.login}>
|
||||||
You need to log in! ...
|
You need to log in! ...
|
||||||
|
<form onSubmit={this.handleSubmit.bind(this)}>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
defaultValue="Username"
|
||||||
|
onChange={this.handleUsernameChange.bind(this)}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
type="password"
|
||||||
|
defaultValue="Password"
|
||||||
|
onChange={this.handlePasswordChange.bind(this)}
|
||||||
|
/>
|
||||||
|
<input type="submit" value="Login" />
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default injectSheet(styles)(Login);
|
const mapStateToProps = state => {
|
||||||
|
return {};
|
||||||
|
};
|
||||||
|
|
||||||
|
const mapDispatchToProps = dispatch => {
|
||||||
|
return {
|
||||||
|
login: (username: string, password: string) =>
|
||||||
|
dispatch(login(username, password))
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const StyledLogin = injectSheet(styles)(
|
||||||
|
connect(
|
||||||
|
mapStateToProps,
|
||||||
|
mapDispatchToProps
|
||||||
|
)(Login)
|
||||||
|
);
|
||||||
|
export default StyledLogin;
|
||||||
|
// export default connect(
|
||||||
|
// mapStateToProps,
|
||||||
|
// mapDispatchToProps
|
||||||
|
// )(StyledLogin);
|
||||||
|
|||||||
@@ -6,16 +6,19 @@ import { routerReducer, routerMiddleware } from "react-router-redux";
|
|||||||
|
|
||||||
import repositories from "./repositories/modules/repositories";
|
import repositories from "./repositories/modules/repositories";
|
||||||
import users from "./users/modules/users";
|
import users from "./users/modules/users";
|
||||||
|
import login from "./modules/login";
|
||||||
|
|
||||||
import type {BrowserHistory} from "history/createBrowserHistory";
|
import type { BrowserHistory } from "history/createBrowserHistory";
|
||||||
|
|
||||||
function createReduxStore(history: BrowserHistory) {
|
function createReduxStore(history: BrowserHistory) {
|
||||||
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
|
const composeEnhancers =
|
||||||
|
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
|
||||||
|
|
||||||
const reducer = combineReducers({
|
const reducer = combineReducers({
|
||||||
router: routerReducer,
|
router: routerReducer,
|
||||||
repositories,
|
repositories,
|
||||||
users
|
users,
|
||||||
|
login
|
||||||
});
|
});
|
||||||
|
|
||||||
return createStore(
|
return createStore(
|
||||||
|
|||||||
71
scm-ui/src/modules/login.js
Normal file
71
scm-ui/src/modules/login.js
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
//@flow
|
||||||
|
|
||||||
|
const LOGIN = "scm/auth/login";
|
||||||
|
const LOGIN_REQUEST = "scm/auth/login_request";
|
||||||
|
const LOGIN_SUCCESSFUL = "scm/auth/login_successful";
|
||||||
|
const LOGIN_FAILED = "scm/auth/login_failed";
|
||||||
|
|
||||||
|
export function loginRequest() {
|
||||||
|
return {
|
||||||
|
type: LOGIN_REQUEST
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function login(username: string, password: string) {
|
||||||
|
var login_data = {
|
||||||
|
cookie: true,
|
||||||
|
grant_type: "password",
|
||||||
|
password: username,
|
||||||
|
username: password
|
||||||
|
};
|
||||||
|
console.log(login_data);
|
||||||
|
return function(dispatch) {
|
||||||
|
dispatch(loginRequest());
|
||||||
|
return fetch("/api/rest/v2/auth/access_token", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json; charset=utf-8"
|
||||||
|
},
|
||||||
|
body: JSON.stringify(login_data)
|
||||||
|
}).then(
|
||||||
|
response => {
|
||||||
|
if (response.ok) {
|
||||||
|
dispatch(loginSuccessful());
|
||||||
|
}
|
||||||
|
},
|
||||||
|
error => console.log("error logging in: " + error)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export function loginSuccessful() {
|
||||||
|
return {
|
||||||
|
type: LOGIN_SUCCESSFUL
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function reducer(state = {}, action = {}) {
|
||||||
|
switch (action.type) {
|
||||||
|
case LOGIN:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
login: false,
|
||||||
|
error: null
|
||||||
|
};
|
||||||
|
case LOGIN_SUCCESSFUL:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
login: true,
|
||||||
|
error: null
|
||||||
|
};
|
||||||
|
case LOGIN_FAILED:
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
login: false,
|
||||||
|
error: action.payload
|
||||||
|
};
|
||||||
|
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user