Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Login basic auth ui #218

Merged
merged 8 commits into from
Jul 26, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions waartaa/client/app/constants/actionTypes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export const AUTHENTICATION_ERROR = 'AUTHENTICATION_ERROR';
export const AUTHORIZATION_ERROR = 'AUTHORIZATION_ERROR';
export const LOGOUT = 'LOGOUT';
export const LOGGEDIN = 'loggedin';
export const CONNECTED = 'connected';
70 changes: 70 additions & 0 deletions waartaa/client/app/containers/forms/LoginForm.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React, { Component, PropTypes } from 'react';
import { reduxForm } from 'redux-form';
import TextField from 'material-ui/TextField';
import Paper from 'material-ui/Paper'
import RaisedButton from 'material-ui/RaisedButton';

export const fields = [ 'username', 'password' ]

const style = {
height: 300,
width: 400,
padding: 20,
textAlign: "center"
}


const submit = (values, dispatch) => {
console.log(values);
dispatch({
type: 'login',
data: values,
remote: true
});
};

class LoginForm extends Component {
render() {
const {
fields: { username, password },
handleSubmit,
submitting
} = this.props
return (
<div>
<Paper style={style} zDepth={1} rounded={false}>
<form onSubmit={handleSubmit(submit)}>
<TextField
floatingLabelText="Username"
floatingLabelFixed={false}
fullWidth={true}
{...username}
/>
<br />
<TextField
floatingLabelText="Password"
floatingLabelFixed={false}
type="password"
fullWidth={true}
{...password}
/>
<br />
<RaisedButton label="Login" type="submit" primary={true} />
</form>
</Paper>
</div>
)
}
}

LoginForm.propTypes = {
handleSubmit: PropTypes.func.isRequired,
submitting: PropTypes.bool.isRequired
}

LoginForm = reduxForm({
form: 'simple',
fields
})(LoginForm);

export default LoginForm;
12 changes: 7 additions & 5 deletions waartaa/client/app/containers/login/LoginController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@ import ActionAndroid from 'material-ui/svg-icons/action/android';
import RaisedButton from 'material-ui/RaisedButton';

import userManager from '../../helpers/oidcHelpers.jsx';
import LoginForm from '../forms/LoginForm';

export default class LoginController extends Component {
onFASLoginButtonClick = (event) => {
event.preventDefault();
userManager.signinRedirect();
};

handleSubmit = (event) => {
event.preventDefault();
console.log('form submitted')
};

render() {
return (
<div>
<RaisedButton
label="Login with FAS"
icon={<ActionAndroid/>}
onMouseUp={this.onFASLoginButtonClick}
/>
<LoginForm handleSubmit={this.handleSubmit} submitting={false} />
</div>
);
}
Expand Down
4 changes: 3 additions & 1 deletion waartaa/client/app/middlewares/sockjs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ export default function createSockjsMiddleware(sock) {
return ({ dispatch }) => {
// Wire sockjs to dispatch actions sent by the server.
sock.onmessage = (e) => {
dispatch(JSON.parse(e.data))
console.log('Message received');
console.log(e.data);
dispatch(JSON.parse(e.data));
}

return next => action => {
Expand Down
18 changes: 18 additions & 0 deletions waartaa/client/app/reducers/authed.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as types from '../constants/actionTypes';

const initialState = {
user: null
}

var authed = (state = initialState, action) => {
switch (action.type) {
case types.LOGGEDIN:
return Object.assign({}, state, {
user: action.data.user
});
default:
return state
}
}

export default authed;
18 changes: 18 additions & 0 deletions waartaa/client/app/reducers/connection.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as types from '../constants/actionTypes';

const initialState = {
connected: false
}

var connection = (state = initialState, action) => {
switch (action.type) {
case types.CONNECTED:
return Object.assign({}, state, {
connected: true
});
default:
return state
}
}

export default connection;
8 changes: 7 additions & 1 deletion waartaa/client/app/reducers/index.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { combineReducers } from 'redux';
import { routerReducer as routing } from 'react-router-redux';
import { reducer as reduxReducer } from 'redux-oidc';
import { reducer as formReducer } from 'redux-form';
import authed from './authed';
import connection from './connection';

const rootReducer = combineReducers({
oidc: reduxReducer,
routing: routing
routing: routing,
form: formReducer,
authed: authed,
connection: connection
});

export default rootReducer
10 changes: 3 additions & 7 deletions waartaa/client/app/stores/configureStore.dev.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import oidcMiddleware from '../middleware/middleware.jsx';
import DevTools from '../containers/DevTools.jsx';
import SockJS from 'sockjs-client';
import createSockjsMiddleware from '../middlewares/sockjs';
import * as types from '../constants/actionTypes';

var sock = new SockJS('/sockjs');
var sockjsMiddleware = createSockjsMiddleware(sock);
Expand Down Expand Up @@ -46,13 +47,8 @@ export default function configureStore(initialState) {

sock.onopen = () => {
store.dispatch({
type: 'login',
data: {
username: 'rtnpro',
password: 'password'
},
remote: true
})
type: types.CONNECTED
});
}

return store;
Expand Down
1 change: 1 addition & 0 deletions waartaa/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"react-tap-event-plugin": "^1.0.0",
"react-title-component": "^1.0.1",
"redux": "^3.5.2",
"redux-form": "^5.3.1",
"redux-oidc": "^2.0.0-beta.2",
"sockjs-client": "^1.0.3",
"style-loader": "~0.13.1",
Expand Down
11 changes: 10 additions & 1 deletion waartaa/websocket/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,16 @@ def on_login(self, data):
)
if user:
self.user = user
response = {'type': 'loggedin', 'data': {'status': 'SUCCESS'}}
response = {'type': 'loggedin',
'data': {
'status': 'SUCCESS',
'user': {
'id': user.id,
'username': user.username,
'email': user.email
}
}
}
self.session.send(json.dumps(response))

@asyncio.coroutine
Expand Down