-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Login page for Add-On Manager (#131)
- Loading branch information
1 parent
d2682c2
commit b284e1d
Showing
6 changed files
with
190 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import React, { Component } from 'react'; | ||
import { hashHistory } from 'react-router'; | ||
import axios from 'axios'; | ||
import { Form, Button, FormControl, FormGroup, Col, ControlLabel, Checkbox, Nav, Modal } from 'react-bootstrap'; | ||
class Login extends Component { | ||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
username: '', | ||
password: '', | ||
show: false | ||
} | ||
this.handleLogin = this.handleLogin.bind(this); | ||
this.handleShow = this.handleShow.bind(this); | ||
this.handleClose = this.handleClose.bind(this); | ||
} | ||
handleClose() { | ||
this.setState({ show: false }); | ||
} | ||
handleShow() { | ||
this.setState({ show: true }); | ||
} | ||
|
||
handleLogin(event) { | ||
event.preventDefault(); | ||
const { username, password } = this.state; | ||
const applicationDistribution = location.href.split('/')[2]; | ||
const urlPrefix = location.href.substr(0, location.href.indexOf('//')); | ||
const url = location.href.split('/')[3]; | ||
const apiBaseUrl = `/${applicationDistribution}/${url}/ws/rest`; | ||
const requestUrl = 'v1/session'; | ||
const auth = 'Basic ' + new Buffer(`${username}:${password}`).toString('base64'); | ||
|
||
axios({ | ||
url: `${urlPrefix}/${apiBaseUrl}/${requestUrl}`, | ||
method: 'GET', | ||
headers: { | ||
'Authorization': auth | ||
} | ||
}).then(response => { | ||
(response.data.authenticated) ? hashHistory.push('/') : toastr.error('Invalid username or password'); | ||
}) | ||
.catch(error => { | ||
toastr.error(error.message); | ||
}); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div className="well"> | ||
<a href="../../"> | ||
<img src="img/openmrs-with-title-small.png" /> | ||
</a> | ||
<div className='form-group'> | ||
<Form className='material-form' onSubmit={(event) => this.handleLogin(event)}> | ||
<FormGroup controlId="formHorizontalUsername"> | ||
<FormControl | ||
input type="text" | ||
placeholder="Username" | ||
onChange={event => this.setState({ username: event.target.value })} | ||
/> | ||
</FormGroup> | ||
<FormGroup controlId="formHorizontalPassword"> | ||
<FormControl | ||
input type="password" | ||
placeholder="Password" | ||
floatingLabelText="Password" | ||
onChange={(event) => this.setState({ password: event.target.value })} | ||
/> | ||
</FormGroup> | ||
<FormGroup> | ||
<Button className="btn-login btn-primary btn-lg" | ||
type="submit" | ||
>Log in</Button> | ||
</FormGroup> | ||
<p className="helper-text">Having trouble logging in? <a className="signinHelp" onClick={(event) => this.handleShow} >Click here</a> for help.</p> | ||
<Modal show={this.state.show} onHide={this.handleClose}> | ||
<Modal.Header closeButton> | ||
<Modal.Title>OpenMRS login</Modal.Title> | ||
</Modal.Header> | ||
<Modal.Body> | ||
Please contact system administrator | ||
</Modal.Body> | ||
<Modal.Footer> | ||
<Button onClick={(event) => this.handleClose}>Close</Button> | ||
</Modal.Footer> | ||
</Modal> | ||
</Form > | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Login; |