superman
8 years ago
15 changed files with 729 additions and 38 deletions
@ -0,0 +1,35 @@
|
||||
package com.fr.design.mainframe.bbs; |
||||
|
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.dialog.UIDialog; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import com.fr.general.Inter; |
||||
import com.fr.general.SiteCenter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
/** |
||||
* Created by zhaohehe on 16/7/26. |
||||
*/ |
||||
public class LoginDialog extends UIDialog { |
||||
private static final Dimension DEFAULT_SHOP = new Dimension(404, 234); |
||||
|
||||
public LoginDialog(Frame frame, BasicPane pane) { |
||||
super(frame); |
||||
setUndecorated(true); |
||||
JPanel panel = (JPanel) getContentPane(); |
||||
panel.setLayout(new BorderLayout()); |
||||
add(pane, BorderLayout.CENTER); |
||||
setSize(DEFAULT_SHOP); |
||||
GUICoreUtils.centerWindow(this); |
||||
setResizable(false); |
||||
setTitle(Inter.getLocText("FR-Designer-Plugin_Manager")); |
||||
} |
||||
|
||||
@Override |
||||
public void checkValid() throws Exception { |
||||
} |
||||
} |
@ -0,0 +1,8 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
/** |
||||
* Created by lp on 2016/8/16. |
||||
*/ |
||||
public interface LoginContextListener { |
||||
void showLoginContext(); |
||||
} |
@ -0,0 +1,43 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StableUtils; |
||||
|
||||
import java.awt.*; |
||||
import java.io.File; |
||||
import java.net.URL; |
||||
|
||||
/** |
||||
* Created by zhaohehe on 16/7/27. |
||||
*/ |
||||
public class LoginPane extends BasicPane { |
||||
private static final String LATEST = "latest"; |
||||
|
||||
public LoginPane() { |
||||
setLayout(new BorderLayout()); |
||||
if (StableUtils.getMajorJavaVersion() == 8) { |
||||
String installHome; |
||||
if (StableUtils.isDebug()) { |
||||
URL url = ClassLoader.getSystemResource(""); |
||||
installHome = url.getPath(); |
||||
addPane(installHome); |
||||
} else { |
||||
installHome = StableUtils.getInstallHome(); |
||||
File file = new File(StableUtils.pathJoin(installHome, "scripts")); |
||||
} |
||||
} else { |
||||
} |
||||
} |
||||
|
||||
private void addPane(String installHome) { |
||||
LoginWebPane webPane = new LoginWebPane(new File(installHome).getAbsolutePath(),LoginPane.this); |
||||
add(webPane, BorderLayout.CENTER); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Inter.getLocText("FR-Designer-Plugin_Manager"); |
||||
} |
||||
} |
@ -0,0 +1,188 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.base.FRContext; |
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.dialog.UIDialog; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import com.fr.design.mainframe.DesignerContext; |
||||
import com.fr.general.FRLogger; |
||||
import com.fr.general.SiteCenter; |
||||
import com.fr.general.http.HttpClient; |
||||
import com.fr.stable.EncodeConstants; |
||||
import com.fr.stable.StringUtils; |
||||
import javafx.scene.web.WebEngine; |
||||
|
||||
import java.io.UnsupportedEncodingException; |
||||
import java.net.HttpURLConnection; |
||||
import java.net.URI; |
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
import java.net.URLEncoder; |
||||
|
||||
/** |
||||
* Created by zhaohehe on 16/8/1. |
||||
*/ |
||||
public class LoginWebBridge { |
||||
|
||||
private static final String LOGIN_SUCCESS_FLAG = "http://bbs.finereport.com"; |
||||
private static final String LOGININ = "0"; |
||||
private static final String LOGIN_INFO_EMPTY = "-1"; |
||||
private static final String DISCONNECTED = "-2"; |
||||
private static final String UNKNOWN_ERROR = "-3"; |
||||
private static final int TIME_OUT = 10000; |
||||
|
||||
private static com.fr.design.extra.LoginWebBridge helper; |
||||
private UIDialog uiDialog; |
||||
private UILabel uiLabel; |
||||
|
||||
private boolean testConnection() { |
||||
HttpClient client = new HttpClient(SiteCenter.getInstance().acquireUrlByKind("bbs.test")); |
||||
return client.isServerAlive(); |
||||
} |
||||
|
||||
public static com.fr.design.extra.LoginWebBridge getHelper() { |
||||
if (helper != null) { |
||||
return helper; |
||||
} |
||||
synchronized (com.fr.design.extra.LoginWebBridge.class) { |
||||
if (helper == null) { |
||||
helper = new com.fr.design.extra.LoginWebBridge(); |
||||
} |
||||
return helper; |
||||
} |
||||
} |
||||
|
||||
public static com.fr.design.extra.LoginWebBridge getHelper(WebEngine webEngine) { |
||||
getHelper(); |
||||
helper.setEngine(webEngine); |
||||
return helper; |
||||
} |
||||
|
||||
private WebEngine webEngine; |
||||
|
||||
private LoginWebBridge() { |
||||
} |
||||
|
||||
public void setEngine(WebEngine webEngine) { |
||||
this.webEngine = webEngine; |
||||
} |
||||
|
||||
public void setDialogHandle(UIDialog uiDialog) { |
||||
this.uiDialog = uiDialog; |
||||
} |
||||
|
||||
public void setUILabel(UILabel uiLabel) { |
||||
this.uiLabel = uiLabel; |
||||
} |
||||
|
||||
/** |
||||
* 注册页面 |
||||
*/ |
||||
public void registerHref() { |
||||
try { |
||||
Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.default"))); |
||||
}catch (Exception e) { |
||||
FRContext.getLogger().info(e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 忘记密码 |
||||
*/ |
||||
public void forgetHref() { |
||||
try { |
||||
Desktop.getDesktop().browse(new URI(SiteCenter.getInstance().acquireUrlByKind("bbs.default"))); |
||||
}catch (Exception e) { |
||||
FRContext.getLogger().info(e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 登录操作的回调 |
||||
* @param username |
||||
* @param password |
||||
* @return |
||||
*/ |
||||
public String defaultLogin(String username, String password) { |
||||
if (!StringUtils.isNotBlank(username) && !StringUtils.isNotBlank(password)) { |
||||
return LOGIN_INFO_EMPTY; |
||||
} |
||||
if (!testConnection()) { |
||||
return DISCONNECTED; |
||||
} |
||||
if (login(username, password)) { |
||||
updateUserInfo(username, password); |
||||
loginSuccess(username); |
||||
return LOGININ; |
||||
}else { |
||||
return UNKNOWN_ERROR; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 关闭窗口 |
||||
*/ |
||||
public void closeWindow() { |
||||
if (uiDialog != null) { |
||||
uiDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); |
||||
uiDialog.setVisible(false); |
||||
} |
||||
} |
||||
|
||||
public void updateUserInfo(String username,String password) { |
||||
DesignerEnvManager.getEnvManager().setBBSName(username); |
||||
DesignerEnvManager.getEnvManager().setBBSPassword(password); |
||||
} |
||||
|
||||
/** |
||||
* 关闭窗口并且重新赋值 |
||||
* @param username |
||||
*/ |
||||
public void loginSuccess(String username) { |
||||
closeWindow(); |
||||
uiLabel.setText(username); |
||||
} |
||||
|
||||
/** |
||||
* 弹出QQ授权页面 |
||||
*/ |
||||
public void showQQ() { |
||||
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); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
public boolean login(String username, String password) { |
||||
if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) { |
||||
try { |
||||
username = URLEncoder.encode(username, EncodeConstants.ENCODING_GBK); |
||||
password = URLEncoder.encode(password, EncodeConstants.ENCODING_GBK); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
String url = SiteCenter.getInstance().acquireUrlByKind("bbs.login") + "&username=" + username + "&password=" + password; |
||||
HttpClient client = new HttpClient(url); |
||||
client.setTimeout(TIME_OUT); |
||||
if (client.getResponseCodeNoException() == HttpURLConnection.HTTP_OK) { |
||||
try { |
||||
String res = client.getResponseText(EncodeConstants.ENCODING_GBK); |
||||
if (res.contains(LOGIN_SUCCESS_FLAG)) { |
||||
return true; |
||||
} |
||||
} catch (Exception e) { |
||||
FRLogger.getLogger().error(e.getMessage()); |
||||
} |
||||
} |
||||
} |
||||
return false; |
||||
} |
||||
} |
@ -0,0 +1,61 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import javafx.application.Platform; |
||||
import javafx.embed.swing.JFXPanel; |
||||
import javafx.event.EventHandler; |
||||
import javafx.scene.Scene; |
||||
import javafx.scene.layout.BorderPane; |
||||
import javafx.scene.web.WebEngine; |
||||
import javafx.scene.web.WebEvent; |
||||
import javafx.scene.web.WebView; |
||||
import netscape.javascript.JSObject; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
/** |
||||
* Created by zhaohehe on 16/7/26. |
||||
*/ |
||||
public class LoginWebPane extends JFXPanel { |
||||
|
||||
private WebEngine webEngine; |
||||
private LoginPane loginPane; |
||||
|
||||
public LoginWebPane(final String installHome,LoginPane loginPane) { |
||||
this.loginPane = loginPane; |
||||
Platform.setImplicitExit(false); |
||||
Platform.runLater(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
BorderPane root = new BorderPane(); |
||||
Scene scene = new Scene(root); |
||||
LoginWebPane.this.setScene(scene); |
||||
WebView webView = new WebView(); |
||||
webEngine = webView.getEngine(); |
||||
webEngine.load("file:///" + installHome + "/scripts/store/web/login.html"); |
||||
webEngine.setOnAlert(new EventHandler<WebEvent<String>>() { |
||||
@Override |
||||
public void handle(WebEvent<String> event) { |
||||
showAlert(event.getData()); |
||||
} |
||||
}); |
||||
JSObject obj = (JSObject) webEngine.executeScript("window"); |
||||
obj.setMember("LoginHelper", LoginWebBridge.getHelper(webEngine)); |
||||
webView.setContextMenuEnabled(false);//屏蔽右键
|
||||
root.setCenter(webView); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
public void setEngine(WebEngine webEngine) { |
||||
this.webEngine = webEngine; |
||||
} |
||||
|
||||
private void showAlert(final String message) { |
||||
SwingUtilities.invokeLater(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
JOptionPane.showMessageDialog(LoginWebPane.this, message); |
||||
} |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,34 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.design.dialog.UIDialog; |
||||
import com.fr.design.utils.gui.GUICoreUtils; |
||||
import com.fr.general.Inter; |
||||
|
||||
import javax.swing.*; |
||||
import java.awt.*; |
||||
|
||||
/** |
||||
* Created by zhaohehe on 16/7/28. |
||||
*/ |
||||
public class QQLoginDialog extends UIDialog { |
||||
private static final Dimension DEFAULT_SHOP = new Dimension(700, 500); |
||||
|
||||
public QQLoginDialog(Frame frame, BasicPane pane) { |
||||
super(frame); |
||||
setUndecorated(true); |
||||
JPanel panel = (JPanel) getContentPane(); |
||||
panel.setLayout(new BorderLayout()); |
||||
add(pane, BorderLayout.CENTER); |
||||
setSize(DEFAULT_SHOP); |
||||
GUICoreUtils.centerWindow(this); |
||||
setResizable(false); |
||||
setTitle(Inter.getLocText("FR-Designer-Plugin_Manager")); |
||||
|
||||
} |
||||
|
||||
@Override |
||||
public void checkValid() throws Exception { |
||||
} |
||||
|
||||
} |
@ -0,0 +1,44 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.design.dialog.BasicPane; |
||||
import com.fr.general.Inter; |
||||
import com.fr.stable.StableUtils; |
||||
|
||||
import java.awt.*; |
||||
import java.io.File; |
||||
import java.net.URL; |
||||
|
||||
/** |
||||
* Created by zhaohehe on 16/7/28. |
||||
*/ |
||||
public class QQLoginPane extends BasicPane { |
||||
private static final String LATEST = "latest"; |
||||
|
||||
public QQLoginPane() { |
||||
setLayout(new BorderLayout()); |
||||
if (System.getProperty("java.version").startsWith("1.8")) { |
||||
String installHome; |
||||
if (StableUtils.isDebug()) { |
||||
URL url = ClassLoader.getSystemResource(""); |
||||
installHome = url.getPath(); |
||||
addPane(installHome); |
||||
} else { |
||||
installHome = StableUtils.getInstallHome(); |
||||
File file = new File(StableUtils.pathJoin(installHome, "scripts")); |
||||
|
||||
} |
||||
} else { |
||||
} |
||||
} |
||||
|
||||
private void addPane(String installHome) { |
||||
QQLoginWebPane webPane = new QQLoginWebPane(new File(installHome).getAbsolutePath()); |
||||
add(webPane, BorderLayout.CENTER); |
||||
} |
||||
|
||||
|
||||
@Override |
||||
protected String title4PopupWindow() { |
||||
return Inter.getLocText("FR-Designer-Plugin_Manager"); |
||||
} |
||||
} |
@ -0,0 +1,105 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.dialog.UIDialog; |
||||
import com.fr.design.gui.ilable.UILabel; |
||||
import javafx.scene.web.WebEngine; |
||||
import org.json.JSONObject; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
/** |
||||
* Created by lp on 2016/8/10. |
||||
*/ |
||||
public class QQLoginWebBridge { |
||||
|
||||
private static com.fr.design.extra.QQLoginWebBridge helper; |
||||
private WebEngine webEngine; |
||||
private static String LOGINSUCCESS = "ok"; |
||||
private static String LOGINFAILED = "failed"; |
||||
private UIDialog uiDialog; |
||||
private UILabel uiLabel; |
||||
private UIDialog qqDialog; |
||||
private String username; |
||||
|
||||
|
||||
private QQLoginWebBridge() { |
||||
} |
||||
|
||||
public static com.fr.design.extra.QQLoginWebBridge getHelper() { |
||||
if (helper != null) { |
||||
return helper; |
||||
} |
||||
synchronized (com.fr.design.extra.QQLoginWebBridge.class) { |
||||
if (helper == null) { |
||||
helper = new com.fr.design.extra.QQLoginWebBridge(); |
||||
} |
||||
return helper; |
||||
} |
||||
} |
||||
|
||||
public void setEngine(WebEngine webEngine) { |
||||
this.webEngine = webEngine; |
||||
} |
||||
|
||||
public void setDialogHandle(UIDialog uiDialog) { |
||||
this.uiDialog = uiDialog; |
||||
} |
||||
|
||||
public void setQQDialogHandle(UIDialog uiDialog) { |
||||
this.qqDialog = uiDialog; |
||||
} |
||||
|
||||
public void setUILabel(UILabel uiLabel) { |
||||
this.uiLabel = uiLabel; |
||||
} |
||||
|
||||
public void setLoginlabel() { |
||||
username = DesignerEnvManager.getEnvManager().getBBSName(); |
||||
} |
||||
|
||||
public static com.fr.design.extra.QQLoginWebBridge getHelper(WebEngine webEngine) { |
||||
getHelper(); |
||||
helper.setEngine(webEngine); |
||||
return helper; |
||||
} |
||||
|
||||
/** |
||||
* 关闭QQ授权窗口 |
||||
*/ |
||||
public void closeQQWindow() { |
||||
if (qqDialog != null) { |
||||
qqDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); |
||||
qqDialog.setVisible(false); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 关闭父窗口 |
||||
*/ |
||||
public void closeParentWindow() { |
||||
if (uiDialog != null) { |
||||
uiDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); |
||||
uiDialog.setVisible(false); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取用户信息 |
||||
* @param userInfo |
||||
*/ |
||||
public void getLoginInfo(String userInfo) { |
||||
JSONObject jo = new JSONObject(userInfo); |
||||
String status = jo.get("status").toString(); |
||||
if (status.equals(LOGINSUCCESS)) { |
||||
String username = jo.get("username").toString(); |
||||
closeQQWindow(); |
||||
closeParentWindow(); |
||||
uiLabel.setText(username); |
||||
DesignerEnvManager.getEnvManager().setBBSName(username); |
||||
}else if (status.equals(LOGINFAILED)){ |
||||
//账号没有QQ授权
|
||||
closeQQWindow(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,55 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import javafx.application.Platform; |
||||
import javafx.embed.swing.JFXPanel; |
||||
import javafx.event.EventHandler; |
||||
import javafx.scene.Scene; |
||||
import javafx.scene.layout.BorderPane; |
||||
import javafx.scene.web.WebEngine; |
||||
import javafx.scene.web.WebEvent; |
||||
import javafx.scene.web.WebView; |
||||
import netscape.javascript.JSObject; |
||||
|
||||
import javax.swing.*; |
||||
|
||||
/** |
||||
* Created by zhaohehe on 16/7/28. |
||||
*/ |
||||
public class QQLoginWebPane extends JFXPanel { |
||||
|
||||
private WebEngine webEngine; |
||||
|
||||
public QQLoginWebPane(final String installHome) { |
||||
Platform.setImplicitExit(false); |
||||
Platform.runLater(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
BorderPane root = new BorderPane(); |
||||
Scene scene = new Scene(root); |
||||
QQLoginWebPane.this.setScene(scene); |
||||
WebView webView = new WebView(); |
||||
webEngine = webView.getEngine(); |
||||
webEngine.load("file:///" + installHome + "/scripts/store/web/qqLogin.html"); |
||||
webEngine.setOnAlert(new EventHandler<WebEvent<String>>() { |
||||
@Override |
||||
public void handle(WebEvent<String> event) { |
||||
showAlert(event.getData()); |
||||
} |
||||
}); |
||||
JSObject obj = (JSObject) webEngine.executeScript("window"); |
||||
obj.setMember("QQLoginHelper", QQLoginWebBridge.getHelper(webEngine)); |
||||
webView.setContextMenuEnabled(false);//屏蔽右键
|
||||
root.setCenter(webView); |
||||
} |
||||
}); |
||||
} |
||||
|
||||
private void showAlert(final String message) { |
||||
SwingUtilities.invokeLater(new Runnable() { |
||||
@Override |
||||
public void run() { |
||||
JOptionPane.showMessageDialog(QQLoginWebPane.this, message); |
||||
} |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,28 @@
|
||||
package com.fr.design.extra; |
||||
|
||||
import java.util.ArrayList; |
||||
|
||||
/** |
||||
* Created by lp on 2016/8/16. |
||||
*/ |
||||
public class UserLoginContext { |
||||
private static ArrayList<LoginContextListener> fireLoginContextListener = new ArrayList<LoginContextListener>(); |
||||
|
||||
/** |
||||
* 触发登录框弹出的监听器 |
||||
*/ |
||||
public static void fireLoginContextListener() { |
||||
for (LoginContextListener l : fireLoginContextListener) { |
||||
l.showLoginContext(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 添加一个弹出登录框的监听事件 |
||||
* |
||||
* @param l 登录框弹出监听事件 |
||||
*/ |
||||
public static void addLoginContextListener(LoginContextListener l) { |
||||
fireLoginContextListener.add(l); |
||||
} |
||||
} |
@ -0,0 +1,37 @@
|
||||
package com.fr.design.extra.exe; |
||||
|
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.extra.Process; |
||||
|
||||
/** |
||||
* Created by lp on 2016/8/16. |
||||
*/ |
||||
public class GetLoginInfoExecutor implements Executor { |
||||
private String result = "[]"; |
||||
|
||||
@Override |
||||
public String getTaskFinishMessage() { |
||||
return result; |
||||
} |
||||
|
||||
@Override |
||||
public Command[] getCommands() { |
||||
return new Command[]{ |
||||
new Command() { |
||||
@Override |
||||
public String getExecuteMessage() { |
||||
return null; |
||||
} |
||||
|
||||
@Override |
||||
public void run(Process<String> process) { |
||||
String username = DesignerEnvManager.getEnvManager().getBBSName(); |
||||
if (username == null) { |
||||
}else { |
||||
result = username; |
||||
} |
||||
} |
||||
} |
||||
}; |
||||
} |
||||
} |
Loading…
Reference in new issue