diff options
| author | jackyzha0 <[email protected]> | 2020-05-12 21:39:57 -0700 |
|---|---|---|
| committer | jackyzha0 <[email protected]> | 2020-05-12 21:39:57 -0700 |
| commit | 4c6d5b49deb330200cbedc76334e6aa9cd848c94 (patch) | |
| tree | 6c121a02ea73b6622d521cfd3630ca7c6fd5c52c /frontend/src/components/ViewPaste.js | |
| parent | password modal (diff) | |
| download | ctrl-v-4c6d5b49deb330200cbedc76334e6aa9cd848c94.tar.xz ctrl-v-4c6d5b49deb330200cbedc76334e6aa9cd848c94.zip | |
working password render
Diffstat (limited to 'frontend/src/components/ViewPaste.js')
| -rw-r--r-- | frontend/src/components/ViewPaste.js | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/frontend/src/components/ViewPaste.js b/frontend/src/components/ViewPaste.js index 4b7c46c..d591d19 100644 --- a/frontend/src/components/ViewPaste.js +++ b/frontend/src/components/ViewPaste.js @@ -24,10 +24,12 @@ class ViewPaste extends React.Component { validPass: false, expiry: 'no expiry', error: '', + passError: '', mode: RENDER_MODES.RAW, }; this.handleChange = this.handleChange.bind(this); + this.validatePass = this.validatePass.bind(this); } handleChange(event) { @@ -45,6 +47,18 @@ class ViewPaste extends React.Component { } } + newPassErr() { + // shake thing + // set err field and clear input + this.setState({ + passError: "incorrect pass", + enteredPass: "", + }) + setTimeout(() => { + this.setState({ passError: '' }) + }, 3000); + } + drawRightMode() { switch (this.state.mode) { // TODO: add other renderers @@ -60,9 +74,35 @@ class ViewPaste extends React.Component { } validatePass(pass) { - // stub - console.log(pass) - // need to toggle validPass + var bodyFormData = new FormData(); + bodyFormData.set('password', pass); + + axios({ + method: 'post', + url: `http://localhost:8080/api/${this.props.hash}`, + data: bodyFormData, + headers: { 'Content-Type': 'multipart/form-data' }, + }).then((response) => { + this.setState({ validPass: true }) + this.setStateFromData(response.data) + }).catch((error) => { + const resp = error.response + + // 401 unauth (bad pass) + if (resp.status === 401) { + this.newPassErr() + return + } + + // otherwise, just log it lmao + if (resp !== undefined) { + const errTxt = `${resp.statusText}: ${resp.data}` + this.newErr(errTxt) + } else { + // some weird err (e.g. network) + this.newErr(error) + } + }); } render() { @@ -73,6 +113,7 @@ class ViewPaste extends React.Component { validPass={this.state.validPass} value={this.state.enteredPass} onChange={this.handleChange} + error={this.state.passError} validateCallback={this.validatePass} /> <TitleInput value={this.state.title} @@ -96,6 +137,7 @@ class ViewPaste extends React.Component { } setStateFromData(data) { + console.log(data) this.setState({ title: data.title, content: data.content, @@ -113,8 +155,6 @@ class ViewPaste extends React.Component { }).catch((error) => { const resp = error.response - console.log(resp.status) - // catch 401 unauth (password protected) if (resp.status === 401) { this.setState({hasPass: true}) |