Settings lock completion

pull/730/head
Vincent 5 years ago
parent 14d3d32532
commit 6ab89a801b

@ -345,7 +345,7 @@ $session_message-container-border-radius: 5px;
border-radius: 0px; border-radius: 0px;
} }
& > *:not(svg):hover { & > *:hover:not(svg) {
filter: brightness(80%); filter: brightness(80%);
} }
} }
@ -1014,9 +1014,8 @@ label {
text-align: center; text-align: center;
font-size: 25px; font-size: 25px;
letter-spacing: 5px; letter-spacing: 5px;
font-family: "SF Pro Text"; font-family: 'SF Pro Text';
} }
} }
} }
} }
@ -1225,4 +1224,3 @@ button.module-scroll-down {
background-color: $session-shade-8; background-color: $session-shade-8;
} }
} }

@ -2,7 +2,11 @@ import React from 'react';
import { SettingsHeader } from './SessionSettingsHeader'; import { SettingsHeader } from './SessionSettingsHeader';
import { SessionSettingListItem } from './SessionSettingListItem'; import { SessionSettingListItem } from './SessionSettingListItem';
import { SessionButtonColor, SessionButton, SessionButtonType } from '../SessionButton'; import {
SessionButton,
SessionButtonColor,
SessionButtonType,
} from '../SessionButton';
export enum SessionSettingCategory { export enum SessionSettingCategory {
General = 'general', General = 'general',
@ -26,6 +30,8 @@ export interface SettingsViewProps {
interface State { interface State {
hasPassword: boolean | null; hasPassword: boolean | null;
shouldLockSettings: boolean | null;
pwdLockError: string | null;
} }
export class SettingsView extends React.Component<SettingsViewProps, State> { export class SettingsView extends React.Component<SettingsViewProps, State> {
@ -36,10 +42,13 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
this.state = { this.state = {
hasPassword: null, hasPassword: null,
pwdLockError: null,
shouldLockSettings: true,
}; };
this.settingsViewRef = React.createRef(); this.settingsViewRef = React.createRef();
this.onPasswordUpdated = this.onPasswordUpdated.bind(this); this.onPasswordUpdated = this.onPasswordUpdated.bind(this);
this.validatePasswordLock = this.validatePasswordLock.bind(this);
this.hasPassword(); this.hasPassword();
} }
@ -104,7 +113,8 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
content: { content: {
options: { options: {
group: 'notification-setting', group: 'notification-setting',
initalItem: window.getSettingValue('notification-setting') || 'message', initalItem:
window.getSettingValue('notification-setting') || 'message',
items: [ items: [
{ {
label: window.i18n('nameAndMessage'), label: window.i18n('nameAndMessage'),
@ -251,31 +261,67 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
); );
} }
public renderPasswordLock() { public renderPasswordLock() {
return ( return (
<div className="session-settings__password-lock"> <div className="session-settings__password-lock">
<div className="session-settings__password-lock-box"> <div className="session-settings__password-lock-box">
<h3> <h3>{window.i18n('password')}</h3>
{window.i18n('password')}
</h3>
<input <input
type="password" type="password"
id="password-modal-input" id="password-lock-input"
placeholder="" defaultValue=""
placeholder={window.i18n('password')}
/> />
{this.state.pwdLockError && (
<>
<div className="session-label warning">
{this.state.pwdLockError}
</div>
<div className="spacer-lg" />
</>
)}
<SessionButton <SessionButton
buttonType={SessionButtonType.BrandOutline} buttonType={SessionButtonType.BrandOutline}
buttonColor={SessionButtonColor.Green} buttonColor={SessionButtonColor.Green}
text={window.i18n('enter')} text={window.i18n('enter')}
onClick={this.validatePasswordLock}
/> />
</div> </div>
</div> </div>
); );
} }
public async validatePasswordLock() {
const enteredPassword = String($('#password-lock-input').val());
if (!enteredPassword) {
this.setState({
pwdLockError: window.i18n('noGivenPassword'),
});
return false;
}
// Check if the password matches the hash we have stored
const hash = await window.Signal.Data.getPasswordHash();
if (hash && !window.passwordUtil.matchesHash(enteredPassword, hash)) {
this.setState({
pwdLockError: window.i18n('invalidPassword'),
});
return false;
}
// Unlocked settings
this.setState({
shouldLockSettings: false,
});
return true;
}
public hasPassword() { public hasPassword() {
const hashPromise = window.Signal.Data.getPasswordHash(); const hashPromise = window.Signal.Data.getPasswordHash();
@ -288,19 +334,19 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
public render() { public render() {
const { category } = this.props; const { category } = this.props;
const shouldRenderPasswordLock = this.state.hasPassword === true; const shouldRenderPasswordLock =
this.state.shouldLockSettings && this.state.hasPassword;
return ( return (
<div className="session-settings"> <div className="session-settings">
<SettingsHeader category={category} /> <SettingsHeader category={category} />
{shouldRenderPasswordLock {shouldRenderPasswordLock ? (
? this.renderPasswordLock() this.renderPasswordLock()
: ( ) : (
<div ref={this.settingsViewRef} className="session-settings-list"> <div ref={this.settingsViewRef} className="session-settings-list">
{this.renderSettingInCategory()} {this.renderSettingInCategory()}
</div> </div>
) )}
}
</div> </div>
); );
} }
@ -326,9 +372,10 @@ export class SettingsView extends React.Component<SettingsViewProps, State> {
} }
public onPasswordUpdated(action: string) { public onPasswordUpdated(action: string) {
if (action === 'set') { if (action === 'set' || action === 'change') {
this.setState({ this.setState({
hasPassword: true, hasPassword: true,
shouldLockSettings: true,
}); });
} }

Loading…
Cancel
Save