Browse Source

Merge pull request #940 in BA/design from ~PAUL/design:master to master

* commit 'c348d42efc5daf54e6a9b5ecb5d8e17ca2514abb':
  build failed
master 20170619
superman 7 years ago
parent
commit
b852c38225
  1. 143
      designer_base/src/com/fr/design/extra/LoginWebBridge.java

143
designer_base/src/com/fr/design/extra/LoginWebBridge.java

@ -6,20 +6,17 @@ import com.fr.design.dialog.UIDialog;
import com.fr.design.extra.ucenter.Client; import com.fr.design.extra.ucenter.Client;
import com.fr.design.extra.ucenter.XMLHelper; import com.fr.design.extra.ucenter.XMLHelper;
import com.fr.design.gui.ilable.UILabel; import com.fr.design.gui.ilable.UILabel;
import com.fr.design.mainframe.DesignerContext;
import com.fr.general.SiteCenter; import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient; import com.fr.general.http.HttpClient;
import com.fr.json.JSONObject;
import com.fr.stable.EncodeConstants; import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
import javafx.scene.web.WebEngine; import javafx.scene.web.WebEngine;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
public class LoginWebBridge { public class LoginWebBridge {
@ -47,50 +44,48 @@ public class LoginWebBridge {
//用户名,密码为空 //用户名,密码为空
private static final String LOGIN_INFO_EMPTY = "-5"; private static final String LOGIN_INFO_EMPTY = "-5";
private static final int TIME_OUT = 10000; private static final int TIME_OUT = 10000;
private static final String LOGIN_SUCCESS = "ok";
private static final String LOGIN_FAILED = "failed";
private static com.fr.design.extra.LoginWebBridge helper; private static LoginWebBridge helper;
private UILabel pluginuiLabel;
private UIDialog uiDialog; private UIDialog uiDialog;
private UIDialog qqDialog;
private UILabel uiLabel; private UILabel uiLabel;
private String userName; private String userName;
public int getMessageCount() { public LoginWebBridge() {
return messageCount; String username = DesignerEnvManager.getEnvManager().getBBSName();
} setUserName(username, uiLabel);
/**
* 测试论坛网络连接
* @return
*/
private boolean testConnection() {
HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.test"));
return client.isServerAlive();
} }
public static com.fr.design.extra.LoginWebBridge getHelper() { public static LoginWebBridge getHelper() {
if (helper != null) { if (helper != null) {
return helper; return helper;
} }
synchronized (com.fr.design.extra.LoginWebBridge.class) { synchronized (LoginWebBridge.class) {
if (helper == null) { if (helper == null) {
helper = new com.fr.design.extra.LoginWebBridge(); helper = new LoginWebBridge();
} }
return helper; return helper;
} }
} }
public static com.fr.design.extra.LoginWebBridge getHelper(WebEngine webEngine) { public int getMessageCount() {
getHelper(); return messageCount;
helper.setEngine(webEngine);
return helper;
} }
private WebEngine webEngine; public void setUILabelInPlugin(UILabel uiLabel) {
this.pluginuiLabel = uiLabel;
}
public void setEngine(WebEngine webEngine) { public void setQqDialog(UIDialog qqDialog) {
this.webEngine = webEngine; closeQQWindow();
this.qqDialog = qqDialog;
} }
public void setDialogHandle(UIDialog uiDialog) { public void setDialogHandle(UIDialog uiDialog) {
closeWindow();
this.uiDialog = uiDialog; this.uiDialog = uiDialog;
} }
@ -98,28 +93,35 @@ public class LoginWebBridge {
this.uiLabel = uiLabel; this.uiLabel = uiLabel;
} }
public LoginWebBridge() {
String username = DesignerEnvManager.getEnvManager().getBBSName();
setUserName(username, uiLabel);
}
/** /**
* 设置显示的用户名 * 设置显示的用户名
*
* @param userName 登录用户名 * @param userName 登录用户名
* @param label label显示 * @param label label显示
*/ */
public void setUserName(String userName, UILabel label) { public void setUserName(String userName, UILabel label) {
if (uiLabel == null) { if (uiLabel == null) {
this.uiLabel = label; this.uiLabel = label;
} }
if(StringUtils.isEmpty(userName)){ if (StringUtils.isEmpty(userName)) {
return; return;
} }
this.userName = userName; this.userName = userName;
} }
/**
* 测试论坛网络连接
*
* @return
*/
private boolean testConnection() {
HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.test"));
return client.isServerAlive();
}
/** /**
* 设置获取的消息长度并设置显示 * 设置获取的消息长度并设置显示
*
* @param count * @param count
*/ */
public void setMessageCount(int count) { public void setMessageCount(int count) {
@ -137,7 +139,7 @@ public class LoginWebBridge {
uiLabel.setText(sb.toString()); uiLabel.setText(sb.toString());
} }
private String encode(String str){ private String encode(String str) {
try { try {
return URLEncoder.encode(str, EncodeConstants.ENCODING_UTF_8); return URLEncoder.encode(str, EncodeConstants.ENCODING_UTF_8);
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
@ -145,7 +147,7 @@ public class LoginWebBridge {
} }
} }
private void sleep(long millis){ private void sleep(long millis) {
try { try {
Thread.sleep(millis); Thread.sleep(millis);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -159,7 +161,7 @@ public class LoginWebBridge {
public void registerHref() { public void registerHref() {
try { try {
Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.register"))); Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.register")));
}catch (Exception e) { } catch (Exception e) {
FRContext.getLogger().info(e.getMessage()); FRContext.getLogger().info(e.getMessage());
} }
} }
@ -170,13 +172,14 @@ public class LoginWebBridge {
public void forgetHref() { public void forgetHref() {
try { try {
Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.reset"))); Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.reset")));
}catch (Exception e) { } catch (Exception e) {
FRContext.getLogger().info(e.getMessage()); FRContext.getLogger().info(e.getMessage());
} }
} }
/** /**
* 设计器端的用户登录 * 设计器端的用户登录
*
* @param username 用户名 * @param username 用户名
* @param password 密码 * @param password 密码
* @return 登录信息标志 * @return 登录信息标志
@ -187,9 +190,10 @@ public class LoginWebBridge {
/** /**
* 插件管理的用户登录部分 * 插件管理的用户登录部分
*
* @param username 用户名 * @param username 用户名
* @param password 密码 * @param password 密码
* @param uiLabel 设计器端的label * @param uiLabel 设计器端的label
* @return 登录信息标志 * @return 登录信息标志
*/ */
public String pluginManageLogin(String username, String password, UILabel uiLabel) { public String pluginManageLogin(String username, String password, UILabel uiLabel) {
@ -198,9 +202,10 @@ public class LoginWebBridge {
/** /**
* 登录操作 * 登录操作
*
* @param username 用户名 * @param username 用户名
* @param password 密码 * @param password 密码
* @param uiLabel 两边的label显示 * @param uiLabel 两边的label显示
* @return 登录信息标志 * @return 登录信息标志
*/ */
public String login(String username, String password, UILabel uiLabel) { public String login(String username, String password, UILabel uiLabel) {
@ -231,8 +236,8 @@ public class LoginWebBridge {
/** /**
* 更新后台的用户信息 * 更新后台的用户信息
*
* @param username 用户名 * @param username 用户名
* @param password 密码
*/ */
public void updateUserInfo(String username) { public void updateUserInfo(String username) {
this.userName = username; this.userName = username;
@ -240,6 +245,7 @@ public class LoginWebBridge {
/** /**
* 关闭窗口并且重新赋值 * 关闭窗口并且重新赋值
*
* @param username * @param username
*/ */
public void loginSuccess(String username, UILabel uiLabel) { public void loginSuccess(String username, UILabel uiLabel) {
@ -254,13 +260,7 @@ public class LoginWebBridge {
SwingUtilities.invokeLater(new Runnable() { SwingUtilities.invokeLater(new Runnable() {
@Override @Override
public void run() { public void run() {
//弹出qq登录的窗口 WebViewDlgHelper.createQQLoginDialog();
QQLoginPane managerPane = new QQLoginPane();
UIDialog qqlog = new QQLoginDialog(DesignerContext.getDesignerFrame(),managerPane);
QQLoginWebBridge.getHelper().setDialogHandle(uiDialog);
QQLoginWebBridge.getHelper().setQQDialogHandle(qqlog);
QQLoginWebBridge.getHelper().setUILabel(uiLabel);
qqlog.setVisible(true);
} }
}); });
} }
@ -286,12 +286,55 @@ public class LoginWebBridge {
} else { } else {
return UNKNOWN_ERROR;//未知错误,-3 return UNKNOWN_ERROR;//未知错误,-3
} }
}else { } else {
return NET_FAILED; return NET_FAILED;
} }
}catch (Exception e) { } catch (Exception e) {
FRContext.getLogger().info(e.getMessage()); FRContext.getLogger().info(e.getMessage());
} }
return UNKNOWN_ERROR; return UNKNOWN_ERROR;
} }
/**
* 关闭QQ授权窗口
*/
public void closeQQWindow() {
if (qqDialog != null) {
qqDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
qqDialog.setVisible(false);
}
}
/**
* 获取用户信息
*
* @param userInfo
*/
public void getLoginInfo(String userInfo) {
org.json.JSONObject jo = new org.json.JSONObject(userInfo);
String status = jo.get("status").toString();
if (status.equals(LOGIN_SUCCESS)) {
String username = jo.get("username").toString();
int uid = Integer.parseInt(jo.get("uid") == null ? "" : jo.get("uid").toString());
closeWindow();
closeQQWindow();
pluginuiLabel.setText(username);
DesignerEnvManager.getEnvManager().setBBSName(username);
DesignerEnvManager.getEnvManager().setBbsUid(uid);
DesignerEnvManager.getEnvManager().setInShowBBsName(username);
} else if (status.equals(LOGIN_FAILED)) {
//账号没有QQ授权
closeQQWindow();
try {
Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("QQ_binding")));
} catch (Exception exp) {
}
}
}
public void openUrlAtLocalWebBrowser(WebEngine eng, String url) {
if (url.indexOf("qqLogin.html") > 0) {
return;
}
}
} }
Loading…
Cancel
Save