Browse Source

mac下没有encode中文名登陆不上

master
vito 9 years ago
parent
commit
fd09cd369d
  1. 100
      designer/src/com/fr/design/mainframe/bbs/BBSLoginDialog.java

100
designer/src/com/fr/design/mainframe/bbs/BBSLoginDialog.java

@ -14,6 +14,7 @@ import com.fr.general.FRFont;
import com.fr.general.FRLogger;
import com.fr.general.Inter;
import com.fr.general.http.HttpClient;
import com.fr.stable.EncodeConstants;
import com.fr.stable.StringUtils;
import javax.swing.*;
@ -24,8 +25,10 @@ import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URLEncoder;
/**
* @author richie
@ -63,14 +66,14 @@ public class BBSLoginDialog extends UIDialog {
private BoxCenterAligmentPane registerLabel;
private KeyListener keyListener = new KeyAdapter() {
public void keyPressed(KeyEvent e){
public void keyPressed(KeyEvent e) {
int code = e.getKeyCode();
if(KeyEvent.VK_ESCAPE == code){
if (KeyEvent.VK_ESCAPE == code) {
BBSLoginDialog.this.setVisible(false);
return;
}
if(KeyEvent.VK_ENTER == code){
if (KeyEvent.VK_ENTER == code) {
login();
}
}
@ -91,22 +94,23 @@ public class BBSLoginDialog extends UIDialog {
/**
* 构造函数
*
* @param parent 父窗口
* @param userInfoLabel 登录状态label
*/
public BBSLoginDialog(Frame parent,UserInfoLabel userInfoLabel) {
public BBSLoginDialog(Frame parent, UserInfoLabel userInfoLabel) {
super(parent);
JPanel panel = (JPanel) getContentPane();
initComponents(panel);
this.userInfoLabel = userInfoLabel;
setSize(new Dimension(DIALOG_WIDTH,DIALOG_HEIGHT));
setSize(new Dimension(DIALOG_WIDTH, DIALOG_HEIGHT));
}
private void initComponents(JPanel contentPane) {
this.setTitle(Inter.getLocText("FR-Designer-BBSLogin_Login-Title"));
tipLabel = new UILabel(Inter.getLocText("FR-Designer-BBSLogin_Login-Failure-Tip"));
userLabel = new UILabel(Inter.getLocText("FR-Designer-BBSLogin_Account")+":");
passLabel = new UILabel(Inter.getLocText("FR-Designer-BBSLogin_Password")+":");
userLabel = new UILabel(Inter.getLocText("FR-Designer-BBSLogin_Account") + ":");
passLabel = new UILabel(Inter.getLocText("FR-Designer-BBSLogin_Password") + ":");
nameField = new UITextField();
passField = new UIPassWordField();
loginButton = new UIButton(Inter.getLocText("FR-Designer-BBSLogin_Login"));
@ -130,7 +134,7 @@ public class BBSLoginDialog extends UIDialog {
contentPane.setLayout(new BorderLayout());
JPanel mainPane = new JPanel();
mainPane.setLayout(new BorderLayout(0,V_GAP));
mainPane.setLayout(new BorderLayout(0, V_GAP));
initNorthPane(mainPane);
@ -138,81 +142,81 @@ public class BBSLoginDialog extends UIDialog {
initSouthPane(mainPane);
contentPane.add(mainPane,BorderLayout.NORTH);
contentPane.add(mainPane, BorderLayout.NORTH);
this.setResizable(false);
}
private void login(){
if(nameField.getText().isEmpty()){
private void login() {
if (nameField.getText().isEmpty()) {
tipForUsernameEmpty();
nameField.requestFocus();
return;
}
if(String.valueOf(passField.getPassword()).isEmpty()){
if (String.valueOf(passField.getPassword()).isEmpty()) {
tipForPasswordEmpty();
passField.requestFocus();
return;
}
if(!testConnection()){
if (!testConnection()) {
connectionFailue();
return;
}
if(login(nameField.getText(),String.valueOf(passField.getPassword()))){
if (login(nameField.getText(), String.valueOf(passField.getPassword()))) {
loginSuccess();
}else{
} else {
loginFailure();
}
}
private boolean testConnection(){
private boolean testConnection() {
HttpClient client = new HttpClient(TEST_CONNECTION_URL);
return client.isServerAlive();
}
private void initNorthPane(JPanel mainPane){
private void initNorthPane(JPanel mainPane) {
JPanel northPane = new JPanel();
northPane.setPreferredSize(new Dimension(DIALOG_WIDTH,NORTH_PANE_HEIGHT));
northPane.setPreferredSize(new Dimension(DIALOG_WIDTH, NORTH_PANE_HEIGHT));
northPane.add(tipLabel);
mainPane.add(northPane,BorderLayout.NORTH);
mainPane.add(northPane, BorderLayout.NORTH);
}
private void initCenterPane(JPanel mainPane){
private void initCenterPane(JPanel mainPane) {
JPanel loginPane = new JPanel();
loginPane.setLayout(new GridLayout(2,1,0,V_GAP));
loginPane.setLayout(new GridLayout(2, 1, 0, V_GAP));
JPanel namePane = new JPanel();
namePane.setLayout(new FlowLayout(FlowLayout.RIGHT,FLOWLAYOUT_H_GAP,0));
namePane.setLayout(new FlowLayout(FlowLayout.RIGHT, FLOWLAYOUT_H_GAP, 0));
namePane.add(userLabel);
nameField.setPreferredSize(new Dimension(FIELD_WIDTH,FIELD_HEIGHT));
nameField.setPreferredSize(new Dimension(FIELD_WIDTH, FIELD_HEIGHT));
namePane.add(nameField);
namePane.add(passwordReset);
loginPane.add(namePane);
JPanel passPane = new JPanel();
passPane.setLayout(new FlowLayout(FlowLayout.RIGHT,FLOWLAYOUT_H_GAP,0));
passPane.setLayout(new FlowLayout(FlowLayout.RIGHT, FLOWLAYOUT_H_GAP, 0));
passPane.add(passLabel);
passPane.add(passField);
passField.setPreferredSize(new Dimension(FIELD_WIDTH,FIELD_HEIGHT));
passField.setPreferredSize(new Dimension(FIELD_WIDTH, FIELD_HEIGHT));
passPane.add(registerLabel);
loginPane.add(passPane);
mainPane.add(loginPane,BorderLayout.CENTER);
mainPane.add(loginPane, BorderLayout.CENTER);
}
private void initSouthPane(JPanel mainPane){
private void initSouthPane(JPanel mainPane) {
JPanel southPane = new JPanel();
southPane.setLayout(new FlowLayout(FlowLayout.RIGHT,BUTTON_H_GAP,0));
loginButton.setPreferredSize(new Dimension(BUTTON_WIDTH,FIELD_HEIGHT));
southPane.setLayout(new FlowLayout(FlowLayout.RIGHT, BUTTON_H_GAP, 0));
loginButton.setPreferredSize(new Dimension(BUTTON_WIDTH, FIELD_HEIGHT));
loginButton.setFont(DEFAULT_FONT);
southPane.add(loginButton);
mainPane.add(southPane,BorderLayout.SOUTH);
mainPane.add(southPane, BorderLayout.SOUTH);
}
// 登录成功
private void loginSuccess(){
private void loginSuccess() {
DesignerEnvManager.getEnvManager().setBBSPassword(String.valueOf(passField.getPassword()));
userInfoLabel.setUserName(nameField.getText());
userInfoLabel.getUserInfoPane().markSignIn(nameField.getText());
@ -221,11 +225,11 @@ public class BBSLoginDialog extends UIDialog {
}
// 登录失败
private void loginFailure(){
private void loginFailure() {
setLoginFailureTxt(Inter.getLocText("FR-Designer-BBSLogin_Login-Failure-Tip"));
}
private void tipForUsernameEmpty(){
private void tipForUsernameEmpty() {
setLoginFailureTxt(Inter.getLocText("FR-Designer-BBSLogin_Username-Empty-Tip"));
}
@ -233,11 +237,11 @@ public class BBSLoginDialog extends UIDialog {
setLoginFailureTxt(Inter.getLocText("FR-Designer-BBSLogin_Download-Unlogin-Tip"));
}
private void tipForPasswordEmpty(){
private void tipForPasswordEmpty() {
setLoginFailureTxt(Inter.getLocText("FR-Designer-BBSLogin_Password-Empty-Tip"));
}
private void setLoginFailureTxt(String errorTxt){
private void setLoginFailureTxt(String errorTxt) {
tipLabel.setText(errorTxt);
tipLabel.setForeground(Color.RED);
tipLabel.repaint();
@ -245,14 +249,14 @@ public class BBSLoginDialog extends UIDialog {
}
// 连接失败
private void connectionFailue(){
private void connectionFailue() {
setLoginFailureTxt(Inter.getLocText("FR-Designer-BBSLogin_Connection-Failure"));
}
/**
* 清楚登录信息
*/
public void clearLoginInformation(){
public void clearLoginInformation() {
tipLabel.setText(StringUtils.EMPTY);
nameField.setText(StringUtils.EMPTY);
passField.setText(StringUtils.EMPTY);
@ -261,7 +265,7 @@ public class BBSLoginDialog extends UIDialog {
/**
* 显示登录窗口
*/
public void showWindow(){
public void showWindow() {
GUICoreUtils.centerWindow(this);
setVisible(true);
}
@ -276,18 +280,24 @@ public class BBSLoginDialog extends UIDialog {
/**
* 是否登陆成功
*
* @param username 用户名
* @param password 密码
* @return 同上
*/
public static boolean login(String username,String password){
public static boolean login(String username, String password) {
try {
username = URLEncoder.encode(username, EncodeConstants.ENCODING_GBK);
} catch (UnsupportedEncodingException e) {
FRLogger.getLogger().error(e.getMessage());
}
String url = URL + "&username=" + username + "&password=" + password;
HttpClient client = new HttpClient(url);
client.setTimeout(TIME_OUT);
if(client.getResponseCodeNoException() == HttpURLConnection.HTTP_OK){
if (client.getResponseCodeNoException() == HttpURLConnection.HTTP_OK) {
try {
String res = client.getResponseText("GBK");
if(res.contains(LOGIN_SUCCESS_FLAG)){
String res = client.getResponseText(EncodeConstants.ENCODING_GBK);
if (res.contains(LOGIN_SUCCESS_FLAG)) {
return true;
}
} catch (Exception e) {
@ -297,11 +307,11 @@ public class BBSLoginDialog extends UIDialog {
return false;
}
private BoxCenterAligmentPane getURLActionLabel(final String url){
private BoxCenterAligmentPane getURLActionLabel(final String url) {
ActionLabel actionLabel = new ActionLabel(url);
if(ComparatorUtils.equals(url, PASSWORD_RESET_URL)){
if (ComparatorUtils.equals(url, PASSWORD_RESET_URL)) {
actionLabel.setText(Inter.getLocText("FR-Designer-BBSLogin_Forgot-Password"));
}else{
} else {
actionLabel.setText(Inter.getLocText("FR-Designer-BBSLogin_Register-Account"));
}

Loading…
Cancel
Save