123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- /* global zxcvbn */
- import Ember from 'ember';
- export default Ember.Service.extend({
- includedJs: false,
- loadedJs: false,
- scorePassword: function(password, inputs) {
- // 0-4 score, the more the stronger password
- return zxcvbn(password, inputs).score;
- },
- load: function() {
- if (!this.get('includedJs')) {
- this._includeJs();
- }
- if (!this.get('loadedJs')) {
- return this._loadingPromise();
- } else {
- return this._loadedPromise();
- }
- },
- _includeJs: function() {
- Ember.$.getScript(this.get('_includedJsPath'));
- this.set('includedJs', true);
- },
- _includedJsPath: function() {
- return this.get('staticUrl') + 'misago/js/zxcvbn.js';
- }.property(),
- _loadingPromise: function() {
- var self = this;
- return new Ember.RSVP.Promise(function(resolve) {
- var wait = function() {
- if (typeof zxcvbn === "undefined") {
- Ember.run.later(function () {
- wait();
- }, 200);
- } else {
- self.set('loadedJs', true);
- resolve();
- }
- };
- wait();
- });
- },
- _loadedPromise: function() {
- // we have already loaded zxcvbn.js, resolve away!
- return new Ember.RSVP.Promise(function(resolve) {
- resolve();
- });
- }
- });
|