mirror of
https://github.com/correl/mage.git
synced 2024-12-25 11:11:16 +00:00
Send an email on successful user registration. Use Gmail API for that. Add password confirmation and email to RegisterUserDialog.
This commit is contained in:
parent
46f60cd857
commit
a0ddd4fff0
11 changed files with 328 additions and 70 deletions
|
@ -24,36 +24,39 @@
|
||||||
<DimensionLayout dim="0">
|
<DimensionLayout dim="0">
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
<Group type="102" attributes="0">
|
<Group type="102" attributes="0">
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
|
||||||
<Group type="102" alignment="0" attributes="0">
|
|
||||||
<EmptySpace min="-2" pref="14" max="-2" attributes="0"/>
|
|
||||||
<Component id="lblUserName" min="-2" max="-2" attributes="0"/>
|
|
||||||
</Group>
|
|
||||||
<Group type="102" alignment="1" attributes="0">
|
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
|
||||||
<Component id="lblPassword" alignment="1" min="-2" max="-2" attributes="0"/>
|
|
||||||
<Component id="lblPort" alignment="1" min="-2" max="-2" attributes="0"/>
|
|
||||||
<Component id="lblServer" alignment="1" min="-2" max="-2" attributes="0"/>
|
|
||||||
</Group>
|
|
||||||
</Group>
|
|
||||||
</Group>
|
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Group type="103" groupAlignment="0" attributes="0">
|
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||||
<Component id="lblStatus" min="-2" pref="292" max="-2" attributes="0"/>
|
<Group type="103" alignment="0" groupAlignment="1" attributes="0">
|
||||||
<Group type="103" groupAlignment="1" max="-2" attributes="0">
|
<Component id="lblPasswordConfirmationReasoning" min="-2" max="-2" attributes="0"/>
|
||||||
<Group type="102" attributes="0">
|
<Group type="102" attributes="0">
|
||||||
|
<Group type="103" groupAlignment="1" attributes="0">
|
||||||
|
<Component id="lblServer" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="lblUserName" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="lblPort" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="lblPassword" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="lblPasswordConfirmation" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="lblEmail" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Group type="103" groupAlignment="0" attributes="0">
|
||||||
|
<Component id="txtServer" min="-2" pref="292" max="-2" attributes="0"/>
|
||||||
|
<Component id="txtPort" min="-2" pref="292" max="-2" attributes="0"/>
|
||||||
|
<Component id="txtUserName" alignment="0" min="-2" pref="292" max="-2" attributes="0"/>
|
||||||
|
<Component id="txtPassword" alignment="0" min="-2" pref="292" max="-2" attributes="0"/>
|
||||||
|
<Component id="txtPasswordConfirmation" alignment="0" min="-2" pref="292" max="-2" attributes="0"/>
|
||||||
|
<Component id="txtEmail" min="-2" pref="292" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
</Group>
|
||||||
|
<Component id="lblEmailReasoning" alignment="1" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Group type="102" alignment="1" attributes="0">
|
||||||
<Component id="btnRegister" min="-2" max="-2" attributes="0"/>
|
<Component id="btnRegister" min="-2" max="-2" attributes="0"/>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
|
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
<Component id="txtUserName" alignment="0" max="32767" attributes="0"/>
|
|
||||||
<Component id="txtPassword" alignment="0" pref="292" max="32767" attributes="0"/>
|
|
||||||
<Component id="txtServer" alignment="0" max="32767" attributes="0"/>
|
|
||||||
</Group>
|
</Group>
|
||||||
<Component id="txtPort" min="-2" pref="292" max="-2" attributes="0"/>
|
<Component id="lblStatus" alignment="0" max="32767" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
<EmptySpace pref="16" max="32767" attributes="0"/>
|
<EmptySpace pref="22" max="32767" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
</DimensionLayout>
|
</DimensionLayout>
|
||||||
|
@ -80,14 +83,26 @@
|
||||||
<Component id="lblPassword" alignment="3" min="-2" max="-2" attributes="0"/>
|
<Component id="lblPassword" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
<Component id="txtPassword" alignment="3" min="-2" max="-2" attributes="0"/>
|
<Component id="txtPassword" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
<EmptySpace type="separate" min="-2" max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
|
<Component id="txtPasswordConfirmation" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="lblPasswordConfirmation" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<Component id="lblPasswordConfirmationReasoning" min="-2" max="-2" attributes="0"/>
|
||||||
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
|
<Component id="lblEmail" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="txtEmail" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
</Group>
|
||||||
|
<Component id="lblEmailReasoning" min="-2" max="-2" attributes="0"/>
|
||||||
|
<EmptySpace max="32767" attributes="0"/>
|
||||||
<Component id="lblStatus" min="-2" pref="28" max="-2" attributes="0"/>
|
<Component id="lblStatus" min="-2" pref="28" max="-2" attributes="0"/>
|
||||||
<EmptySpace max="-2" attributes="0"/>
|
<EmptySpace max="-2" attributes="0"/>
|
||||||
<Group type="103" groupAlignment="3" attributes="0">
|
<Group type="103" groupAlignment="3" attributes="0">
|
||||||
<Component id="btnRegister" alignment="3" min="-2" max="-2" attributes="0"/>
|
|
||||||
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
|
<Component id="btnCancel" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
|
<Component id="btnRegister" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
<EmptySpace pref="14" max="32767" attributes="0"/>
|
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Group>
|
||||||
</DimensionLayout>
|
</DimensionLayout>
|
||||||
|
@ -157,5 +172,48 @@
|
||||||
</Component>
|
</Component>
|
||||||
<Component class="javax.swing.JTextField" name="txtPort">
|
<Component class="javax.swing.JTextField" name="txtPort">
|
||||||
</Component>
|
</Component>
|
||||||
|
<Component class="javax.swing.JTextField" name="txtEmail">
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JLabel" name="lblPasswordConfirmation">
|
||||||
|
<Properties>
|
||||||
|
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||||
|
<ComponentRef name="txtPasswordConfirmation"/>
|
||||||
|
</Property>
|
||||||
|
<Property name="text" type="java.lang.String" value="Password:"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JPasswordField" name="txtPasswordConfirmation">
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JLabel" name="lblEmail">
|
||||||
|
<Properties>
|
||||||
|
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||||
|
<ComponentRef name="txtEmail"/>
|
||||||
|
</Property>
|
||||||
|
<Property name="text" type="java.lang.String" value="Email:"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JLabel" name="lblPasswordConfirmationReasoning">
|
||||||
|
<Properties>
|
||||||
|
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||||
|
<Font name="Lucida Grande" size="10" style="0"/>
|
||||||
|
</Property>
|
||||||
|
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||||
|
<ComponentRef name="txtPasswordConfirmation"/>
|
||||||
|
</Property>
|
||||||
|
<Property name="text" type="java.lang.String" value="(confirmation)"/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
<Component class="javax.swing.JLabel" name="lblEmailReasoning">
|
||||||
|
<Properties>
|
||||||
|
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
|
||||||
|
<Font name="Lucida Grande" size="10" style="0"/>
|
||||||
|
</Property>
|
||||||
|
<Property name="labelFor" type="java.awt.Component" editor="org.netbeans.modules.form.ComponentChooserEditor">
|
||||||
|
<ComponentRef name="txtEmail"/>
|
||||||
|
</Property>
|
||||||
|
<Property name="text" type="java.lang.String" value="(used for password reset)"/>
|
||||||
|
<Property name="toolTipText" type="java.lang.String" value=""/>
|
||||||
|
</Properties>
|
||||||
|
</Component>
|
||||||
</SubComponents>
|
</SubComponents>
|
||||||
</Form>
|
</Form>
|
||||||
|
|
|
@ -56,6 +56,12 @@ public class RegisterUserDialog extends MageDialog {
|
||||||
lblStatus = new javax.swing.JLabel();
|
lblStatus = new javax.swing.JLabel();
|
||||||
txtServer = new javax.swing.JTextField();
|
txtServer = new javax.swing.JTextField();
|
||||||
txtPort = new javax.swing.JTextField();
|
txtPort = new javax.swing.JTextField();
|
||||||
|
txtEmail = new javax.swing.JTextField();
|
||||||
|
lblPasswordConfirmation = new javax.swing.JLabel();
|
||||||
|
txtPasswordConfirmation = new javax.swing.JPasswordField();
|
||||||
|
lblEmail = new javax.swing.JLabel();
|
||||||
|
lblPasswordConfirmationReasoning = new javax.swing.JLabel();
|
||||||
|
lblEmailReasoning = new javax.swing.JLabel();
|
||||||
|
|
||||||
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
|
||||||
setTitle("Register");
|
setTitle("Register");
|
||||||
|
@ -94,34 +100,53 @@ public class RegisterUserDialog extends MageDialog {
|
||||||
|
|
||||||
lblStatus.setToolTipText("");
|
lblStatus.setToolTipText("");
|
||||||
|
|
||||||
|
lblPasswordConfirmation.setLabelFor(txtPasswordConfirmation);
|
||||||
|
lblPasswordConfirmation.setText("Password:");
|
||||||
|
|
||||||
|
lblEmail.setLabelFor(txtEmail);
|
||||||
|
lblEmail.setText("Email:");
|
||||||
|
|
||||||
|
lblPasswordConfirmationReasoning.setFont(new java.awt.Font("Lucida Grande", 0, 10)); // NOI18N
|
||||||
|
lblPasswordConfirmationReasoning.setLabelFor(txtPasswordConfirmation);
|
||||||
|
lblPasswordConfirmationReasoning.setText("(confirmation)");
|
||||||
|
|
||||||
|
lblEmailReasoning.setFont(new java.awt.Font("Lucida Grande", 0, 10)); // NOI18N
|
||||||
|
lblEmailReasoning.setLabelFor(txtEmail);
|
||||||
|
lblEmailReasoning.setText("(used for password reset)");
|
||||||
|
lblEmailReasoning.setToolTipText("");
|
||||||
|
|
||||||
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
|
||||||
getContentPane().setLayout(layout);
|
getContentPane().setLayout(layout);
|
||||||
layout.setHorizontalGroup(
|
layout.setHorizontalGroup(
|
||||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
.addContainerGap()
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||||
.addGap(14, 14, 14)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||||
.addComponent(lblUserName))
|
.addComponent(lblPasswordConfirmationReasoning)
|
||||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addContainerGap()
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
.addComponent(lblServer)
|
||||||
.addComponent(lblPassword, javax.swing.GroupLayout.Alignment.TRAILING)
|
.addComponent(lblUserName)
|
||||||
.addComponent(lblPort, javax.swing.GroupLayout.Alignment.TRAILING)
|
.addComponent(lblPort)
|
||||||
.addComponent(lblServer, javax.swing.GroupLayout.Alignment.TRAILING))))
|
.addComponent(lblPassword)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addComponent(lblPasswordConfirmation)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
.addComponent(lblEmail))
|
||||||
.addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
|
.addComponent(txtServer, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addComponent(txtPasswordConfirmation, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)))
|
||||||
|
.addComponent(lblEmailReasoning)
|
||||||
.addGroup(layout.createSequentialGroup()
|
.addGroup(layout.createSequentialGroup()
|
||||||
.addComponent(btnRegister)
|
.addComponent(btnRegister)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addComponent(btnCancel))
|
.addComponent(btnCancel)))
|
||||||
.addComponent(txtUserName, javax.swing.GroupLayout.Alignment.LEADING)
|
.addComponent(lblStatus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||||
.addComponent(txtPassword, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
|
.addContainerGap(22, Short.MAX_VALUE))
|
||||||
.addComponent(txtServer, javax.swing.GroupLayout.Alignment.LEADING))
|
|
||||||
.addComponent(txtPort, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE))
|
|
||||||
.addContainerGap(16, Short.MAX_VALUE))
|
|
||||||
);
|
);
|
||||||
layout.setVerticalGroup(
|
layout.setVerticalGroup(
|
||||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||||
|
@ -142,13 +167,24 @@ public class RegisterUserDialog extends MageDialog {
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
.addComponent(lblPassword)
|
.addComponent(lblPassword)
|
||||||
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
.addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||||
.addGap(18, 18, 18)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
|
.addComponent(txtPasswordConfirmation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
|
.addComponent(lblPasswordConfirmation))
|
||||||
|
.addComponent(lblPasswordConfirmationReasoning)
|
||||||
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
|
.addComponent(lblEmail)
|
||||||
|
.addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
|
||||||
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
|
.addComponent(lblEmailReasoning)
|
||||||
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
|
||||||
.addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
|
.addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||||
.addComponent(btnRegister)
|
.addComponent(btnCancel)
|
||||||
.addComponent(btnCancel))
|
.addComponent(btnRegister))
|
||||||
.addContainerGap(14, Short.MAX_VALUE))
|
.addContainerGap())
|
||||||
);
|
);
|
||||||
|
|
||||||
pack();
|
pack();
|
||||||
|
@ -163,11 +199,16 @@ public class RegisterUserDialog extends MageDialog {
|
||||||
}//GEN-LAST:event_btnCancelActionPerformed
|
}//GEN-LAST:event_btnCancelActionPerformed
|
||||||
|
|
||||||
private void btnRegisterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegisterActionPerformed
|
private void btnRegisterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRegisterActionPerformed
|
||||||
|
if (!this.txtPassword.getText().equals(this.txtPasswordConfirmation.getText())) {
|
||||||
|
MageFrame.getInstance().showError("Passwords don't match.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
connection = new Connection();
|
connection = new Connection();
|
||||||
connection.setHost(this.txtServer.getText().trim());
|
connection.setHost(this.txtServer.getText().trim());
|
||||||
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
|
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
|
||||||
connection.setUsername(this.txtUserName.getText().trim());
|
connection.setUsername(this.txtUserName.getText().trim());
|
||||||
connection.setPassword(this.txtPassword.getText().trim());
|
connection.setPassword(this.txtPassword.getText().trim());
|
||||||
|
connection.setEmail(this.txtEmail.getText().trim());
|
||||||
PreferencesDialog.setProxyInformation(connection);
|
PreferencesDialog.setProxyInformation(connection);
|
||||||
task = new ConnectTask();
|
task = new ConnectTask();
|
||||||
task.execute();
|
task.execute();
|
||||||
|
@ -218,12 +259,18 @@ public class RegisterUserDialog extends MageDialog {
|
||||||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
private javax.swing.JButton btnCancel;
|
private javax.swing.JButton btnCancel;
|
||||||
private javax.swing.JButton btnRegister;
|
private javax.swing.JButton btnRegister;
|
||||||
|
private javax.swing.JLabel lblEmail;
|
||||||
|
private javax.swing.JLabel lblEmailReasoning;
|
||||||
private javax.swing.JLabel lblPassword;
|
private javax.swing.JLabel lblPassword;
|
||||||
|
private javax.swing.JLabel lblPasswordConfirmation;
|
||||||
|
private javax.swing.JLabel lblPasswordConfirmationReasoning;
|
||||||
private javax.swing.JLabel lblPort;
|
private javax.swing.JLabel lblPort;
|
||||||
private javax.swing.JLabel lblServer;
|
private javax.swing.JLabel lblServer;
|
||||||
private javax.swing.JLabel lblStatus;
|
private javax.swing.JLabel lblStatus;
|
||||||
private javax.swing.JLabel lblUserName;
|
private javax.swing.JLabel lblUserName;
|
||||||
|
private javax.swing.JTextField txtEmail;
|
||||||
private javax.swing.JPasswordField txtPassword;
|
private javax.swing.JPasswordField txtPassword;
|
||||||
|
private javax.swing.JPasswordField txtPasswordConfirmation;
|
||||||
private javax.swing.JTextField txtPort;
|
private javax.swing.JTextField txtPort;
|
||||||
private javax.swing.JTextField txtServer;
|
private javax.swing.JTextField txtServer;
|
||||||
private javax.swing.JTextField txtUserName;
|
private javax.swing.JTextField txtUserName;
|
||||||
|
|
|
@ -45,6 +45,7 @@ public class Connection {
|
||||||
private int port;
|
private int port;
|
||||||
private String username;
|
private String username;
|
||||||
private String password;
|
private String password;
|
||||||
|
private String email;
|
||||||
private String adminPassword;
|
private String adminPassword;
|
||||||
private ProxyType proxyType;
|
private ProxyType proxyType;
|
||||||
private String proxyHost;
|
private String proxyHost;
|
||||||
|
@ -173,6 +174,14 @@ public class Connection {
|
||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
public String getAdminPassword() {
|
public String getAdminPassword() {
|
||||||
return adminPassword;
|
return adminPassword;
|
||||||
}
|
}
|
||||||
|
|
|
@ -195,7 +195,7 @@ public class SessionImpl implements Session {
|
||||||
public boolean run() throws Throwable {
|
public boolean run() throws Throwable {
|
||||||
logger.info("Trying to register as " + getUserName() + " to XMAGE server at " + connection.getHost() + ":" + connection.getPort());
|
logger.info("Trying to register as " + getUserName() + " to XMAGE server at " + connection.getHost() + ":" + connection.getPort());
|
||||||
boolean registerResult = server.registerUser(sessionId, connection.getUsername(),
|
boolean registerResult = server.registerUser(sessionId, connection.getUsername(),
|
||||||
connection.getPassword(), "");
|
connection.getPassword(), connection.getEmail());
|
||||||
if (registerResult) {
|
if (registerResult) {
|
||||||
logger.info("Registered as " + getUserName() + " to MAGE server at " + connection.getHost() + ":" + connection.getPort());
|
logger.info("Registered as " + getUserName() + " to MAGE server at " + connection.getHost() + ":" + connection.getPort());
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,8 @@
|
||||||
userNamePattern="[^a-z0-9_]"
|
userNamePattern="[^a-z0-9_]"
|
||||||
maxAiOpponents="15"
|
maxAiOpponents="15"
|
||||||
saveGameActivated="false"
|
saveGameActivated="false"
|
||||||
|
authenticationActivated="false"
|
||||||
|
googleAccount=""
|
||||||
/>
|
/>
|
||||||
<playerTypes>
|
<playerTypes>
|
||||||
<playerType name="Human" jar="mage-player-human.jar" className="mage.player.human.HumanPlayer"/>
|
<playerType name="Human" jar="mage-player-human.jar" className="mage.player.human.HumanPlayer"/>
|
||||||
|
|
|
@ -154,6 +154,36 @@
|
||||||
<version>1.2.4</version>
|
<version>1.2.4</version>
|
||||||
<type>jar</type>
|
<type>jar</type>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.api-client</groupId>
|
||||||
|
<artifactId>google-api-client</artifactId>
|
||||||
|
<version>1.21.0</version>
|
||||||
|
<type>jar</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.apis</groupId>
|
||||||
|
<artifactId>google-api-services-gmail</artifactId>
|
||||||
|
<version>v1-rev35-1.21.0</version>
|
||||||
|
<type>jar</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.oauth-client</groupId>
|
||||||
|
<artifactId>google-oauth-client-java6</artifactId>
|
||||||
|
<version>1.19.0</version>
|
||||||
|
<type>jar</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.oauth-client</groupId>
|
||||||
|
<artifactId>google-oauth-client-jetty</artifactId>
|
||||||
|
<version>1.19.0</version>
|
||||||
|
<type>jar</type>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.mail</groupId>
|
||||||
|
<artifactId>mail</artifactId>
|
||||||
|
<version>1.4.2</version>
|
||||||
|
<type>jar</type>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
86
Mage.Server/src/main/java/mage/server/GmailClient.java
Normal file
86
Mage.Server/src/main/java/mage/server/GmailClient.java
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
package mage.server;
|
||||||
|
|
||||||
|
import com.google.api.client.auth.oauth2.Credential;
|
||||||
|
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
|
||||||
|
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
|
||||||
|
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
|
||||||
|
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
|
||||||
|
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
|
||||||
|
import com.google.api.client.http.HttpTransport;
|
||||||
|
import com.google.api.client.json.JsonFactory;
|
||||||
|
import com.google.api.client.json.jackson2.JacksonFactory;
|
||||||
|
import com.google.api.client.util.Base64;
|
||||||
|
import com.google.api.client.util.store.FileDataStoreFactory;
|
||||||
|
import com.google.api.services.gmail.Gmail;
|
||||||
|
import com.google.api.services.gmail.Gmail.Builder;
|
||||||
|
import com.google.api.services.gmail.GmailScopes;
|
||||||
|
import com.google.api.services.gmail.model.Message;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import javax.mail.Session;
|
||||||
|
import java.security.GeneralSecurityException;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Properties;
|
||||||
|
import javax.mail.MessagingException;
|
||||||
|
import javax.mail.internet.InternetAddress;
|
||||||
|
import javax.mail.internet.MimeMessage;
|
||||||
|
import mage.server.util.ConfigSettings;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
public class GmailClient {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(Main.class);
|
||||||
|
private static final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
|
||||||
|
private static final java.io.File DATA_STORE_DIR = new java.io.File(System.getProperty("user.home"), ".store/xmage");
|
||||||
|
private static FileDataStoreFactory dataStoreFactory;
|
||||||
|
private static HttpTransport httpTransport;
|
||||||
|
private static Credential credential;
|
||||||
|
|
||||||
|
public static boolean initilize() {
|
||||||
|
try {
|
||||||
|
dataStoreFactory = new FileDataStoreFactory(DATA_STORE_DIR);
|
||||||
|
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
|
||||||
|
|
||||||
|
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new FileReader("client_secrets.json"));
|
||||||
|
if (clientSecrets.getDetails().getClientId().startsWith("Enter")
|
||||||
|
|| clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
|
||||||
|
logger.error("client_secrets.json not found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
|
||||||
|
httpTransport, JSON_FACTORY, clientSecrets,
|
||||||
|
Collections.singleton(GmailScopes.GMAIL_COMPOSE)).setDataStoreFactory(
|
||||||
|
dataStoreFactory).build();
|
||||||
|
|
||||||
|
credential = new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
|
||||||
|
return true;
|
||||||
|
} catch (IOException | GeneralSecurityException ex) {
|
||||||
|
logger.error("Error initializing GmailClient", ex);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean sendMessage(String email, String subject, String text) {
|
||||||
|
try {
|
||||||
|
Gmail gmail = new Builder(httpTransport, JSON_FACTORY, credential).setApplicationName("XMage Server").build();
|
||||||
|
|
||||||
|
MimeMessage mimeMessage = new MimeMessage(Session.getDefaultInstance(new Properties()));
|
||||||
|
mimeMessage.addRecipient(javax.mail.Message.RecipientType.TO, new InternetAddress(email));
|
||||||
|
mimeMessage.setSubject(subject);
|
||||||
|
mimeMessage.setText(text);
|
||||||
|
|
||||||
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
|
mimeMessage.writeTo(baos);
|
||||||
|
Message message = new Message();
|
||||||
|
message.setRaw(Base64.encodeBase64URLSafeString(baos.toByteArray()));
|
||||||
|
|
||||||
|
gmail.users().messages().send(ConfigSettings.getInstance().getGoogleAccount() + "@gmail.com", message).execute();
|
||||||
|
return true;
|
||||||
|
} catch (MessagingException | IOException ex) {
|
||||||
|
logger.error("Error sending message", ex);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
|
@ -108,6 +108,17 @@ public class Main {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfigSettings config = ConfigSettings.getInstance();
|
||||||
|
if (config.isAuthenticationActivated()) {
|
||||||
|
logger.info("Initializing GmailClient. This will open up a tab in your browser to ask for an OAuth access token.");
|
||||||
|
if (GmailClient.initilize()) {
|
||||||
|
logger.info("GmailClient initilized successfully.");
|
||||||
|
} else {
|
||||||
|
logger.fatal("GmailClient initialization failed.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("Loading cards...");
|
logger.info("Loading cards...");
|
||||||
if (fastDbMode) {
|
if (fastDbMode) {
|
||||||
CardScanner.scanned = true;
|
CardScanner.scanned = true;
|
||||||
|
@ -117,7 +128,6 @@ public class Main {
|
||||||
logger.info("Done.");
|
logger.info("Done.");
|
||||||
|
|
||||||
deleteSavedGames();
|
deleteSavedGames();
|
||||||
ConfigSettings config = ConfigSettings.getInstance();
|
|
||||||
for (GamePlugin plugin: config.getGameTypes()) {
|
for (GamePlugin plugin: config.getGameTypes()) {
|
||||||
GameFactory.getInstance().addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin));
|
GameFactory.getInstance().addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin));
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,6 +87,12 @@ public class Session {
|
||||||
return returnMessage;
|
return returnMessage;
|
||||||
}
|
}
|
||||||
AuthorizedUserRepository.instance.add(userName, password, email);
|
AuthorizedUserRepository.instance.add(userName, password, email);
|
||||||
|
if (GmailClient.sendMessage(email, "XMage Registration Completed",
|
||||||
|
"You are successfully registered as " + userName + ".")) {
|
||||||
|
logger.info("Sent a registration confirmation email to " + email + " for " + userName);
|
||||||
|
} else {
|
||||||
|
logger.error("Failed sending a registration confirmation email to " + email + " for " + userName);
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,8 +120,16 @@ public class ConfigSettings {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Boolean isSaveGameActivated() {
|
public Boolean isSaveGameActivated() {
|
||||||
return config.getServer().isSaveGameActivated();
|
return config.getServer().isSaveGameActivated();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean isAuthenticationActivated() {
|
||||||
|
return config.getServer().isAuthenticationActivated();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGoogleAccount() {
|
||||||
|
return config.getServer().getGoogleAccount();
|
||||||
|
}
|
||||||
|
|
||||||
public List<Plugin> getPlayerTypes() {
|
public List<Plugin> getPlayerTypes() {
|
||||||
return config.getPlayerTypes().getPlayerType();
|
return config.getPlayerTypes().getPlayerType();
|
||||||
|
|
|
@ -2,14 +2,14 @@
|
||||||
|
|
||||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||||
|
|
||||||
<xs:element name="config">
|
<xs:element name="config">
|
||||||
<xs:complexType>
|
<xs:complexType>
|
||||||
<xs:sequence>
|
<xs:sequence>
|
||||||
<xs:element ref="server"/>
|
<xs:element ref="server"/>
|
||||||
<xs:element ref="playerTypes"/>
|
<xs:element ref="playerTypes"/>
|
||||||
<xs:element ref="gameTypes"/>
|
<xs:element ref="gameTypes"/>
|
||||||
<xs:element ref="tournamentTypes"/>
|
<xs:element ref="tournamentTypes"/>
|
||||||
<xs:element ref="draftCubes"/>
|
<xs:element ref="draftCubes"/>
|
||||||
<xs:element ref="deckTypes"/>
|
<xs:element ref="deckTypes"/>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
|
@ -22,16 +22,18 @@
|
||||||
<xs:attribute name="port" type="xs:positiveInteger" use="required"/>
|
<xs:attribute name="port" type="xs:positiveInteger" use="required"/>
|
||||||
<xs:attribute name="maxGameThreads" type="xs:positiveInteger" use="required"/>
|
<xs:attribute name="maxGameThreads" type="xs:positiveInteger" use="required"/>
|
||||||
<xs:attribute name="maxSecondsIdle" type="xs:positiveInteger" use="required"/>
|
<xs:attribute name="maxSecondsIdle" type="xs:positiveInteger" use="required"/>
|
||||||
<xs:attribute name="secondaryBindPort" type="xs:integer" use="required"/>
|
<xs:attribute name="secondaryBindPort" type="xs:integer" use="required"/>
|
||||||
<xs:attribute name="backlogSize" type="xs:positiveInteger" use="required"/>
|
<xs:attribute name="backlogSize" type="xs:positiveInteger" use="required"/>
|
||||||
<xs:attribute name="numAcceptThreads" type="xs:positiveInteger" use="required"/>
|
<xs:attribute name="numAcceptThreads" type="xs:positiveInteger" use="required"/>
|
||||||
<xs:attribute name="maxPoolSize" type="xs:positiveInteger" use="required"/>
|
<xs:attribute name="maxPoolSize" type="xs:positiveInteger" use="required"/>
|
||||||
<xs:attribute name="leasePeriod" type="xs:positiveInteger" use="required"/>
|
<xs:attribute name="leasePeriod" type="xs:positiveInteger" use="required"/>
|
||||||
<xs:attribute name="minUserNameLength" type="xs:positiveInteger" use="required"/>
|
<xs:attribute name="minUserNameLength" type="xs:positiveInteger" use="required"/>
|
||||||
<xs:attribute name="maxUserNameLength" type="xs:positiveInteger" use="required"/>
|
<xs:attribute name="maxUserNameLength" type="xs:positiveInteger" use="required"/>
|
||||||
<xs:attribute name="userNamePattern" type="xs:string" use="required"/>
|
<xs:attribute name="userNamePattern" type="xs:string" use="required"/>
|
||||||
<xs:attribute name="maxAiOpponents" type="xs:string" use="optional"/>
|
<xs:attribute name="maxAiOpponents" type="xs:string" use="optional"/>
|
||||||
<xs:attribute name="saveGameActivated" type="xs:boolean" use="optional"/>
|
<xs:attribute name="saveGameActivated" type="xs:boolean" use="optional"/>
|
||||||
|
<xs:attribute name="authenticationActivated" type="xs:boolean" use="optional"/>
|
||||||
|
<xs:attribute name="googleAccount" type="xs:string" use="optional"/>
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue