Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPARK-2341 Improve signup wizzard #877

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
252 changes: 207 additions & 45 deletions core/src/main/java/org/jivesoftware/AccountCreationWizard.java

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions core/src/main/java/org/jivesoftware/LoginDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ private final class LoginPanel extends JPanel implements KeyListener, ActionList
private final JCheckBox loginAsInvisibleBox = new JCheckBox();
private final JCheckBox loginAnonymouslyBox = new JCheckBox();

private final RolloverButton createAccountButton = new RolloverButton();
private final RolloverButton signUpButton = new RolloverButton();
private final RolloverButton passwordResetButton = new RolloverButton();

private final JLabel progressBar = new JLabel();
Expand All @@ -410,7 +410,7 @@ private final class LoginPanel extends JPanel implements KeyListener, ActionList
ResourceUtils.resButton(savePasswordBox, Res.getString("checkbox.save.password"));
ResourceUtils.resButton(autoLoginBox, Res.getString("checkbox.auto.login"));
ResourceUtils.resLabel(serverLabel, serverField, Res.getString("label.server"));
ResourceUtils.resButton(createAccountButton, Res.getString("label.accounts"));
ResourceUtils.resButton(signUpButton, Res.getString("label.accounts"));
ResourceUtils.resButton(passwordResetButton, Res.getString("label.passwordreset"));
ResourceUtils.resButton(loginAsInvisibleBox, Res.getString("checkbox.login.as.invisible"));
ResourceUtils.resButton(loginAnonymouslyBox, Res.getString("checkbox.login.anonymously"));
Expand Down Expand Up @@ -515,7 +515,7 @@ private final class LoginPanel extends JPanel implements KeyListener, ActionList
loginAnonymouslyBox.addActionListener(this);

if (!Default.getBoolean(Default.ACCOUNT_DISABLED) && localPref.getAccountsReg()) {
buttonPanel.add(createAccountButton,
buttonPanel.add(signUpButton,
new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0,
GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0));
}
Expand Down Expand Up @@ -665,7 +665,7 @@ public void mouseClicked(MouseEvent e) {
validateLogin();
}

createAccountButton.addActionListener(this);
signUpButton.addActionListener(this);

final String lockedDownURL = Default.getString(Default.HOST_NAME);
if (ModelUtil.hasLength(lockedDownURL)) {
Expand Down Expand Up @@ -728,7 +728,7 @@ boolean isLoginAsInvisible() {
public void actionPerformed(ActionEvent e) {
if (e.getSource() == quitButton) {
quitLogin();
} else if (e.getSource() == createAccountButton) {
} else if (e.getSource() == signUpButton) {
AccountCreationWizard createAccountPanel = new AccountCreationWizard();
createAccountPanel.invoke(loginDialog);

Expand Down
105 changes: 105 additions & 0 deletions core/src/main/java/org/jivesoftware/XmppProviders.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* Copyright (C) 2004-2024 Jive Software. All rights reserved.
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


package org.jivesoftware;

import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.ClassicHttpResponse;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.jivesoftware.spark.util.log.Log;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

import static java.util.Arrays.asList;


public class XmppProviders {
/**
* <a href="https://data.xmpp.net/providers/v2/providers-A.json">Providers A</a>
*/
private static final String[] providers = new String[]{
"07f.de",
"chalec.org",
"chapril.org",
"chatrix.one",
"draugr.de",
"hookipa.net",
"jabber.fr",
"macaw.me",
"magicbroccoli.de",
"nixnet.services",
"projectsegfau.lt",
"redlibre.es",
"suchat.org",
"sure.im",
"trashserver.net",
"xmpp.earth",
"yax.im",
};

public static List<String> getXmppProvidersModel() {
List<String> providersList = downloadProvidersList();
if (providersList != null) {
return providersList;
}
// fallback to static list
providersList = asList(providers);
return providersList;
}

static List<String> downloadProvidersList() {
Log.debug("Download providers");
try (CloseableHttpClient httpClient = HttpClients.createSystem()) {
HttpGet request = new HttpGet("https://data.xmpp.net/providers/v2/providers-As.json");
try (ClassicHttpResponse httpResponse = httpClient.executeOpen(null, request, null)) {
final int statusCode = httpResponse.getCode();
if (statusCode == 200) {
String json = EntityUtils.toString(httpResponse.getEntity(), StandardCharsets.UTF_8);
return parseProvidersJson(json);
}
Log.error("Download providers: bad status " + statusCode);
return null;
}
} catch (Exception e) {
Log.error("Download providers: error", e);
return null;
}
}

static List<String> parseProvidersJson(String json) {
// manually parse JSON array
json = json.trim();
if (json.charAt(0) != '[' || json.charAt(json.length() - 1) != ']') {
return null;
}
String[] lines = json.substring(1, json.length() - 1).split(",");
List<String> providers = new ArrayList<>(lines.length);
for (String line : lines) {
line = line.trim();
if (line.charAt(0) != '"' || line.charAt(line.length() - 1) != '"') {
continue;
}
String provider = line.substring(1, line.length() - 1);
providers.add(provider);
}
return providers;
}
}
4 changes: 2 additions & 2 deletions core/src/main/java/org/jivesoftware/gui/LoginUIPanel.form
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,12 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnLoginActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnCreateAccount">
<Component class="javax.swing.JButton" name="btnSignUp">
<Properties>
<Property name="background" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="ff" green="ff" red="ff" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="Account"/>
<Property name="text" type="java.lang.String" value="Sign Up"/>
<Property name="borderPainted" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="10"/>
<Property name="opaque" type="boolean" value="false"/>
Expand Down
30 changes: 15 additions & 15 deletions core/src/main/java/org/jivesoftware/gui/LoginUIPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private void init() {

ResourceUtils.resButton(cbSavePassword, Res.getString("checkbox.save.password"));
ResourceUtils.resButton(cbAutoLogin, Res.getString("checkbox.auto.login"));
ResourceUtils.resButton(btnCreateAccount, Res.getString("label.accounts"));
ResourceUtils.resButton(btnSignUp, Res.getString("label.accounts"));
ResourceUtils.resButton(cbLoginInvisible, Res.getString("checkbox.login.as.invisible"));
ResourceUtils.resButton(cbAnonymous, Res.getString("checkbox.login.anonymously"));
ResourceUtils.resButton(btnReset, Res.getString("label.passwordreset"));
Expand Down Expand Up @@ -305,7 +305,7 @@ public void mouseClicked(MouseEvent e) {
TaskEngine.getInstance().submit(this::login);
}

btnCreateAccount.addActionListener(this);
btnSignUp.addActionListener(this);

final String lockedDownURL = Default.getString(Default.HOST_NAME);
if (ModelUtil.hasLength(lockedDownURL)) {
Expand All @@ -314,7 +314,7 @@ public void mouseClicked(MouseEvent e) {

//reset ui
//btnAdvanced.setUI(new BasicButtonUI());
//btnCreateAccount.setUI(new BasicButtonUI());
//btnSignUp.setUI(new BasicButtonUI());
tfDomain.putClientProperty("JTextField.placeholderText", Res.getString("hint.login.domain"));
tfPassword.putClientProperty("JTextField.placeholderText", Res.getString("hint.login.password"));
tfUsername.putClientProperty("JTextField.placeholderText", Res.getString("hint.login.username"));
Expand Down Expand Up @@ -355,7 +355,7 @@ private void configureVisibility() {
}

if (Default.getBoolean(Default.ACCOUNT_DISABLED) || !localPref.getAccountsReg()) {
pnlBtns.remove(btnCreateAccount);
pnlBtns.remove(btnSignUp);
height = height + 15;
}

Expand Down Expand Up @@ -397,7 +397,7 @@ private void initComponents() {
cbAnonymous = new javax.swing.JCheckBox();
pnlBtns = new javax.swing.JPanel();
btnLogin = new javax.swing.JButton();
btnCreateAccount = new javax.swing.JButton();
btnSignUp = new javax.swing.JButton();
btnAdvanced = new javax.swing.JButton();
btnReset = new javax.swing.JButton();

Expand Down Expand Up @@ -504,13 +504,13 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
});
pnlBtns.add(btnLogin);

btnCreateAccount.setBackground(new java.awt.Color(255, 255, 255));
btnCreateAccount.setText("Account");
btnCreateAccount.setBorderPainted(false);
btnCreateAccount.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
btnCreateAccount.setOpaque(false);
btnCreateAccount.setPreferredSize(new java.awt.Dimension(95, 28));
pnlBtns.add(btnCreateAccount);
btnSignUp.setBackground(new java.awt.Color(255, 255, 255));
btnSignUp.setText("Account");
btnSignUp.setBorderPainted(false);
btnSignUp.setHorizontalTextPosition(javax.swing.SwingConstants.LEADING);
btnSignUp.setOpaque(false);
btnSignUp.setPreferredSize(new java.awt.Dimension(95, 28));
pnlBtns.add(btnSignUp);

btnAdvanced.setBackground(new java.awt.Color(255, 255, 255));
btnAdvanced.setText("Advanced");
Expand Down Expand Up @@ -569,7 +569,7 @@ private void btnResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnAdvanced;
private javax.swing.JButton btnCreateAccount;
private javax.swing.JButton btnSignUp;
private javax.swing.JButton btnLogin;
private javax.swing.JButton btnReset;
private javax.swing.JCheckBox cbAnonymous;
Expand Down Expand Up @@ -910,7 +910,7 @@ boolean isLoginAsInvisible() {
*/
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnCreateAccount) {
if (e.getSource() == btnSignUp) {
AccountCreationWizard createAccountPanel = new AccountCreationWizard();
createAccountPanel.invoke(loginDialog);

Expand Down Expand Up @@ -1055,7 +1055,7 @@ private void setComponentsAvailable(boolean available)
cbAnonymous.setEnabled(available);
btnLogin.setEnabled(available);
btnAdvanced.setEnabled(available);
btnCreateAccount.setEnabled(available);
btnSignUp.setEnabled(available);

// Need to set both editable and enabled for best behavior.
tfUsername.setEditable(available);
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/resources/i18n/spark_i18n.properties
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ button.cert.info = Details
button.clear = Clear
button.close = Close
button.copy.to.clipboard = Copy to clipboard
button.start.registration = Start registration
button.create.account = Create account
button.create.room = Create or join room
button.decline = Decline
Expand Down Expand Up @@ -224,7 +225,7 @@ group.encryption_mode = Encryption mode

label.na = n/a
label.home = Home
label.accounts = A&ccounts
label.accounts = Sign Up
label.add.conference.service = Add conference service
label.add.jid = Add JID
label.add.task = Add task
Expand Down
22 changes: 22 additions & 0 deletions core/src/test/java/org/jivesoftware/XmppProvidersTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.jivesoftware;

import org.junit.Test;

import java.util.List;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;

public class XmppProvidersTest {

@Test
public void testParseProvidersJson() {
List<String> providers = XmppProviders.parseProvidersJson("[\n" +
" \"07f.de\",\n" +
" \"404.city\",\n" +
" \"5222.de\"" +
"]");
assertEquals(asList("07f.de", "404.city", "5222.de"), providers);
}

}
Loading