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.XMLHelper;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.mainframe.DesignerContext;
import com.fr.general.SiteCenter;
import com.fr.general.http.HttpClient;
import com.fr.json.JSONObject;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils;
import javafx.scene.web.WebEngine;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import javax.swing.*;
import java.awt.*;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.LinkedList;
public class LoginWebBridge {
@ -47,50 +44,48 @@ public class LoginWebBridge {
//用户名,密码为空
private static final String LOGIN_INFO_EMPTY = "-5";
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 qqDialog;
private UILabel uiLabel;
private String userName;
public int getMessageCount() {
return messageCount;
}
/**
* 测试论坛网络连接
* @return
*/
private boolean testConnection() {
HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.test"));
return client.isServerAlive();
public LoginWebBridge() {
String username = DesignerEnvManager.getEnvManager().getBBSName();
setUserName(username, uiLabel);
}
public static com.fr.design.extra.LoginWebBridge getHelper() {
public static LoginWebBridge getHelper() {
if (helper != null) {
return helper;
}
synchronized (com.fr.design.extra.LoginWebBridge.class) {
synchronized (LoginWebBridge.class) {
if (helper == null) {
helper = new com.fr.design.extra.LoginWebBridge();
helper = new LoginWebBridge();
}
return helper;
}
}
public static com.fr.design.extra.LoginWebBridge getHelper(WebEngine webEngine) {
getHelper();
helper.setEngine(webEngine);
return helper;
public int getMessageCount() {
return messageCount;
}
private WebEngine webEngine;
public void setUILabelInPlugin(UILabel uiLabel) {
this.pluginuiLabel = uiLabel;
}
public void setEngine(WebEngine webEngine) {
this.webEngine = webEngine;
public void setQqDialog(UIDialog qqDialog) {
closeQQWindow();
this.qqDialog = qqDialog;
}
public void setDialogHandle(UIDialog uiDialog) {
closeWindow();
this.uiDialog = uiDialog;
}
@ -98,28 +93,35 @@ public class LoginWebBridge {
this.uiLabel = uiLabel;
}
public LoginWebBridge() {
String username = DesignerEnvManager.getEnvManager().getBBSName();
setUserName(username, uiLabel);
}
/**
* 设置显示的用户名
*
* @param userName 登录用户名
* @param label label显示
* @param label label显示
*/
public void setUserName(String userName, UILabel label) {
if (uiLabel == null) {
this.uiLabel = label;
}
if(StringUtils.isEmpty(userName)){
if (StringUtils.isEmpty(userName)) {
return;
}
this.userName = userName;
}
/**
* 测试论坛网络连接
*
* @return
*/
private boolean testConnection() {
HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.test"));
return client.isServerAlive();
}
/**
* 设置获取的消息长度并设置显示
*
* @param count
*/
public void setMessageCount(int count) {
@ -137,7 +139,7 @@ public class LoginWebBridge {
uiLabel.setText(sb.toString());
}
private String encode(String str){
private String encode(String str) {
try {
return URLEncoder.encode(str, EncodeConstants.ENCODING_UTF_8);
} catch (UnsupportedEncodingException e) {
@ -145,7 +147,7 @@ public class LoginWebBridge {
}
}
private void sleep(long millis){
private void sleep(long millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
@ -159,7 +161,7 @@ public class LoginWebBridge {
public void registerHref() {
try {
Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.register")));
}catch (Exception e) {
} catch (Exception e) {
FRContext.getLogger().info(e.getMessage());
}
}
@ -170,13 +172,14 @@ public class LoginWebBridge {
public void forgetHref() {
try {
Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.reset")));
}catch (Exception e) {
} catch (Exception e) {
FRContext.getLogger().info(e.getMessage());
}
}
/**
* 设计器端的用户登录
*
* @param username 用户名
* @param password 密码
* @return 登录信息标志
@ -187,9 +190,10 @@ public class LoginWebBridge {
/**
* 插件管理的用户登录部分
*
* @param username 用户名
* @param password 密码
* @param uiLabel 设计器端的label
* @param uiLabel 设计器端的label
* @return 登录信息标志
*/
public String pluginManageLogin(String username, String password, UILabel uiLabel) {
@ -198,9 +202,10 @@ public class LoginWebBridge {
/**
* 登录操作
*
* @param username 用户名
* @param password 密码
* @param uiLabel 两边的label显示
* @param uiLabel 两边的label显示
* @return 登录信息标志
*/
public String login(String username, String password, UILabel uiLabel) {
@ -231,8 +236,8 @@ public class LoginWebBridge {
/**
* 更新后台的用户信息
*
* @param username 用户名
* @param password 密码
*/
public void updateUserInfo(String username) {
this.userName = username;
@ -240,6 +245,7 @@ public class LoginWebBridge {
/**
* 关闭窗口并且重新赋值
*
* @param username
*/
public void loginSuccess(String username, UILabel uiLabel) {
@ -254,13 +260,7 @@ public class LoginWebBridge {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
//弹出qq登录的窗口
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);
WebViewDlgHelper.createQQLoginDialog();
}
});
}
@ -286,12 +286,55 @@ public class LoginWebBridge {
} else {
return UNKNOWN_ERROR;//未知错误,-3
}
}else {
} else {
return NET_FAILED;
}
}catch (Exception e) {
} catch (Exception e) {
FRContext.getLogger().info(e.getMessage());
}
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