{"action":"created","comment":{"url":"https://api.github.com/repos/edx/edx-app-android/pulls/comments/67011785","id":67011785,"diff_hunk":"@@ -1,38 +1,173 @@\n package org.edx.mobile.authentication;\n \n+import android.os.Bundle;\n import android.support.annotation.NonNull;\n \n import com.google.inject.Inject;\n import com.google.inject.Singleton;\n \n+import org.edx.mobile.exception.AuthException;\n+import org.edx.mobile.http.HttpResponseStatusException;\n import org.edx.mobile.http.RetroHttpException;\n-import org.edx.mobile.logger.Logger;\n+import org.edx.mobile.model.api.RegisterResponse;\n+import org.edx.mobile.module.analytics.ISegment;\n+import org.edx.mobile.module.notification.NotificationDelegate;\n+import org.edx.mobile.module.prefs.LoginPrefs;\n+import org.edx.mobile.services.ServiceManager;\n import org.edx.mobile.util.Config;\n+import org.edx.mobile.util.observer.BasicObservable;\n+import org.edx.mobile.util.observer.Observable;\n \n import retrofit.RestAdapter;\n \n-/**\n- * Created by cleeedx on 4/12/16.\n- */\n-\n @Singleton\n public class LoginAPI {\n \n     @NonNull\n     private final LoginService loginService;\n \n-    @Inject\n-    Config config;\n+    @NonNull\n+    private final Config config;\n+\n+    @NonNull\n+    private final LoginPrefs loginPrefs;\n+\n+    @NonNull\n+    private final ServiceManager serviceManager;\n+\n+    @NonNull\n+    private final ISegment segment;\n+\n+    @NonNull\n+    private final NotificationDelegate notificationDelegate;\n+\n+    @NonNull\n+    private final BasicObservable<LogInEvent> logInEvents = new BasicObservable<>();\n \n     @Inject\n-    public LoginAPI(@NonNull RestAdapter restAdapter) {\n+    public LoginAPI(@NonNull RestAdapter restAdapter, @NonNull Config config, @NonNull LoginPrefs loginPrefs, @NonNull ServiceManager serviceManager, @NonNull ISegment segment, @NonNull NotificationDelegate notificationDelegate) {\n+        this.config = config;\n+        this.loginPrefs = loginPrefs;\n+        this.serviceManager = serviceManager;\n+        this.segment = segment;\n+        this.notificationDelegate = notificationDelegate;\n         loginService = restAdapter.create(LoginService.class);\n     }\n \n+    @NonNull\n     public AuthResponse getAccessToken(@NonNull String username,\n                                        @NonNull String password) throws RetroHttpException {\n         String grantType = \"password\";\n         String clientID = config.getOAuthClientId();\n         return loginService.getAccessToken(grantType, clientID, username, password);\n     }\n+\n+    @NonNull\n+    public AuthResponse logInUsingEmail(String email, String password) throws Exception {\n+        try {\n+            final AuthResponse response = getAccessToken(email, password);\n+            if (!response.isSuccess()) {\n+                throw new AuthException(response.error);\n+            }\n+            finishLogIn(response, LoginPrefs.AuthBackend.PASSWORD, email.trim());\n+            return response;\n+        } catch (HttpResponseStatusException ex) {\n+            if (ex.getStatusCode() >= 400 && ex.getStatusCode() < 500) {\n+                throw new AuthException(ex);\n+            }\n+            throw ex;\n+        }\n+    }\n+\n+    @NonNull\n+    public AuthResponse logInUsingFacebook(String accessToken) throws Exception {\n+        final AuthResponse response = serviceManager.loginByFacebook(accessToken);","path":"VideoLocker/src/main/java/org/edx/mobile/authentication/LoginAPI.java","position":92,"original_position":92,"commit_id":"bbe2f332dde88ef58b5d0cf8b6617d49fb918816","original_commit_id":"bbe2f332dde88ef58b5d0cf8b6617d49fb918816","user":{"login":"bguertin","id":1685613,"avatar_url":"https://avatars.githubusercontent.com/u/1685613?v=3","gravatar_id":"","url":"https://api.github.com/users/bguertin","html_url":"https://github.com/bguertin","followers_url":"https://api.github.com/users/bguertin/followers","following_url":"https://api.github.com/users/bguertin/following{/other_user}","gists_url":"https://api.github.com/users/bguertin/gists{/gist_id}","starred_url":"https://api.github.com/users/bguertin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bguertin/subscriptions","organizations_url":"https://api.github.com/users/bguertin/orgs","repos_url":"https://api.github.com/users/bguertin/repos","events_url":"https://api.github.com/users/bguertin/events{/privacy}","received_events_url":"https://api.github.com/users/bguertin/received_events","type":"User","site_admin":false},"body":"Hmm, you mean move the calls into `LoginService` and out of ServiceManager? that's a good idea","created_at":"2016-06-14T17:00:18Z","updated_at":"2016-06-14T17:00:18Z","html_url":"https://github.com/edx/edx-app-android/pull/728#discussion_r67011785","pull_request_url":"https://api.github.com/repos/edx/edx-app-android/pulls/728","_links":{"self":{"href":"https://api.github.com/repos/edx/edx-app-android/pulls/comments/67011785"},"html":{"href":"https://github.com/edx/edx-app-android/pull/728#discussion_r67011785"},"pull_request":{"href":"https://api.github.com/repos/edx/edx-app-android/pulls/728"}}},"pull_request":{"url":"https://api.github.com/repos/edx/edx-app-android/pulls/728","id":72090463,"html_url":"https://github.com/edx/edx-app-android/pull/728","diff_url":"https://github.com/edx/edx-app-android/pull/728.diff","patch_url":"https://github.com/edx/edx-app-android/pull/728.patch","issue_url":"https://api.github.com/repos/edx/edx-app-android/issues/728","number":728,"state":"open","locked":false,"title":"Refactor login preference handling into its own class","user":{"login":"bguertin","id":1685613,"avatar_url":"https://avatars.githubusercontent.com/u/1685613?v=3","gravatar_id":"","url":"https://api.github.com/users/bguertin","html_url":"https://github.com/bguertin","followers_url":"https://api.github.com/users/bguertin/followers","following_url":"https://api.github.com/users/bguertin/following{/other_user}","gists_url":"https://api.github.com/users/bguertin/gists{/gist_id}","starred_url":"https://api.github.com/users/bguertin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bguertin/subscriptions","organizations_url":"https://api.github.com/users/bguertin/orgs","repos_url":"https://api.github.com/users/bguertin/repos","events_url":"https://api.github.com/users/bguertin/events{/privacy}","received_events_url":"https://api.github.com/users/bguertin/received_events","type":"User","site_admin":false},"body":"So, I don't like how so many classes are touching the same preference file ad-hoc. No behaviour change is intended by this cleanup, except for bug-fixes.\r\n\r\n- Updated every reference to the \"LOGIN\" preference file to go through a single class, `LoginPrefs`.\r\n- Removed the login-specific methods from `PrefManager`, since they are now all handled by `LoginPrefs`\r\n- Fixed a bug where logging in via Facebook or Google would be recorded to Segment.IO as logging in via password.\r\n- Removed code (that never ran) that seems to have been trying to force users to log out if they logged in via Facebook/Google. I don't know what it's purpose was, but it was not working anyway.\r\n- Deleting that code also fixes a bug where the last activity instance was forced to remain in memory.\r\n- Also fixed https://openedx.atlassian.net/browse/MA-2489\r\n\r\nTODO:\r\n - [x] Manually test Google login / registration\r\n - [x] Manually test Facebook login / registration\r\n - [x] Manually test Email login / registration\r\n - [x] Manually Test OAuth token refresh","created_at":"2016-05-31T21:40:15Z","updated_at":"2016-06-14T17:00:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"83ddc244aaad027153b725a48f3cc439073f7fd0","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/edx/edx-app-android/pulls/728/commits","review_comments_url":"https://api.github.com/repos/edx/edx-app-android/pulls/728/comments","review_comment_url":"https://api.github.com/repos/edx/edx-app-android/pulls/comments{/number}","comments_url":"https://api.github.com/repos/edx/edx-app-android/issues/728/comments","statuses_url":"https://api.github.com/repos/edx/edx-app-android/statuses/bbe2f332dde88ef58b5d0cf8b6617d49fb918816","head":{"label":"edx:bguertin/login_prefs","ref":"bguertin/login_prefs","sha":"bbe2f332dde88ef58b5d0cf8b6617d49fb918816","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":29251742,"name":"edx-app-android","full_name":"edx/edx-app-android","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-app-android","description":"","fork":false,"url":"https://api.github.com/repos/edx/edx-app-android","forks_url":"https://api.github.com/repos/edx/edx-app-android/forks","keys_url":"https://api.github.com/repos/edx/edx-app-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-app-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-app-android/teams","hooks_url":"https://api.github.com/repos/edx/edx-app-android/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-app-android/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-app-android/events","assignees_url":"https://api.github.com/repos/edx/edx-app-android/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-app-android/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-app-android/tags","blobs_url":"https://api.github.com/repos/edx/edx-app-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-app-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-app-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-app-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-app-android/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-app-android/languages","stargazers_url":"https://api.github.com/repos/edx/edx-app-android/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-app-android/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-app-android/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-app-android/subscription","commits_url":"https://api.github.com/repos/edx/edx-app-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-app-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-app-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-app-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-app-android/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-app-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-app-android/merges","archive_url":"https://api.github.com/repos/edx/edx-app-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-app-android/downloads","issues_url":"https://api.github.com/repos/edx/edx-app-android/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-app-android/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-app-android/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-app-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-app-android/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-app-android/releases{/id}","deployments_url":"https://api.github.com/repos/edx/edx-app-android/deployments","created_at":"2015-01-14T15:49:47Z","updated_at":"2016-06-09T10:31:39Z","pushed_at":"2016-06-14T16:51:24Z","git_url":"git://github.com/edx/edx-app-android.git","ssh_url":"git@github.com:edx/edx-app-android.git","clone_url":"https://github.com/edx/edx-app-android.git","svn_url":"https://github.com/edx/edx-app-android","homepage":null,"size":22734,"stargazers_count":79,"watchers_count":79,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":94,"mirror_url":null,"open_issues_count":8,"forks":94,"open_issues":8,"watchers":79,"default_branch":"master"}},"base":{"label":"edx:master","ref":"master","sha":"d22ad4992491215d7a5d569bf752d8146ed9d1ad","user":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"repo":{"id":29251742,"name":"edx-app-android","full_name":"edx/edx-app-android","owner":{"login":"edx","id":3179841,"avatar_url":"https://avatars.githubusercontent.com/u/3179841?v=3","gravatar_id":"","url":"https://api.github.com/users/edx","html_url":"https://github.com/edx","followers_url":"https://api.github.com/users/edx/followers","following_url":"https://api.github.com/users/edx/following{/other_user}","gists_url":"https://api.github.com/users/edx/gists{/gist_id}","starred_url":"https://api.github.com/users/edx/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/edx/subscriptions","organizations_url":"https://api.github.com/users/edx/orgs","repos_url":"https://api.github.com/users/edx/repos","events_url":"https://api.github.com/users/edx/events{/privacy}","received_events_url":"https://api.github.com/users/edx/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/edx/edx-app-android","description":"","fork":false,"url":"https://api.github.com/repos/edx/edx-app-android","forks_url":"https://api.github.com/repos/edx/edx-app-android/forks","keys_url":"https://api.github.com/repos/edx/edx-app-android/keys{/key_id}","collaborators_url":"https://api.github.com/repos/edx/edx-app-android/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/edx/edx-app-android/teams","hooks_url":"https://api.github.com/repos/edx/edx-app-android/hooks","issue_events_url":"https://api.github.com/repos/edx/edx-app-android/issues/events{/number}","events_url":"https://api.github.com/repos/edx/edx-app-android/events","assignees_url":"https://api.github.com/repos/edx/edx-app-android/assignees{/user}","branches_url":"https://api.github.com/repos/edx/edx-app-android/branches{/branch}","tags_url":"https://api.github.com/repos/edx/edx-app-android/tags","blobs_url":"https://api.github.com/repos/edx/edx-app-android/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/edx/edx-app-android/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/edx/edx-app-android/git/refs{/sha}","trees_url":"https://api.github.com/repos/edx/edx-app-android/git/trees{/sha}","statuses_url":"https://api.github.com/repos/edx/edx-app-android/statuses/{sha}","languages_url":"https://api.github.com/repos/edx/edx-app-android/languages","stargazers_url":"https://api.github.com/repos/edx/edx-app-android/stargazers","contributors_url":"https://api.github.com/repos/edx/edx-app-android/contributors","subscribers_url":"https://api.github.com/repos/edx/edx-app-android/subscribers","subscription_url":"https://api.github.com/repos/edx/edx-app-android/subscription","commits_url":"https://api.github.com/repos/edx/edx-app-android/commits{/sha}","git_commits_url":"https://api.github.com/repos/edx/edx-app-android/git/commits{/sha}","comments_url":"https://api.github.com/repos/edx/edx-app-android/comments{/number}","issue_comment_url":"https://api.github.com/repos/edx/edx-app-android/issues/comments{/number}","contents_url":"https://api.github.com/repos/edx/edx-app-android/contents/{+path}","compare_url":"https://api.github.com/repos/edx/edx-app-android/compare/{base}...{head}","merges_url":"https://api.github.com/repos/edx/edx-app-android/merges","archive_url":"https://api.github.com/repos/edx/edx-app-android/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/edx/edx-app-android/downloads","issues_url":"https://api.github.com/repos/edx/edx-app-android/issues{/number}","pulls_url":"https://api.github.com/repos/edx/edx-app-android/pulls{/number}","milestones_url":"https://api.github.com/repos/edx/edx-app-android/milestones{/number}","notifications_url":"https://api.github.com/repos/edx/edx-app-android/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/edx/edx-app-android/labels{/name}","releases_url":"https://api.github.com/repos/edx/edx-app-android/releases{/id}","deployments_url":"https://api.github.com/repos/edx/edx-app-android/deployments","created_at":"2015-01-14T15:49:47Z","updated_at":"2016-06-09T10:31:39Z","pushed_at":"2016-06-14T16:51:24Z","git_url":"git://github.com/edx/edx-app-android.git","ssh_url":"git@github.com:edx/edx-app-android.git","clone_url":"https://github.com/edx/edx-app-android.git","svn_url":"https://github.com/edx/edx-app-android","homepage":null,"size":22734,"stargazers_count":79,"watchers_count":79,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":94,"mirror_url":null,"open_issues_count":8,"forks":94,"open_issues":8,"watchers":79,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/edx/edx-app-android/pulls/728"},"html":{"href":"https://github.com/edx/edx-app-android/pull/728"},"issue":{"href":"https://api.github.com/repos/edx/edx-app-android/issues/728"},"comments":{"href":"https://api.github.com/repos/edx/edx-app-android/issues/728/comments"},"review_comments":{"href":"https://api.github.com/repos/edx/edx-app-android/pulls/728/comments"},"review_comment":{"href":"https://api.github.com/repos/edx/edx-app-android/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/edx/edx-app-android/pulls/728/commits"},"statuses":{"href":"https://api.github.com/repos/edx/edx-app-android/statuses/bbe2f332dde88ef58b5d0cf8b6617d49fb918816"}}}}
{"actor":{"display_login":"bguertin"}}