Skip to content
This repository has been archived by the owner on Apr 1, 2020. It is now read-only.

Support for user registration in users page + little aesthetics #6

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Features:

- Login and register
- Change password and manage Git ssh keys
- List users, grant admin, delete user (admin only)
- List users, grant admin, delete user, register user (admin only)
- List and create new apps
- Scale app
- Destroy app
Expand Down
15 changes: 15 additions & 0 deletions actions/deis.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ export const listApps = () => (
client.get('/apps')
)

export const listUsers = () => (
client.get('/users')
)

export const login = (username, password) => (
client.post('/auth/login', { body: { username, password } }, {
mapResponse: (response, json, baseAction) => {
Expand Down Expand Up @@ -256,6 +260,17 @@ export const createApp = (appID) => (dispatch, getState) => (
})
)

export const createUser = (username, password, email) => (dispatch, getState) => (
client.post(`/auth/register`, {
body: { username, password, email },
}, {
action: { type: 'POST_USER' },
})(dispatch, getState).then(() => {
// refresh user list
dispatch(listUsers())
})
)

export const appOverview = (appID) => (
client.get(`/apps/${appID}`, {}, { action: { type: 'GET_APP_OVERVIEW' } })
)
Expand Down
62 changes: 61 additions & 1 deletion containers/Dash/Users/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,66 @@ import { connect } from 'react-redux'
import UserItem from './UserItem'
import { Table } from 'react-bootstrap'

class CreateUser extends React.Component {
constructor(props) {
super(props)

this.create = this.create.bind(this)
this.change = this.change.bind(this)
this.state = {
username: '',
password: '',
email: '',
}
}

change(type, field) {
const nextState = {}
nextState[type] = field.target.value
this.setState(nextState)
}

create() {
this.props.createUser(this.state.username, this.state.password, this.state.email)
this.setState({ username: '', password: '', email: '' })
}

render() {
return (
<div className="form-inline create-user-form">
<div className="form-group">
<input
value={this.state.username}
onChange={this.change.bind(this, 'username')}
className="form-control"
placeholder="username"
/>
<input type="password"
value={this.state.password}
onChange={this.change.bind(this, 'password')}
className="form-control"
placeholder="password"
/>
<input
value={this.state.email}
onChange={this.change.bind(this, 'email')}
className="form-control"
placeholder="email"
/>
</div>
<button className="btn btn-success" onClick={this.create}>Create user</button>
</div>
)
}
}

class Users extends React.Component {
constructor(props) {
super(props)
this.onDestroyUser = this.onDestroyUser.bind(this)
this.grantAdmin = this.grantAdmin.bind(this)
this.revokeAdmin = this.revokeAdmin.bind(this)
this.createUser = this.createUser.bind(this)
}
// TODO: also do this in willreceiveprops
componentWillMount() {
Expand All @@ -27,6 +81,11 @@ class Users extends React.Component {
dispatch(deis.delUser(username))
}

createUser(username, password, email) {
const { dispatch } = this.props
dispatch(deis.createUser(username, password, email))
}

grantAdmin(username) {
const { dispatch } = this.props
dispatch(deis.grantAdmin(username))
Expand All @@ -43,7 +102,7 @@ class Users extends React.Component {
if (!users) return <div></div>

// Sort by username
users.sort(function(a,b) {return (a.username > b.username) ? 1 : ((b.username > a.username) ? -1 : 0);} );
users.sort(function( a,b) {return (a.username > b.username) ? 1 : ((b.username > a.username) ? -1 : 0);} );

const userItems = users.map((user) => (
<UserItem
Expand Down Expand Up @@ -78,6 +137,7 @@ class Users extends React.Component {
{userItems}
</tbody>
</Table>
<CreateUser createUser={this.createUser} />
</div>
)
}
Expand Down
1 change: 1 addition & 0 deletions styles/_apps.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
clear: both;
}
.create-app-form {
padding-bottom: 20px;
button {
margin-left: 10px;
}
Expand Down
6 changes: 6 additions & 0 deletions styles/_users.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.create-user-form {
input {
margin-right: 10px;
}
margin-bottom: 20px;
}
1 change: 1 addition & 0 deletions styles/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
@import "auth";
@import "header";
@import "apps";
@import "users";
@import "apps_show";
@import "config";
@import "hpanel";
Expand Down