-
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.
- Loading branch information
1 parent
6d9fada
commit c01be70
Showing
23 changed files
with
389 additions
and
33 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,186 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import tt from 'counterpart'; | ||
import { config, auth } from 'golos-lib-js' | ||
|
||
import DialogFrame from 'app/components/dialogs/DialogFrame'; | ||
import DialogManager from 'app/components/elements/common/DialogManager'; | ||
import Input from 'app/components/elements/common/Input'; | ||
import keyCodes from 'app/utils/keyCodes'; | ||
import { pageSession } from 'app/redux/UserSaga' | ||
|
||
export function showLoginDialog(username, onClose, authType = 'active', saveLogin = false) { | ||
let dm, oldZ = '' | ||
|
||
DialogManager.showDialog({ | ||
component: LoginDialog, | ||
adaptive: true, | ||
props: { | ||
username, | ||
authType, | ||
}, | ||
onClose: (data) => { | ||
if (dm) dm.style.zIndex = oldZ | ||
if (onClose) onClose(data) | ||
}, | ||
}); | ||
|
||
setTimeout(() => { | ||
dm = document.getElementsByClassName('DialogManager')[0] | ||
oldZ = dm ? dm.style.zIndex : '' | ||
if (dm) dm.style.zIndex = 1000 | ||
}, 1) | ||
} | ||
|
||
export default class LoginDialog extends React.PureComponent { | ||
static propTypes = { | ||
onClose: PropTypes.func.isRequired, | ||
}; | ||
|
||
state = { | ||
password: '', | ||
error: '', | ||
saveLogin: false | ||
} | ||
|
||
componentDidMount() { | ||
let { saveLogin } = this.props | ||
const session = pageSession.load() | ||
if (session) { | ||
this.setState({ | ||
password: session[1] | ||
}) | ||
saveLogin = true | ||
} | ||
if (saveLogin) { | ||
this.setState({ saveLogin }) | ||
} | ||
const linkInput = document.getElementsByClassName('AddImageDialog__link-input')[0]; | ||
if (linkInput) | ||
linkInput.focus(); | ||
} | ||
|
||
onPasswordChange = (e) => { | ||
e.preventDefault() | ||
this.setState({ | ||
password: e.target.value | ||
}) | ||
} | ||
|
||
onSaveLoginChange = (e) => { | ||
this.setState({ | ||
saveLogin: !this.state.saveLogin | ||
}) | ||
} | ||
|
||
onLogin = async (e) => { | ||
e.preventDefault() | ||
const { username, authType } = this.props | ||
const { password, saveLogin } = this.state | ||
|
||
this.setState({ | ||
error: '' | ||
}) | ||
let authRes | ||
try { | ||
authRes = await auth.login(username, password) | ||
} catch (err) { | ||
this.setState({ | ||
error: tt('login_dialog_jsx.node_failure_NODE_ERROR', { | ||
NODE: config.get('websocket'), | ||
ERROR: err.toString().substring(0, 100) | ||
}) | ||
}) | ||
return | ||
} | ||
if (!authRes[authType]) { | ||
this.setState({ | ||
error: tt('login_dialog_jsx.wrong_pass_ROLE', { | ||
ROLE: authType | ||
}) | ||
}) | ||
return | ||
} | ||
|
||
if (saveLogin) { | ||
pageSession.save(password, username) | ||
} else { | ||
pageSession.clear() | ||
} | ||
|
||
this.setState({ | ||
error: '' | ||
}) | ||
this.props.onClose({ | ||
password | ||
}) | ||
} | ||
|
||
onCancel = (e) => { | ||
e.preventDefault() | ||
this.props.onClose({}) | ||
} | ||
|
||
render() { | ||
const { password, error, saveLogin } = this.state | ||
return ( | ||
<DialogFrame | ||
className='LoginDialog' | ||
title={tt('loginform_jsx.login_active')} | ||
onCloseClick={this._onCloseClick} | ||
> | ||
<div> | ||
<div className="AddImageDialog__link-text"> | ||
{tt('loginform_jsx.is_is_for_operation')} | ||
</div> | ||
<Input | ||
block | ||
className="AddImageDialog__link-input" | ||
type='password' | ||
autoFocus | ||
required | ||
autoComplete='on' | ||
value={password} | ||
onKeyDown={this._onInputKeyDown} | ||
onChange={this.onPasswordChange} | ||
/> | ||
</div> | ||
{error && <div className='error'> | ||
{error} | ||
</div>} | ||
<div style={{ marginTop: '1rem' }}> | ||
<center> | ||
<label htmlFor='saveLogin'> | ||
{tt('loginform_jsx.keep_me_logged_in_memo')} | ||
<input id='saveLogin' type='checkbox' checked={saveLogin} | ||
onClick={this.onSaveLoginChange} /> | ||
</label> | ||
</center> | ||
</div> | ||
<div style={{ marginTop: '1rem' }}> | ||
<center> | ||
<button className='button' onClick={this.onLogin}> | ||
{tt('g.login')} | ||
</button> | ||
<button className='button hollow' onClick={this.onCancel}> | ||
{tt('g.cancel')} | ||
</button> | ||
</center> | ||
</div> | ||
</DialogFrame> | ||
); | ||
} | ||
|
||
_onInputKeyDown = e => { | ||
if (e.which === keyCodes.ENTER) { | ||
e.preventDefault(); | ||
this.props.onClose({ | ||
url: e.target.value, | ||
}); | ||
} | ||
}; | ||
|
||
_onCloseClick = () => { | ||
this.props.onClose(); | ||
}; | ||
} |
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,12 @@ | ||
.LoginDialog { | ||
min-width: 700px; | ||
|
||
@media screen and (max-width: 700px) { | ||
min-width: 200px; | ||
width: 100%; | ||
} | ||
|
||
.button { | ||
margin-bottom: 0px; | ||
} | ||
} |
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
Oops, something went wrong.