Commit 97d1b55e14c5c833e4a4c3dca9146af42eebd08d

Authored by OpenWapp Developer
1 parent 9a16471fa8

Alerting with a message when the account has expired.

Showing 7 changed files with 74 additions and 10 deletions

app/scripts/localisations/translation.js View file @ 97d1b55
... ... @@ -179,7 +179,10 @@
179 179 'que tienes red? Prueba a reiniciar OpenWapp y si sigue ' +
180 180 'ocurriendo, intenta la operación más tarde',
181 181 participatingInTooMuchGroups: 'Estás participando en demasiados grupos.' +
182   - ' El límite es 50. Por favor, abandona uno antes de crear otro'
  182 + ' El límite es 50. Por favor, abandona uno antes de crear otro',
  183 + accountExpired: 'Su cuenta ha caducado. ¿Desea actualizar su cuenta?',
  184 + accountExpiration: 'Fecha de expiración',
  185 + upgradeNow: 'Actualizar ahora'
183 186 },
184 187 'en-US': {
185 188 all: 'All',
... ... @@ -361,7 +364,12 @@
361 364 'sure you are connected? Try to close and open OpenWapp. If the ' +
362 365 'behaviour keep reproducing, try again later.',
363 366 participatingInTooMuchGroups: 'You are participating in too much groups' +
364   - '. The limit is 50. You must leave one group before starting another one.'
  367 + '. The limit is 50. You must leave one group before starting another ' +
  368 + 'one.',
  369 + accountExpired: 'Your account has expired. Do you want to upgrade ' +
  370 + 'your account now?',
  371 + accountExpiration: 'Expiration date',
  372 + upgradeNow: 'Upgrade now'
365 373 },
366 374 pt : {
367 375 all: 'Tudo',
... ... @@ -541,7 +549,11 @@
541 549 'que você está conectado? Tente fechar e abrir OpenWapp. Se o ' +
542 550 'comportamento continuar reproduzindo, tente novamente mais tarde.',
543 551 participatingInTooMuchGroups: 'Está muito adicionado em grupos. O ' +
544   - 'limite é de 50. Você deve deixar um grupo antes de iniciar outra.'
  552 + 'limite é de 50. Você deve deixar um grupo antes de iniciar outra.',
  553 + accountExpired: 'Sua conta expirou. Você quer atualizar a sua conta ' +
  554 + 'agora?',
  555 + accountExpiration: 'Data de validade',
  556 + upgradeNow: 'Actualizar agora'
545 557 },
546 558 'pt-BR' : {
547 559 all: 'Tudo',
... ... @@ -722,7 +734,11 @@
722 734 'que você está conectado? Tente fechar e abrir OpenWapp. Se o ' +
723 735 'comportamento continuar reproduzindo, tente novamente mais tarde.',
724 736 participatingInTooMuchGroups: 'Está muito adicionado em grupos. O ' +
725   - 'limite é de 50. Você deve deixar um grupo antes de iniciar outra.'
  737 + 'limite é de 50. Você deve deixar um grupo antes de iniciar outra.',
  738 + accountExpired: 'Sua conta expirou. Você quer atualizar a sua conta ' +
  739 + 'agora?',
  740 + accountExpiration: 'Data de validade',
  741 + upgradeNow: 'Actualizar agora'
726 742 }
727 743 };
728 744 });
app/scripts/models/auth.js View file @ 97d1b55
... ... @@ -87,15 +87,17 @@
87 87 _this.trigger('login:fail');
88 88 return;
89 89 }
90   -
91   - // TODO: Distinguish when the error is expired to warn the users about
92   - // the state of their account.
  90 + else if (err === 'expired') {
  91 + _this.trigger('login:expired');
  92 + return;
  93 + }
93 94 else if (err) {
94 95 _this._retryLoginBecauseOfErrors();
95 96 return;
96 97 }
97 98  
98   - console.log('WA PASSWORD: ' + pass);
  99 + console.log('[auth] MSISDN: ' + msisdn);
  100 + console.log('[auth] password: ' + pass);
99 101  
100 102 _this.set('password', pass);
101 103 _this.set('msisdn', msisdn);
app/scripts/templates/helpers.js View file @ 97d1b55
... ... @@ -58,7 +58,10 @@
58 58 if (!messageDate) { return ''; }
59 59 var formattedDate = formatDay(messageDate);
60 60 var formattedTime = /^\d\d:\d\d/.exec(messageDate.toTimeString());
61   - return formattedTime + ' ' + formattedDate;
  61 + var currentYear = new Date().getFullYear();
  62 + var formattedYear = currentYear !== messageDate.getFullYear() ?
  63 + ' ' + messageDate.getFullYear() : '';
  64 + return formattedTime + ' ' + formattedDate + formattedYear;
62 65 },
63 66  
64 67 _ifIsUnsent: function (status, block) {
app/scripts/templates/profile.hbs View file @ 97d1b55
... ... @@ -48,6 +48,9 @@
48 48 <p>{{translate 'wakeUpDescription'}}</p>
49 49 </form>
50 50 <hr />
  51 + <p>{{translate 'accountExpiration'}}: {{formattedMessageDate expiration}}</p>
  52 + <a id="upgrade-now" href="#">{{translate 'upgradeNow'}}</a>
  53 + <hr />
51 54 <p id="revision">rev: {{currentCommit}}</p>
52 55 </section>
53 56 </div>
app/scripts/vendor/coseme-client/client.js View file @ 97d1b55
... ... @@ -570,6 +570,21 @@
570 570 return methods.call('is_online', []);
571 571 },
572 572  
  573 + get expirationDate() {
  574 + return methods.call('getExpirationDate', []);
  575 + },
  576 +
  577 + UPGRADE_URL: 'http://www.whatsapp.com/payments/cksum_pay.php?' +
  578 + 'phone={{phone}}&cksum={{cksum}}',
  579 +
  580 + getUpgradeAccountURL: function (phone) {
  581 + var token = phone + 'abc';
  582 + var cksum = CoSeMe.crypto.MD5(token);
  583 + var url = this.UPGRADE_URL.replace('{{phone}}', phone);
  584 + url = url.replace('{{cksum}}', cksum);
  585 + return url + '';
  586 + },
  587 +
573 588 auth: function(userId, password, callback) {
574 589 // Avoid authenticate while in the middle of another authentication
575 590 if (authenticating) {
app/scripts/views/inbox.js View file @ 97d1b55
... ... @@ -33,10 +33,12 @@
33 33 if (!global.client.isOnline) {
34 34 var onSuccess = function () {
35 35 this.stopListening(global.auth, 'login:fail', onFail);
  36 + this.stopListening(global.auth, 'login:expired', onExpired);
36 37 };
37 38  
38 39 var onFail = function () {
39 40 this.stopListening(global.auth, 'login:success', onSuccess);
  41 + this.stopListening(global.auth, 'login:expired', onExpired);
40 42 if (localStorage.getItem('isPinSent')) {
41 43 this._goToValidate();
42 44 }
43 45  
44 46  
... ... @@ -45,12 +47,27 @@
45 47 }
46 48 };
47 49  
  50 + var onExpired = function () {
  51 + this.stopListening(global.auth, 'login:fail', onFail);
  52 + this.stopListening(global.auth, 'login:success', onSuccess);
  53 + var wantToPurchase =
  54 + confirm('Your account has expired. Do you want to update your account?');
  55 + if (wantToPurchase) {
  56 + window.open(this._getUpgradeURL(), '', 'dialog');
  57 + }
  58 + };
  59 +
48 60 this.listenToOnce(global.auth, 'login:success', onSuccess);
49 61 this.listenToOnce(global.auth, 'login:fail', onFail);
  62 + this.listenToOnce(global.auth, 'login:expired', onExpired);
50 63  
51 64 global.auth.checkCredentials();
52 65 }
53 66 this._contactListBuffer = document.createDocumentFragment();
  67 + },
  68 +
  69 + _getUpgradeURL: function () {
  70 + return global.client.getUpgradeAccountURL(global.auth.get('msisdn'));
54 71 },
55 72  
56 73 _newGroup: function (evt) {
app/scripts/views/profile.js View file @ 97d1b55
... ... @@ -32,6 +32,7 @@
32 32  
33 33 render: function () {
34 34 this.$el.html(this.template({
  35 + expiration: global.client.expirationDate,
35 36 screenName: this.model.get('screenName'),
36 37 status: this.model.get('status')
37 38 }));
... ... @@ -51,7 +52,8 @@
51 52 'click button.close': 'goToInbox',
52 53 'click img': 'selectPicture',
53 54 'click legend': 'showSelect',
54   - 'change select': 'setAwakePeriod'
  55 + 'change select': 'setAwakePeriod',
  56 + 'click #upgrade-now': 'goToUpgradeNow'
55 57 },
56 58  
57 59 checkNameInput: function (evt) {
... ... @@ -164,6 +166,12 @@
164 166 goToInbox: function (evt) {
165 167 if (evt) { evt.preventDefault(); }
166 168 global.router.navigate('inbox', { trigger: true });
  169 + },
  170 +
  171 + goToUpgradeNow: function (evt) {
  172 + if (evt) { evt.preventDefault(); }
  173 + var phone = this.model.get('msisdn');
  174 + window.open(global.client.getUpgradeAccountURL(phone), '', 'dialog');
167 175 },
168 176  
169 177 clear: function () {