2018-07-07 00:48:14 +00:00
|
|
|
/* global Whisper, $, getAccountManager, textsecure */
|
|
|
|
|
|
|
|
/* eslint-disable more/no-then */
|
|
|
|
|
|
|
|
// eslint-disable-next-line func-names
|
2018-04-27 21:25:04 +00:00
|
|
|
(function() {
|
|
|
|
'use strict';
|
2018-07-07 00:48:14 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
window.Whisper = window.Whisper || {};
|
2017-04-19 17:34:19 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
Whisper.StandaloneRegistrationView = Whisper.View.extend({
|
|
|
|
templateName: 'standalone',
|
|
|
|
className: 'full-screen-flow',
|
2018-07-07 00:48:14 +00:00
|
|
|
initialize() {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.accountManager = getAccountManager();
|
2017-04-19 17:34:19 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
this.render();
|
2017-05-09 20:53:45 +00:00
|
|
|
|
2018-07-07 00:48:14 +00:00
|
|
|
const number = textsecure.storage.user.getNumber();
|
2018-04-27 21:25:04 +00:00
|
|
|
if (number) {
|
|
|
|
this.$('input.number').val(number);
|
|
|
|
}
|
|
|
|
this.phoneView = new Whisper.PhoneInputView({
|
|
|
|
el: this.$('#phone-number-input'),
|
|
|
|
});
|
|
|
|
this.$('#error').hide();
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
'validation input.number': 'onValidation',
|
|
|
|
'click #request-voice': 'requestVoice',
|
|
|
|
'click #request-sms': 'requestSMSVerification',
|
|
|
|
'change #code': 'onChangeCode',
|
|
|
|
'click #verifyCode': 'verifyCode',
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
verifyCode() {
|
|
|
|
const number = this.phoneView.validateNumber();
|
|
|
|
const verificationCode = $('#code')
|
2018-04-27 21:25:04 +00:00
|
|
|
.val()
|
|
|
|
.replace(/\D+/g, '');
|
2017-04-19 17:34:19 +00:00
|
|
|
|
2018-04-27 21:25:04 +00:00
|
|
|
this.accountManager
|
|
|
|
.registerSingleDevice(number, verificationCode)
|
2018-07-07 00:48:14 +00:00
|
|
|
.then(() => {
|
|
|
|
this.$el.trigger('openInbox');
|
|
|
|
})
|
2018-04-27 21:25:04 +00:00
|
|
|
.catch(this.log.bind(this));
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
log(s) {
|
2018-07-21 19:00:08 +00:00
|
|
|
window.log.info(s);
|
2018-04-27 21:25:04 +00:00
|
|
|
this.$('#status').text(s);
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
validateCode() {
|
|
|
|
const verificationCode = $('#code')
|
2018-04-27 21:25:04 +00:00
|
|
|
.val()
|
|
|
|
.replace(/\D/g, '');
|
2018-07-07 00:48:14 +00:00
|
|
|
|
|
|
|
if (verificationCode.length === 6) {
|
2018-04-27 21:25:04 +00:00
|
|
|
return verificationCode;
|
|
|
|
}
|
2018-07-07 00:48:14 +00:00
|
|
|
|
|
|
|
return null;
|
2018-04-27 21:25:04 +00:00
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
displayError(error) {
|
2018-04-27 21:25:04 +00:00
|
|
|
this.$('#error')
|
|
|
|
.hide()
|
|
|
|
.text(error)
|
|
|
|
.addClass('in')
|
|
|
|
.fadeIn();
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
onValidation() {
|
2018-04-27 21:25:04 +00:00
|
|
|
if (this.$('#number-container').hasClass('valid')) {
|
|
|
|
this.$('#request-sms, #request-voice').removeAttr('disabled');
|
|
|
|
} else {
|
|
|
|
this.$('#request-sms, #request-voice').prop('disabled', 'disabled');
|
|
|
|
}
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
onChangeCode() {
|
2018-04-27 21:25:04 +00:00
|
|
|
if (!this.validateCode()) {
|
|
|
|
this.$('#code').addClass('invalid');
|
|
|
|
} else {
|
|
|
|
this.$('#code').removeClass('invalid');
|
|
|
|
}
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
requestVoice() {
|
2018-04-27 21:25:04 +00:00
|
|
|
window.removeSetupMenuItems();
|
|
|
|
this.$('#error').hide();
|
2018-07-07 00:48:14 +00:00
|
|
|
const number = this.phoneView.validateNumber();
|
2018-04-27 21:25:04 +00:00
|
|
|
if (number) {
|
|
|
|
this.accountManager
|
|
|
|
.requestVoiceVerification(number)
|
|
|
|
.catch(this.displayError.bind(this));
|
|
|
|
this.$('#step2')
|
|
|
|
.addClass('in')
|
|
|
|
.fadeIn();
|
|
|
|
} else {
|
|
|
|
this.$('#number-container').addClass('invalid');
|
|
|
|
}
|
|
|
|
},
|
2018-07-07 00:48:14 +00:00
|
|
|
requestSMSVerification() {
|
2018-04-27 21:25:04 +00:00
|
|
|
window.removeSetupMenuItems();
|
|
|
|
$('#error').hide();
|
2018-07-07 00:48:14 +00:00
|
|
|
const number = this.phoneView.validateNumber();
|
2018-04-27 21:25:04 +00:00
|
|
|
if (number) {
|
|
|
|
this.accountManager
|
|
|
|
.requestSMSVerification(number)
|
|
|
|
.catch(this.displayError.bind(this));
|
|
|
|
this.$('#step2')
|
|
|
|
.addClass('in')
|
|
|
|
.fadeIn();
|
|
|
|
} else {
|
|
|
|
this.$('#number-container').addClass('invalid');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
2017-04-19 17:34:19 +00:00
|
|
|
})();
|