Changed registration to be a 2 step process.

pull/259/head
Mikunj 6 years ago
parent 338f4e3682
commit ae8b3899ad

@ -11,7 +11,7 @@ const matchesHash = (phrase, hash) =>
phrase && sha512(phrase.trim()) === hash.trim(); phrase && sha512(phrase.trim()) === hash.trim();
const validatePassword = (phrase, i18n) => { const validatePassword = (phrase, i18n) => {
if (!phrase || typeof phrase !== 'string') { if (typeof phrase !== 'string') {
return i18n ? i18n('passwordTypeError') : ERRORS.TYPE; return i18n ? i18n('passwordTypeError') : ERRORS.TYPE;
} }

@ -655,21 +655,15 @@
<div class='step-body'> <div class='step-body'>
<div class='header'>Create your Loki Messenger Account</div> <div class='header'>Create your Loki Messenger Account</div>
<div class='display-name-input'> <!-- Registration -->
<div class='input-header'>Enter a name that will be shown to all your contacts</div> <div class='page'>
<input class='form-control' type='text' id='display-name' placeholder='Display Name (optional)' autocomplete='off' spellcheck='false' maxlength='25'>
</div>
<div class='password-inputs'>
<div class='input-header'>Type an optional password for added security</div>
<input class='form-control' type='password' id='password' placeholder='Password (optional)' autocomplete='off' spellcheck='false'>
<input class='form-control' type='password' id='password-confirmation' placeholder='Retype your password' autocomplete='off' spellcheck='false'>
<div class='error'></div>
</div>
<h4 class='section-toggle'>Restore using seed</h4> <h4 class='section-toggle'>Restore using seed</h4>
<div class='standalone-mnemonic section-content'> <div class='standalone-mnemonic section-content'>
<div class='standalone-mnemonic-inputs'> <div class='standalone-mnemonic-inputs'>
<input class='form-control' type='text' id='mnemonic' placeholder='Mnemonic Seed' autocomplete='off' spellcheck='false' /> <input class='form-control' type='text' id='mnemonic' placeholder='Mnemonic Seed' autocomplete='off' spellcheck='false' />
</div>
<div class='restore standalone-register-language'>
<span>Language:</span>
<div class='select-container'> <div class='select-container'>
<select id='mnemonic-language'></select> <select id='mnemonic-language'></select>
</div> </div>
@ -693,12 +687,32 @@
</div> </div>
<div id='mnemonic-display' /> <div id='mnemonic-display' />
<div class='standalone-register-buttons'> <div class='standalone-register-buttons'>
<a class='button' id='generate-mnemonic'>Generate Seed</a> <a class='button grey' id='generate-mnemonic'>Generate Seed</a>
<a class='button' id='copy-mnemonic'>Copy Seed</a> <a class='button grey' id='copy-mnemonic'>Copy Seed</a>
<a class='button' id='register' data-loading-text='Please wait...'>Register</a> <a class='button' id='register' data-loading-text='Please wait...'>Register</a>
</div> </div>
</div> </div>
</div> </div>
<!-- Profile -->
<div class='page'>
<div class='display-name-input'>
<div class='input-header'>Enter a name that will be shown to all your contacts</div>
<input class='form-control' type='text' id='display-name' placeholder='Display Name (optional)' autocomplete='off' spellcheck='false' maxlength='25'>
</div>
<div class='password-inputs'>
<div class='input-header'>Type an optional password for added security</div>
<input class='form-control' type='password' id='password' placeholder='Password (optional)' autocomplete='off' spellcheck='false'>
<input class='form-control' type='password' id='password-confirmation' placeholder='Retype your password' autocomplete='off' spellcheck='false'>
<div class='error'></div>
</div>
<div class='buttons'>
<a class='button grey' id='back-button'>Back</a>
<a class='button' id='save-button' data-loading-text='Please wait...'>Save</a>
</div>
</div>
</div>
</div> </div>
</div> </div>
</script> </script>

@ -1,4 +1,4 @@
/* global Whisper, $, getAccountManager, textsecure, i18n, passwordUtil */ /* global Whisper, $, getAccountManager, textsecure, i18n, passwordUtil, _ */
/* eslint-disable more/no-then */ /* eslint-disable more/no-then */
@ -38,9 +38,12 @@
this.$passwordInput = this.$('#password'); this.$passwordInput = this.$('#password');
this.$passwordConfirmationInput = this.$('#password-confirmation'); this.$passwordConfirmationInput = this.$('#password-confirmation');
this.$passwordConfirmationInput.hide();
this.$passwordInputError = this.$('.password-inputs .error'); this.$passwordInputError = this.$('.password-inputs .error');
this.registrationParams = {};
this.$pages = this.$('.page');
this.showRegisterPage();
this.onValidatePassword(); this.onValidatePassword();
}, },
events: { events: {
@ -50,14 +53,40 @@
'change #code': 'onChangeCode', 'change #code': 'onChangeCode',
'click #register': 'registerWithoutMnemonic', 'click #register': 'registerWithoutMnemonic',
'click #register-mnemonic': 'registerWithMnemonic', 'click #register-mnemonic': 'registerWithMnemonic',
'click #back-button': 'onBack',
'click #save-button': 'onSaveProfile',
'change #mnemonic': 'onChangeMnemonic', 'change #mnemonic': 'onChangeMnemonic',
'click #generate-mnemonic': 'onGenerateMnemonic', 'click #generate-mnemonic': 'onGenerateMnemonic',
'change #mnemonic-display-language': 'onGenerateMnemonic', 'change #mnemonic-display-language': 'onGenerateMnemonic',
'click #copy-mnemonic': 'onCopyMnemonic', 'click #copy-mnemonic': 'onCopyMnemonic',
'click .section-toggle': 'toggleSection', 'click .section-toggle': 'toggleSection',
'keyup #password': 'onPasswordChange', 'keyup #password': 'onValidatePassword',
'keyup #password-confirmation': 'onValidatePassword', 'keyup #password-confirmation': 'onValidatePassword',
}, },
async showPage(pageIndex) {
// eslint-disable-next-line func-names
this.$pages.each(function(index) {
if (index !== pageIndex) {
$(this).hide();
} else {
$(this).show();
}
});
},
async showRegisterPage() {
this.registrationParams = {};
this.showPage(0);
},
async showProfilePage(mnemonic, language) {
this.registrationParams = {
mnemonic,
language,
};
this.$passwordInput.val('');
this.$passwordConfirmationInput.val('');
this.onValidatePassword();
this.showPage(1);
},
async register(mnemonic, language) { async register(mnemonic, language) {
// Make sure the password is valid // Make sure the password is valid
if (this.validatePassword()) { if (this.validatePassword()) {
@ -85,7 +114,7 @@
registerWithoutMnemonic() { registerWithoutMnemonic() {
const mnemonic = this.$('#mnemonic-display').text(); const mnemonic = this.$('#mnemonic-display').text();
const language = this.$('#mnemonic-display-language').val(); const language = this.$('#mnemonic-display-language').val();
this.register(mnemonic, language); this.showProfilePage(mnemonic, language);
}, },
registerWithMnemonic() { registerWithMnemonic() {
const mnemonic = this.$('#mnemonic').val(); const mnemonic = this.$('#mnemonic').val();
@ -93,8 +122,20 @@
if (!mnemonic) { if (!mnemonic) {
this.log('Please provide a mnemonic word list'); this.log('Please provide a mnemonic word list');
} else { } else {
this.register(mnemonic, language); this.showProfilePage(mnemonic, language);
}
},
onSaveProfile() {
if (_.isEmpty(this.registrationParams)) {
this.onBack();
return;
} }
const { mnemonic, language } = this.registrationParams;
this.register(mnemonic, language);
},
onBack() {
this.showRegisterPage();
}, },
onChangeMnemonic() { onChangeMnemonic() {
this.$('#status').html(''); this.$('#status').html('');
@ -185,16 +226,6 @@
.not($next) .not($next)
.slideUp('fast'); .slideUp('fast');
}, },
onPasswordChange() {
const input = this.$passwordInput.val();
if (!input || input.length === 0) {
this.$passwordConfirmationInput.val('');
this.$passwordConfirmationInput.hide();
} else {
this.$passwordConfirmationInput.show();
}
this.onValidatePassword();
},
validatePassword() { validatePassword() {
const input = this.trim(this.$passwordInput.val()); const input = this.trim(this.$passwordInput.val());
const confirmationInput = this.trim( const confirmationInput = this.trim(

@ -872,8 +872,7 @@ $loading-height: 16px;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
align-items: center; align-items: center;
margin: 1em 8px; margin: 0 8px;
margin-top: 0;
input { input {
flex: 1; flex: 1;
@ -914,6 +913,10 @@ $loading-height: 16px;
justify-content: center; justify-content: center;
margin-top: 2em; margin-top: 2em;
&.restore {
margin-bottom: 2em;
}
span { span {
margin-right: 8px; margin-right: 8px;
} }
@ -924,15 +927,18 @@ $loading-height: 16px;
font-size: 14px; font-size: 14px;
} }
#generate-mnemonic, .button.grey {
#copy-mnemonic {
background: $grey; background: $grey;
} }
.buttons {
margin-top: 24px;
}
.select-container { .select-container {
position: relative; position: relative;
display: block; display: block;
width: 10em; width: 9em;
line-height: 2.8; line-height: 2.8;
background: white; background: white;
overflow: hidden; overflow: hidden;
@ -957,6 +963,7 @@ $loading-height: 16px;
padding: 0 0 0 0.5em; padding: 0 0 0 0.5em;
color: black; color: black;
cursor: pointer; cursor: pointer;
font-size: 14px;
::-ms-expand { ::-ms-expand {
display: none; display: none;
@ -979,6 +986,11 @@ $loading-height: 16px;
} }
.password-inputs { .password-inputs {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
input { input {
margin-bottom: 0.5em; margin-bottom: 0.5em;
} }

Loading…
Cancel
Save