Blame view

public/js/services/EncryptServ.js 718 Bytes
2201e360   Geoffrey PREUD'HOMME   Le login se fait ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
  angular.module('EncryptServ', []).service('EncryptService', ['$http',
    function ($http) {
      a = {
        encrypter: false,
        whenOk: function (cb) {
          if (this.encrypter) {
            cb();
          } else {
            this.prepare(cb);
          }
        },
        prepare: function (cb) {
          $http.get('/com/ci_com_pub.pem').success(function (key) {
            this.encrypter = new JSEncrypt();
            this.encrypter.setPublicKey(key);
            cb();
          });
        },
        preload: function(cb) {
          this.whenOk(cb);
        },
        encrypt: function (string, cb) {
          this.whenOk(function() {
            cb(this.encrypter.encrypt(string));
          });
        }
      };
      return a;
    }
  ]);