2016-03-17 11:31:11 +05:30
|
|
|
import React, { Component } from 'react';
|
2017-10-16 00:30:21 +05:30
|
|
|
import PropTypes from 'prop-types';
|
2016-03-17 11:31:11 +05:30
|
|
|
|
2017-06-13 01:02:59 +05:30
|
|
|
import { FormattedMessage as Message, FormattedRelative as Relative } from 'react-intl';
|
2017-05-26 00:41:57 +05:30
|
|
|
import { Link } from 'react-router-dom';
|
2016-03-17 11:31:11 +05:30
|
|
|
import Helmet from 'react-helmet';
|
|
|
|
|
2017-12-31 01:14:32 +05:30
|
|
|
import { localeFlags } from 'components/i18n';
|
2017-10-16 00:30:21 +05:30
|
|
|
import LANGS from 'i18n/index.json';
|
|
|
|
|
2016-03-17 11:31:11 +05:30
|
|
|
import { userShape } from 'components/user/User';
|
|
|
|
|
|
|
|
import ProfileField from './ProfileField';
|
|
|
|
import styles from './profile.scss';
|
2016-04-17 15:05:04 +05:30
|
|
|
import profileForm from './profileForm.scss';
|
2016-05-14 14:11:32 +05:30
|
|
|
import messages from './Profile.intl.json';
|
2016-03-17 11:31:11 +05:30
|
|
|
|
2016-06-01 14:42:41 +05:30
|
|
|
import RulesPage from 'pages/rules/RulesPage';
|
|
|
|
|
2017-05-26 00:41:57 +05:30
|
|
|
class Profile extends Component {
|
2016-03-17 11:31:11 +05:30
|
|
|
static displayName = 'Profile';
|
|
|
|
static propTypes = {
|
2017-10-16 00:30:21 +05:30
|
|
|
user: userShape,
|
|
|
|
createLanguageSwitcherPopup: PropTypes.func.isRequired,
|
2016-03-17 11:31:11 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { user } = this.props;
|
|
|
|
|
|
|
|
return (
|
2016-04-17 15:05:04 +05:30
|
|
|
<div>
|
2016-03-20 14:00:58 +05:30
|
|
|
<Message {...messages.accountPreferencesTitle}>
|
|
|
|
{(pageTitle) => (
|
2016-04-17 15:05:04 +05:30
|
|
|
<h2 className={styles.indexTitle}>
|
2016-03-20 14:00:58 +05:30
|
|
|
<Helmet title={pageTitle} />
|
|
|
|
{pageTitle}
|
|
|
|
</h2>
|
|
|
|
)}
|
|
|
|
</Message>
|
2016-03-17 11:31:11 +05:30
|
|
|
|
2016-04-17 15:05:04 +05:30
|
|
|
<div className={styles.indexContent}>
|
|
|
|
<div className={styles.descriptionColumn}>
|
|
|
|
<div className={styles.indexDescription}>
|
|
|
|
<Message {...messages.accountDescription} />
|
|
|
|
</div>
|
2016-03-17 11:31:11 +05:30
|
|
|
</div>
|
|
|
|
|
2016-04-17 15:05:04 +05:30
|
|
|
<div className={styles.formColumn}>
|
|
|
|
<div className={profileForm.form}>
|
|
|
|
<div className={styles.item}>
|
|
|
|
<h3 className={profileForm.title}>
|
|
|
|
<Message {...messages.personalData} />
|
|
|
|
</h3>
|
|
|
|
<p className={profileForm.description}>
|
|
|
|
<Message {...messages.preferencesDescription} />
|
|
|
|
</p>
|
|
|
|
</div>
|
2016-03-17 11:31:11 +05:30
|
|
|
|
2016-04-17 15:05:04 +05:30
|
|
|
<ProfileField
|
2016-05-02 18:43:18 +05:30
|
|
|
link="/profile/change-username"
|
2016-04-17 15:05:04 +05:30
|
|
|
label={<Message {...messages.nickname} />}
|
|
|
|
value={user.username}
|
2016-04-24 00:14:10 +05:30
|
|
|
warningMessage={user.hasMojangUsernameCollision ? (
|
2016-06-01 14:42:41 +05:30
|
|
|
<Message {...messages.mojangPriorityWarning} values={{
|
|
|
|
rules: (
|
|
|
|
<Link to={{
|
|
|
|
pathname: '/rules',
|
|
|
|
hash: `#${RulesPage.getRuleHash(1, 4)}`
|
|
|
|
}}>
|
|
|
|
<Message {...messages.projectRules} />
|
|
|
|
</Link>
|
|
|
|
)
|
|
|
|
}} />
|
2016-04-24 00:14:10 +05:30
|
|
|
) : ''}
|
2016-04-17 15:05:04 +05:30
|
|
|
/>
|
2016-03-17 11:31:11 +05:30
|
|
|
|
2016-04-17 15:05:04 +05:30
|
|
|
<ProfileField
|
2016-05-02 23:02:03 +05:30
|
|
|
link="/profile/change-email"
|
2017-11-30 17:26:09 +05:30
|
|
|
label={<Message {...messages.email} />}
|
2016-04-17 15:05:04 +05:30
|
|
|
value={user.email}
|
|
|
|
/>
|
2016-03-17 11:31:11 +05:30
|
|
|
|
2016-04-17 15:05:04 +05:30
|
|
|
<ProfileField
|
|
|
|
link="/profile/change-password"
|
2016-05-02 18:43:18 +05:30
|
|
|
label={<Message {...messages.password} />}
|
2016-04-17 15:05:04 +05:30
|
|
|
value={<Message {...messages.changedAt} values={{
|
2016-05-02 23:12:40 +05:30
|
|
|
at: (<Relative value={user.passwordChangedAt * 1000} updateInterval={1000} />)
|
2016-04-17 15:05:04 +05:30
|
|
|
}} />}
|
|
|
|
/>
|
2016-03-17 11:31:11 +05:30
|
|
|
|
2016-05-20 01:11:43 +05:30
|
|
|
<ProfileField
|
2017-11-30 17:26:09 +05:30
|
|
|
label={<Message {...messages.siteLanguage} />}
|
2017-10-16 00:30:21 +05:30
|
|
|
value={
|
|
|
|
<span className={styles.language} onClick={this.onLanguageSwitcher.bind(this)}>
|
|
|
|
<span className={styles.languageIcon} style={{
|
2017-12-31 01:14:32 +05:30
|
|
|
backgroundImage: `url('${localeFlags.getIconUrl(user.lang)}')`
|
2017-10-16 00:30:21 +05:30
|
|
|
}} />
|
|
|
|
{LANGS[user.lang].name}
|
|
|
|
</span>
|
|
|
|
}
|
2016-05-20 01:11:43 +05:30
|
|
|
/>
|
|
|
|
|
2016-04-17 15:05:04 +05:30
|
|
|
<ProfileField
|
2017-11-21 04:06:19 +05:30
|
|
|
link="/profile/mfa"
|
2016-04-17 15:05:04 +05:30
|
|
|
label={<Message {...messages.twoFactorAuth} />}
|
2017-08-20 21:15:21 +05:30
|
|
|
value={user.isOtpEnabled ? (
|
|
|
|
<Message {...messages.enabled} />
|
|
|
|
) : (
|
|
|
|
<Message {...messages.disabled} />
|
|
|
|
)}
|
2016-04-17 15:05:04 +05:30
|
|
|
/>
|
2016-03-17 11:31:11 +05:30
|
|
|
|
2016-04-17 15:05:04 +05:30
|
|
|
<ProfileField
|
2017-11-30 17:26:09 +05:30
|
|
|
label={<Message {...messages.uuid} />}
|
2016-05-26 20:51:52 +05:30
|
|
|
value={
|
|
|
|
<span
|
|
|
|
className={styles.uuid}
|
|
|
|
ref={this.setUUID.bind(this)}
|
|
|
|
onMouseOver={this.handleUUIDMouseOver.bind(this)}
|
|
|
|
>
|
|
|
|
{user.uuid}
|
|
|
|
</span>
|
|
|
|
}
|
2016-04-17 15:05:04 +05:30
|
|
|
/>
|
|
|
|
</div>
|
2016-03-17 11:31:11 +05:30
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2016-05-26 20:51:52 +05:30
|
|
|
|
2017-10-16 00:30:21 +05:30
|
|
|
onLanguageSwitcher() {
|
|
|
|
this.props.createLanguageSwitcherPopup();
|
|
|
|
}
|
|
|
|
|
2016-05-26 20:51:52 +05:30
|
|
|
handleUUIDMouseOver() {
|
|
|
|
try {
|
|
|
|
const selection = window.getSelection();
|
|
|
|
const range = document.createRange();
|
|
|
|
range.selectNodeContents(this.UUID);
|
|
|
|
selection.removeAllRanges();
|
|
|
|
selection.addRange(range);
|
2017-01-02 19:07:02 +05:30
|
|
|
} catch (err) {
|
|
|
|
// the browser does not support an API
|
|
|
|
}
|
2016-05-26 20:51:52 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
setUUID(el) {
|
|
|
|
this.UUID = el;
|
|
|
|
}
|
2016-03-17 11:31:11 +05:30
|
|
|
}
|
2017-05-26 00:41:57 +05:30
|
|
|
|
|
|
|
import { connect } from 'react-redux';
|
2017-10-16 00:30:21 +05:30
|
|
|
import LanguageSwitcher from 'components/languageSwitcher/LanguageSwitcher';
|
|
|
|
import { create as createPopup } from 'components/ui/popup/actions';
|
2017-05-26 00:41:57 +05:30
|
|
|
|
|
|
|
export default connect((state) => ({
|
2017-10-16 00:30:21 +05:30
|
|
|
user: state.user,
|
|
|
|
}), {
|
|
|
|
createLanguageSwitcherPopup: () => createPopup(LanguageSwitcher),
|
|
|
|
})(Profile);
|