{"action":"created","comment":{"url":"https://api.github.com/repos/camptocamp/ngeo/pulls/comments/47229351","id":47229351,"diff_hunk":"@@ -0,0 +1,174 @@\n+goog.provide('gmf.Authentication');\n+goog.provide('gmf.AuthenticationEventType');\n+\n+goog.require('gmf');\n+goog.require('goog.events.EventTarget');\n+goog.require('goog.uri.utils');\n+\n+\n+/**\n+ * @enum {string}\n+ */\n+gmf.AuthenticationEventType = {\n+  LOAD: 'load'\n+};\n+\n+\n+/**\n+ * @typedef {{\n+ *     logged: boolean\n+ * }}\n+ */\n+gmf.AuthenticationIsLoggedInResponse;\n+\n+\n+/**\n+ * @typedef {{\n+ *     status: boolean\n+ * }}\n+ */\n+gmf.AuthenticationLoginResponse;\n+\n+\n+/**\n+ * @typedef {{\n+ *     status: boolean\n+ * }}\n+ */\n+gmf.AuthenticationResetPasswordResponse;\n+\n+\n+\n+/**\n+ * @constructor\n+ * @extends {goog.events.EventTarget}\n+ * @param {angular.$http} $http Angular http service.\n+ * @param {string} authenticationBaseUrl URL to \"authentication\" web service.\n+ * @ngInject\n+ */\n+gmf.Authentication = function($http, authenticationBaseUrl) {\n+\n+  goog.base(this);\n+\n+  /**\n+   * @type {angular.$http}\n+   * @private\n+   */\n+  this.http_ = $http;\n+\n+  /**\n+   * @type {string}\n+   * @private\n+   */\n+  this.baseUrl_ = authenticationBaseUrl;\n+\n+  /**\n+   * @type {string}\n+   * @private\n+   */\n+  this.isLoggedInRouteSuffix_ = 'isloggedin';\n+\n+  /**\n+   * @type {string}\n+   * @private\n+   */\n+  this.loginRouteSuffix_ = 'login';\n+\n+  /**\n+   * @type {string}\n+   * @private\n+   */\n+  this.resetPasswordRouteSuffix_ = 'loginresetpassword';\n+\n+  /**\n+   * @type {string}\n+   * @private\n+   */\n+  //this.logoutRouteSuffix_ = 'logout';\n+\n+  /**\n+   * @type {?boolean}\n+   * @export\n+   */\n+  this.isLoggedIn = null;\n+\n+  this.load_();\n+};\n+goog.inherits(gmf.Authentication, goog.events.EventTarget);\n+\n+\n+/**\n+ * Load the authentication service, which sends an asynch request to\n+ * determine whether the user is currently connected or not.\n+ * @private\n+ */\n+gmf.Authentication.prototype.load_ = function() {\n+  var isLoggedInUrl = goog.uri.utils.appendPath(\n+      this.baseUrl_, this.isLoggedInRouteSuffix_);\n+  this.http_.get(isLoggedInUrl, {\n+    cache: false\n+  }).then(goog.bind(\n+      /**\n+       * @param {angular.$http.Response} resp Ajax response.\n+       * @return {gmf.AuthenticationIsLoggedInResponse}\n+       */\n+      function(resp) {\n+        var data = /** @type {gmf.AuthenticationIsLoggedInResponse} */ (\n+            resp.data);\n+        this.isLoggedIn = data.logged;\n+        this.dispatchEvent(gmf.AuthenticationEventType.LOAD);\n+        return data;\n+      }, this));\n+};\n+\n+\n+/**\n+ * @param {string} login\n+ * @param {string} pwd\n+ * @param {Function} callback\n+ * @export\n+ */\n+gmf.Authentication.prototype.login = function(login, pwd, callback) {\n+\n+  var url = goog.uri.utils.appendPath(this.baseUrl_, this.loginRouteSuffix_);\n+\n+  // FIXME - use post\n+  this.http_.get(url, {\n+    login: login,\n+    password: pwd\n+  })\n+    .then(goog.bind(function(response) {\n+        var responseData = /** @type {gmf.AuthenticationLoginResponse} */ (\n+            response.data);\n+        if (responseData.status) {\n+          this.isLoggedIn = true;\n+        }\n+        callback(responseData);","path":"contribs/gmf/src/services/authenticationservice.js","position":146,"original_position":146,"commit_id":"f555c5d1e9897a7f3632a25e60698e7f1ca63ae0","original_commit_id":"f555c5d1e9897a7f3632a25e60698e7f1ca63ae0","user":{"login":"fgravin","id":1491924,"avatar_url":"https://avatars.githubusercontent.com/u/1491924?v=3","gravatar_id":"","url":"https://api.github.com/users/fgravin","html_url":"https://github.com/fgravin","followers_url":"https://api.github.com/users/fgravin/followers","following_url":"https://api.github.com/users/fgravin/following{/other_user}","gists_url":"https://api.github.com/users/fgravin/gists{/gist_id}","starred_url":"https://api.github.com/users/fgravin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fgravin/subscriptions","organizations_url":"https://api.github.com/users/fgravin/orgs","repos_url":"https://api.github.com/users/fgravin/repos","events_url":"https://api.github.com/users/fgravin/events{/privacy}","received_events_url":"https://api.github.com/users/fgravin/received_events","type":"User","site_admin":false},"body":"No this is not the way it should be done.\r\nLook at the themservice, it should return $promises, then you call your callback from where you call the method (don't pass a callback to the method).\r\nhttps://github.com/fgravin/ngeo/blob/9a95af08e373d1928394bf8cbec03ae0c3499739/contribs/gmf/src/services/themesservice.js#L103\r\n\r\nWatch doc https://docs.angularjs.org/api/ng/service/$q\r\n","created_at":"2015-12-10T14:09:07Z","updated_at":"2015-12-10T14:09:07Z","html_url":"https://github.com/camptocamp/ngeo/pull/462#discussion_r47229351","pull_request_url":"https://api.github.com/repos/camptocamp/ngeo/pulls/462","_links":{"self":{"href":"https://api.github.com/repos/camptocamp/ngeo/pulls/comments/47229351"},"html":{"href":"https://github.com/camptocamp/ngeo/pull/462#discussion_r47229351"},"pull_request":{"href":"https://api.github.com/repos/camptocamp/ngeo/pulls/462"}}},"pull_request":{"url":"https://api.github.com/repos/camptocamp/ngeo/pulls/462","id":53158080,"html_url":"https://github.com/camptocamp/ngeo/pull/462","diff_url":"https://github.com/camptocamp/ngeo/pull/462.diff","patch_url":"https://github.com/camptocamp/ngeo/pull/462.patch","issue_url":"https://api.github.com/repos/camptocamp/ngeo/issues/462","number":462,"state":"open","locked":false,"title":"[WIP] gmf-authentication","user":{"login":"adube","id":432436,"avatar_url":"https://avatars.githubusercontent.com/u/432436?v=3","gravatar_id":"","url":"https://api.github.com/users/adube","html_url":"https://github.com/adube","followers_url":"https://api.github.com/users/adube/followers","following_url":"https://api.github.com/users/adube/following{/other_user}","gists_url":"https://api.github.com/users/adube/gists{/gist_id}","starred_url":"https://api.github.com/users/adube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adube/subscriptions","organizations_url":"https://api.github.com/users/adube/orgs","repos_url":"https://api.github.com/users/adube/repos","events_url":"https://api.github.com/users/adube/events{/privacy}","received_events_url":"https://api.github.com/users/adube/received_events","type":"User","site_admin":false},"body":"This is a very early state of the `gmf-authentication` directive.  The idea is to collect comments from the core developers of ngeo/gmf.\r\n\r\nThe base idea is this: an `authentication` service, configured with a base url, will attempt to ask to the server upon creation if the user is connected or not.  The main `authentication` directive listens to the `load` event of the service and checks if the user is connected or not.  It will then decide which inner directive to include.\r\n\r\nIs this a good start ?","created_at":"2015-12-09T18:24:40Z","updated_at":"2015-12-10T14:09:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"79daa80ef2578340da6732d18df35215fba75788","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/camptocamp/ngeo/pulls/462/commits","review_comments_url":"https://api.github.com/repos/camptocamp/ngeo/pulls/462/comments","review_comment_url":"https://api.github.com/repos/camptocamp/ngeo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/camptocamp/ngeo/issues/462/comments","statuses_url":"https://api.github.com/repos/camptocamp/ngeo/statuses/f555c5d1e9897a7f3632a25e60698e7f1ca63ae0","head":{"label":"adube:gmf-authentication","ref":"gmf-authentication","sha":"f555c5d1e9897a7f3632a25e60698e7f1ca63ae0","user":{"login":"adube","id":432436,"avatar_url":"https://avatars.githubusercontent.com/u/432436?v=3","gravatar_id":"","url":"https://api.github.com/users/adube","html_url":"https://github.com/adube","followers_url":"https://api.github.com/users/adube/followers","following_url":"https://api.github.com/users/adube/following{/other_user}","gists_url":"https://api.github.com/users/adube/gists{/gist_id}","starred_url":"https://api.github.com/users/adube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adube/subscriptions","organizations_url":"https://api.github.com/users/adube/orgs","repos_url":"https://api.github.com/users/adube/repos","events_url":"https://api.github.com/users/adube/events{/privacy}","received_events_url":"https://api.github.com/users/adube/received_events","type":"User","site_admin":false},"repo":{"id":46440520,"name":"ngeo","full_name":"adube/ngeo","owner":{"login":"adube","id":432436,"avatar_url":"https://avatars.githubusercontent.com/u/432436?v=3","gravatar_id":"","url":"https://api.github.com/users/adube","html_url":"https://github.com/adube","followers_url":"https://api.github.com/users/adube/followers","following_url":"https://api.github.com/users/adube/following{/other_user}","gists_url":"https://api.github.com/users/adube/gists{/gist_id}","starred_url":"https://api.github.com/users/adube/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adube/subscriptions","organizations_url":"https://api.github.com/users/adube/orgs","repos_url":"https://api.github.com/users/adube/repos","events_url":"https://api.github.com/users/adube/events{/privacy}","received_events_url":"https://api.github.com/users/adube/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/adube/ngeo","description":"Library combining OpenLayers 3 and AngularJS","fork":true,"url":"https://api.github.com/repos/adube/ngeo","forks_url":"https://api.github.com/repos/adube/ngeo/forks","keys_url":"https://api.github.com/repos/adube/ngeo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/adube/ngeo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/adube/ngeo/teams","hooks_url":"https://api.github.com/repos/adube/ngeo/hooks","issue_events_url":"https://api.github.com/repos/adube/ngeo/issues/events{/number}","events_url":"https://api.github.com/repos/adube/ngeo/events","assignees_url":"https://api.github.com/repos/adube/ngeo/assignees{/user}","branches_url":"https://api.github.com/repos/adube/ngeo/branches{/branch}","tags_url":"https://api.github.com/repos/adube/ngeo/tags","blobs_url":"https://api.github.com/repos/adube/ngeo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/adube/ngeo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/adube/ngeo/git/refs{/sha}","trees_url":"https://api.github.com/repos/adube/ngeo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/adube/ngeo/statuses/{sha}","languages_url":"https://api.github.com/repos/adube/ngeo/languages","stargazers_url":"https://api.github.com/repos/adube/ngeo/stargazers","contributors_url":"https://api.github.com/repos/adube/ngeo/contributors","subscribers_url":"https://api.github.com/repos/adube/ngeo/subscribers","subscription_url":"https://api.github.com/repos/adube/ngeo/subscription","commits_url":"https://api.github.com/repos/adube/ngeo/commits{/sha}","git_commits_url":"https://api.github.com/repos/adube/ngeo/git/commits{/sha}","comments_url":"https://api.github.com/repos/adube/ngeo/comments{/number}","issue_comment_url":"https://api.github.com/repos/adube/ngeo/issues/comments{/number}","contents_url":"https://api.github.com/repos/adube/ngeo/contents/{+path}","compare_url":"https://api.github.com/repos/adube/ngeo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/adube/ngeo/merges","archive_url":"https://api.github.com/repos/adube/ngeo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/adube/ngeo/downloads","issues_url":"https://api.github.com/repos/adube/ngeo/issues{/number}","pulls_url":"https://api.github.com/repos/adube/ngeo/pulls{/number}","milestones_url":"https://api.github.com/repos/adube/ngeo/milestones{/number}","notifications_url":"https://api.github.com/repos/adube/ngeo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/adube/ngeo/labels{/name}","releases_url":"https://api.github.com/repos/adube/ngeo/releases{/id}","created_at":"2015-11-18T18:59:08Z","updated_at":"2015-11-18T18:59:11Z","pushed_at":"2015-12-09T21:00:39Z","git_url":"git://github.com/adube/ngeo.git","ssh_url":"git@github.com:adube/ngeo.git","clone_url":"https://github.com/adube/ngeo.git","svn_url":"https://github.com/adube/ngeo","homepage":null,"size":15070,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"camptocamp:master","ref":"master","sha":"edc283aceadcc07b4b3c2000297274519e2314bb","user":{"login":"camptocamp","id":28109,"avatar_url":"https://avatars.githubusercontent.com/u/28109?v=3","gravatar_id":"","url":"https://api.github.com/users/camptocamp","html_url":"https://github.com/camptocamp","followers_url":"https://api.github.com/users/camptocamp/followers","following_url":"https://api.github.com/users/camptocamp/following{/other_user}","gists_url":"https://api.github.com/users/camptocamp/gists{/gist_id}","starred_url":"https://api.github.com/users/camptocamp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/camptocamp/subscriptions","organizations_url":"https://api.github.com/users/camptocamp/orgs","repos_url":"https://api.github.com/users/camptocamp/repos","events_url":"https://api.github.com/users/camptocamp/events{/privacy}","received_events_url":"https://api.github.com/users/camptocamp/received_events","type":"Organization","site_admin":false},"repo":{"id":20212761,"name":"ngeo","full_name":"camptocamp/ngeo","owner":{"login":"camptocamp","id":28109,"avatar_url":"https://avatars.githubusercontent.com/u/28109?v=3","gravatar_id":"","url":"https://api.github.com/users/camptocamp","html_url":"https://github.com/camptocamp","followers_url":"https://api.github.com/users/camptocamp/followers","following_url":"https://api.github.com/users/camptocamp/following{/other_user}","gists_url":"https://api.github.com/users/camptocamp/gists{/gist_id}","starred_url":"https://api.github.com/users/camptocamp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/camptocamp/subscriptions","organizations_url":"https://api.github.com/users/camptocamp/orgs","repos_url":"https://api.github.com/users/camptocamp/repos","events_url":"https://api.github.com/users/camptocamp/events{/privacy}","received_events_url":"https://api.github.com/users/camptocamp/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/camptocamp/ngeo","description":"Library combining OpenLayers 3 and AngularJS","fork":false,"url":"https://api.github.com/repos/camptocamp/ngeo","forks_url":"https://api.github.com/repos/camptocamp/ngeo/forks","keys_url":"https://api.github.com/repos/camptocamp/ngeo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/camptocamp/ngeo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/camptocamp/ngeo/teams","hooks_url":"https://api.github.com/repos/camptocamp/ngeo/hooks","issue_events_url":"https://api.github.com/repos/camptocamp/ngeo/issues/events{/number}","events_url":"https://api.github.com/repos/camptocamp/ngeo/events","assignees_url":"https://api.github.com/repos/camptocamp/ngeo/assignees{/user}","branches_url":"https://api.github.com/repos/camptocamp/ngeo/branches{/branch}","tags_url":"https://api.github.com/repos/camptocamp/ngeo/tags","blobs_url":"https://api.github.com/repos/camptocamp/ngeo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/camptocamp/ngeo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/camptocamp/ngeo/git/refs{/sha}","trees_url":"https://api.github.com/repos/camptocamp/ngeo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/camptocamp/ngeo/statuses/{sha}","languages_url":"https://api.github.com/repos/camptocamp/ngeo/languages","stargazers_url":"https://api.github.com/repos/camptocamp/ngeo/stargazers","contributors_url":"https://api.github.com/repos/camptocamp/ngeo/contributors","subscribers_url":"https://api.github.com/repos/camptocamp/ngeo/subscribers","subscription_url":"https://api.github.com/repos/camptocamp/ngeo/subscription","commits_url":"https://api.github.com/repos/camptocamp/ngeo/commits{/sha}","git_commits_url":"https://api.github.com/repos/camptocamp/ngeo/git/commits{/sha}","comments_url":"https://api.github.com/repos/camptocamp/ngeo/comments{/number}","issue_comment_url":"https://api.github.com/repos/camptocamp/ngeo/issues/comments{/number}","contents_url":"https://api.github.com/repos/camptocamp/ngeo/contents/{+path}","compare_url":"https://api.github.com/repos/camptocamp/ngeo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/camptocamp/ngeo/merges","archive_url":"https://api.github.com/repos/camptocamp/ngeo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/camptocamp/ngeo/downloads","issues_url":"https://api.github.com/repos/camptocamp/ngeo/issues{/number}","pulls_url":"https://api.github.com/repos/camptocamp/ngeo/pulls{/number}","milestones_url":"https://api.github.com/repos/camptocamp/ngeo/milestones{/number}","notifications_url":"https://api.github.com/repos/camptocamp/ngeo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/camptocamp/ngeo/labels{/name}","releases_url":"https://api.github.com/repos/camptocamp/ngeo/releases{/id}","created_at":"2014-05-27T08:34:54Z","updated_at":"2015-12-04T10:42:33Z","pushed_at":"2015-12-10T14:02:05Z","git_url":"git://github.com/camptocamp/ngeo.git","ssh_url":"git@github.com:camptocamp/ngeo.git","clone_url":"https://github.com/camptocamp/ngeo.git","svn_url":"https://github.com/camptocamp/ngeo","homepage":null,"size":18848,"stargazers_count":51,"watchers_count":51,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":30,"mirror_url":null,"open_issues_count":34,"forks":30,"open_issues":34,"watchers":51,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/camptocamp/ngeo/pulls/462"},"html":{"href":"https://github.com/camptocamp/ngeo/pull/462"},"issue":{"href":"https://api.github.com/repos/camptocamp/ngeo/issues/462"},"comments":{"href":"https://api.github.com/repos/camptocamp/ngeo/issues/462/comments"},"review_comments":{"href":"https://api.github.com/repos/camptocamp/ngeo/pulls/462/comments"},"review_comment":{"href":"https://api.github.com/repos/camptocamp/ngeo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/camptocamp/ngeo/pulls/462/commits"},"statuses":{"href":"https://api.github.com/repos/camptocamp/ngeo/statuses/f555c5d1e9897a7f3632a25e60698e7f1ca63ae0"}}}}