-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from clef/feat/initial-library
Add initial library
- Loading branch information
Showing
12 changed files
with
132 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,63 @@ | ||
# Instant2fa-component | ||
# Instant2FAComponent | ||
|
||
## Installation | ||
|
||
```bash | ||
npm install --save instant2fa-component | ||
``` | ||
|
||
## Settings page | ||
|
||
```javascript | ||
// UserSettings.jsx | ||
import React from 'react'; | ||
import Instant2FAComponent from 'instant2fa-component'; | ||
|
||
const UserSettings = () => { | ||
return ( | ||
<div> | ||
<Instant2FAComponent | ||
uri='YOUR_SETTINGS_PAGE_URI' | ||
></Instant2FAComponent> | ||
</div> | ||
) | ||
}; | ||
|
||
export default UserSettings; | ||
``` | ||
|
||
## Verification page | ||
|
||
```javascript | ||
// UserVerification.jsx | ||
import React from 'react'; | ||
import Instant2FAComponent from 'instant2fa-component'; | ||
|
||
const UserVerification = () => { | ||
const onEvent = (event) => { | ||
if (event.type === "verificationSuccess") { | ||
var token = event.payload.token; | ||
console.log("Verification token is: " + token); | ||
|
||
$.ajax({ | ||
method: 'POST', | ||
url: '/two-factor-verification', | ||
data: { | ||
instant2faToken: event.payload.token | ||
} | ||
}); | ||
} | ||
} | ||
|
||
return ( | ||
<div> | ||
<Instant2FAComponent | ||
uri='YOUR_VERIFICATION_PAGE_URI' | ||
onEvent={onEvent} | ||
></Instant2FAComponent> | ||
</div> | ||
) | ||
}; | ||
|
||
export default UserVerification; | ||
``` |
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,19 @@ | ||
import React from 'react'; | ||
import Instant2FAComponent from '../src/Instant2FAComponent.jsx'; | ||
|
||
const App = () => { | ||
const onError = (e) => { | ||
alert("There was an error: " + e.message) | ||
} | ||
|
||
return ( | ||
<div> | ||
<Instant2FAComponent | ||
uri='https://hosted.instant2fa.com/users/123456' | ||
onError={onError} | ||
></Instant2FAComponent> | ||
</div> | ||
) | ||
}; | ||
|
||
export default App; |
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
File renamed without changes.
File renamed without changes.
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
var Instant2FAComponent = require('./lib/Instant2fa-component').default; | ||
var Instant2FAComponent = require('./lib/Instant2FAComponent').default; | ||
module.exports = Instant2FAComponent; |
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
File renamed without changes.
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,42 @@ | ||
import React, {Component} from 'react' | ||
import ReactDOM from 'react-dom' | ||
import scriptLoader from 'react-async-script-loader' | ||
|
||
class Instant2FAComponent extends Component { | ||
|
||
componentWillReceiveProps ({ isScriptLoaded, isScriptLoadSucceed }) { | ||
if (isScriptLoaded && !this.props.isScriptLoaded) { // load finished | ||
if (isScriptLoadSucceed) { | ||
this.init() | ||
} else this.props.onError() | ||
} | ||
} | ||
|
||
componentDidMount () { | ||
const { isScriptLoaded, isScriptLoadSucceed } = this.props | ||
if (isScriptLoaded && isScriptLoadSucceed) { | ||
this.init() | ||
} | ||
} | ||
|
||
init() { | ||
window.Instant2FAPage.configure({ | ||
element: ReactDOM.findDOMNode(this), | ||
uri: this.props.uri | ||
}, this.props.onEvent) | ||
} | ||
|
||
render() { | ||
return ( | ||
<div></div> | ||
) | ||
} | ||
} | ||
Instant2FAComponent.propTypes = { | ||
uri: React.PropTypes.string.isRequired, | ||
onError: React.PropTypes.func, | ||
onEvent: React.PropTypes.func | ||
} | ||
Instant2FAComponent.SCRIPT_URL = 'https://js.instant2fa.com/hosted.js' | ||
|
||
export default scriptLoader([Instant2FAComponent.SCRIPT_URL])(Instant2FAComponent) |
This file was deleted.
Oops, something went wrong.
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