2017-12-31 03:08:54 +05:30
|
|
|
// @flow
|
2016-03-17 11:31:11 +05:30
|
|
|
import React, { Component } from 'react';
|
2017-12-31 03:08:54 +05:30
|
|
|
import { connect } from 'react-redux';
|
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 03:08:54 +05:30
|
|
|
import { ChangeLanguageLink } from 'components/languageSwitcher';
|
2016-03-17 11:31:11 +05:30
|
|
|
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-06-01 14:42:41 +05:30
|
|
|
import RulesPage from 'pages/rules/RulesPage';
|
|
|
|
|
2017-12-31 03:08:54 +05:30
|
|
|
import type { User } from 'components/user';
|
|
|
|
|
|
|
|
class Profile extends Component<{
|
|
|
|
user: User
|
|
|
|
}> {
|
2018-05-03 10:45:09 +05:30
|
|
|
UUID: ?HTMLElement;
|
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}>
|
2017-12-31 03:08:54 +05:30
|
|
|
{(pageTitle: string) => (
|
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-12-31 03:08:54 +05:30
|
|
|
value={<ChangeLanguageLink />}
|
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
|
|
|
|
|
|
|
handleUUIDMouseOver() {
|
2017-12-31 03:08:54 +05:30
|
|
|
if (!this.UUID) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const el = this.UUID;
|
|
|
|
|
2016-05-26 20:51:52 +05:30
|
|
|
try {
|
|
|
|
const selection = window.getSelection();
|
|
|
|
const range = document.createRange();
|
2017-12-31 03:08:54 +05:30
|
|
|
range.selectNodeContents(el);
|
2016-05-26 20:51:52 +05:30
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-05-03 10:45:09 +05:30
|
|
|
setUUID(el: ?HTMLElement) {
|
2016-05-26 20:51:52 +05:30
|
|
|
this.UUID = el;
|
|
|
|
}
|
2016-03-17 11:31:11 +05:30
|
|
|
}
|
2017-05-26 00:41:57 +05:30
|
|
|
|
2018-05-03 10:45:09 +05:30
|
|
|
export default connect(({ user }): {
|
|
|
|
user: User,
|
|
|
|
} => ({
|
|
|
|
user,
|
2017-12-31 03:08:54 +05:30
|
|
|
}))(Profile);
|