5
5
import org .json .JSONException ;
6
6
import org .json .JSONObject ;
7
7
8
+ import android .app .Activity ;
9
+ import android .content .Intent ;
8
10
import android .util .Log ;
9
11
import android .widget .Toast ;
10
12
11
13
import com .zulip .android .activities .LoginActivity ;
14
+ import com .zulip .android .activities .ZulipActivity ;
12
15
import com .zulip .android .util .ZLog ;
13
16
import com .zulip .android .ZulipApp ;
14
17
15
18
public class AsyncLogin extends ZulipAsyncPushTask {
16
19
public static final String UNREGISTERED = "unregistered" ;
17
20
public static final String DISABLED = "disabled" ;
18
-
19
21
boolean startedFromAddRealm = false ;
20
22
LoginActivity context ;
21
23
boolean userDefinitelyInvalid = false ;
@@ -52,6 +54,8 @@ protected void onPostExecute(String result) {
52
54
53
55
if (obj .getString ("result" ).equals ("success" )) {
54
56
if (startedFromAddRealm ) {
57
+ loginThroughAddRealm (obj );
58
+ callback .onTaskComplete (result , obj );
55
59
} else {
56
60
this .app .setServerURL (serverURL );
57
61
this .app .setLoggedInApiKey (obj .getString ("api_key" ));
@@ -68,6 +72,20 @@ protected void onPostExecute(String result) {
68
72
Log .wtf ("login" , "We shouldn't have gotten this far." );
69
73
}
70
74
75
+ private void loginThroughAddRealm (JSONObject jsonObject ) {
76
+ try {
77
+ Intent intent = new Intent (context , ZulipActivity .class );
78
+ intent .putExtra ("realmName" , realmName );
79
+ intent .putExtra ("api_key" , jsonObject .getString ("api_key" ));
80
+ intent .putExtra ("email" , username );
81
+ intent .putExtra ("serverURL" , serverURL );
82
+ context .setResult (Activity .RESULT_OK , intent );
83
+ context .finish ();
84
+ } catch (JSONException e ) {
85
+ e .printStackTrace ();
86
+ }
87
+ }
88
+
71
89
@ Override
72
90
protected void handleHTTPError (final HttpResponseException e ) {
73
91
if (e .getStatusCode () == HttpStatus .SC_FORBIDDEN ) {
0 commit comments