diff --git a/README.md b/README.md index 35f18e034..2dc5140ef 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,9 @@ ### Coding Android客户端代码说明 - - - -##编译环境 +## 编译环境 Android Studio 3.1.3,根据 `variants` 选择编译企业版或个人版。修改 `gradle.properties.sample` 为 `gradle.properties` 并修改文件中 `keystore` 相关的环境变量,编译企业版的时候,`DEV_ENTERPRISE` 设置为 `true` ,因为用 `gradle` 引用的许多第三方库,所以第一次加载会有点慢,加载完毕后要 `build` 一下,这些带下划线的类(比如 `MainActivity_`)会在build之后自动生成。 -##包说明 +## 包说明 >common 基类和工具类 >>comment 评论区 >>enter 输入框 @@ -24,7 +21,7 @@ Android Studio 3.1.3,根据 `variants` 选择编译企业版或个人版。修 >third 一些第三方代码 >user 好友界面 -##一些觉得有必要提一下的 +## 一些觉得有必要提一下的 因为不想写一堆绑定函数,所以项目用了 [androidannotations](https://github.com/excilys/androidannotations),如果以前没用过最好先看看。 显示图片用的[universal-image-loader](https://github.com/nostra13/Android-Universal-Image-Loader),网络库用的[android-async-http](https://github.com/loopj/android-async-http),因为登录以后保存的cookie都在[android-async-http](https://github.com/loopj/android-async-http),有些图片需要登录后的cookie才能取到(例如项目文件里面的图片),这种情况就会用先用[android-async-http](https://github.com/loopj/android-async-http)下载图片(AttachmentimagePagerFragment.java)。 @@ -61,8 +58,8 @@ Android Studio 3.1.3,根据 `variants` 选择编译企业版或个人版。修 - 推送用的是腾讯的信鸽,之前用的是umeng推送,但有延迟有时候很大,而且用新账号登录后还能收到旧账号的推送,多种原因之下就换了。 -##用到的一些开源库说明 +## 用到的一些开源库说明 见我写的[blog](http://blog.coding.net/blog/android-open-source-library) -##License +## License Coding is available under the MIT license. See the LICENSE file for more info. \ No newline at end of file diff --git a/app/src/enterprise/java/net/coding/program/user/EnterpriseLoginActivity.java b/app/src/enterprise/java/net/coding/program/user/EnterpriseLoginActivity.java index d2f973709..d68152719 100644 --- a/app/src/enterprise/java/net/coding/program/user/EnterpriseLoginActivity.java +++ b/app/src/enterprise/java/net/coding/program/user/EnterpriseLoginActivity.java @@ -76,9 +76,13 @@ public class EnterpriseLoginActivity extends BaseActivity { private final String CLOSE_2FA_TIP = "关闭两步验证"; private String TAG_HOST_NEED_CAPTCHA = "TAG_HOST_NEED_CAPTCHA"; private final String TAG_LOGIN = "TAG_LOGIN"; + private final String CE_INFO = "CE_INFO"; private static final int RESULT_CLOSE = 100; + private String ssoType = "default"; + private boolean ssoEnabled = false; + @Extra Uri background; @@ -299,11 +303,8 @@ public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Thr @Click protected final void loginButton() { - if (layout2fa.getVisibility() == View.GONE) { - login(); - } else { - login2fa(); - } + updateGlobalHost(); + getNetwork(Global.HOST_API + "/enterprise/info/ce", CE_INFO); } private void login2fa() { @@ -321,7 +322,7 @@ private void login2fa() { Global.popSoftkeyboard(this, edit2FA, false); } - private void login() { + private void login(boolean sha1) { try { String name = editName.getTextString(); String password = editPassword.getTextString(); @@ -340,7 +341,11 @@ private void login() { RequestParams params = new RequestParams(); params.put("account", name); - params.put("password", SimpleSHA1.sha1(password)); + if (sha1) { + params.put("password", SimpleSHA1.sha1(password)); + } else { + params.put("password", password); + } if (captchaLayout.getVisibility() == View.VISIBLE) { params.put("j_captcha", captcha); } @@ -359,6 +364,10 @@ private void login() { } } + private void login() { + login(true); + } + private void updateGlobalHost() { if (isPrivate) { EnterpriseApp.setPrivateHost(privateHost.getTextString()); @@ -455,6 +464,25 @@ public void parseJson(int code, JSONObject respanse, String tag, int pos, Object loginFail(code, respanse, true); } + } else if (tag.equals(CE_INFO)) { + if (code == 0) { + try { + ssoEnabled = respanse.getJSONObject("data").getJSONObject("settings").getBoolean("ssoEnabled"); + ssoType = respanse.getJSONObject("data").getJSONObject("settings").getString("ssoType"); + } catch (Exception e) { + ssoEnabled = false; + ssoType = "default"; + } + if (layout2fa.getVisibility() == View.GONE) { + if (ssoEnabled && "ldap".equals(ssoType)) { + login(false); + } else { + login(); + } + } else { + login2fa(); + } + } } else if (tag.equals(TAG_HOST_USER_NEED_2FA)) { if (code == 0) { loginSuccess(respanse); diff --git a/app/src/enterprise/res/layout/activity_enterprise_guide.xml b/app/src/enterprise/res/layout/activity_enterprise_guide.xml index ef583a67a..506828069 100644 --- a/app/src/enterprise/res/layout/activity_enterprise_guide.xml +++ b/app/src/enterprise/res/layout/activity_enterprise_guide.xml @@ -155,6 +155,7 @@ android:text="企业账号登录" android:textColor="@color/white" android:textSize="17sp" + android:visibility="invisible" app:rv_backgroundColor="@color/font_2" app:rv_cornerRadius="4dp" />