mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +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">
|
||||
<Group type="103" groupAlignment="0" 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"/>
|
||||
<Group type="103" groupAlignment="0" attributes="0">
|
||||
<Component id="lblStatus" min="-2" pref="292" max="-2" attributes="0"/>
|
||||
<Group type="103" groupAlignment="1" max="-2" attributes="0">
|
||||
<Group type="103" groupAlignment="0" max="-2" attributes="0">
|
||||
<Group type="103" alignment="0" groupAlignment="1" attributes="0">
|
||||
<Component id="lblPasswordConfirmationReasoning" min="-2" max="-2" 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"/>
|
||||
<EmptySpace max="-2" attributes="0"/>
|
||||
<Component id="btnCancel" min="-2" max="-2" attributes="0"/>
|
||||
</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>
|
||||
<Component id="txtPort" min="-2" pref="292" max="-2" attributes="0"/>
|
||||
<Component id="lblStatus" alignment="0" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="16" max="32767" attributes="0"/>
|
||||
<EmptySpace pref="22" max="32767" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
@ -80,14 +83,26 @@
|
|||
<Component id="lblPassword" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
<Component id="txtPassword" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</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"/>
|
||||
<EmptySpace max="-2" 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="btnRegister" alignment="3" min="-2" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
<EmptySpace pref="14" max="32767" attributes="0"/>
|
||||
<EmptySpace type="unrelated" max="-2" attributes="0"/>
|
||||
</Group>
|
||||
</Group>
|
||||
</DimensionLayout>
|
||||
|
@ -157,5 +172,48 @@
|
|||
</Component>
|
||||
<Component class="javax.swing.JTextField" name="txtPort">
|
||||
</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>
|
||||
</Form>
|
||||
|
|
|
@ -56,6 +56,12 @@ public class RegisterUserDialog extends MageDialog {
|
|||
lblStatus = new javax.swing.JLabel();
|
||||
txtServer = 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);
|
||||
setTitle("Register");
|
||||
|
@ -94,34 +100,53 @@ public class RegisterUserDialog extends MageDialog {
|
|||
|
||||
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());
|
||||
getContentPane().setLayout(layout);
|
||||
layout.setHorizontalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGap(14, 14, 14)
|
||||
.addComponent(lblUserName))
|
||||
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblPassword, javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(lblPort, javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(lblServer, javax.swing.GroupLayout.Alignment.TRAILING))))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(lblStatus, javax.swing.GroupLayout.PREFERRED_SIZE, 292, javax.swing.GroupLayout.PREFERRED_SIZE)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
|
||||
.addContainerGap()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(lblPasswordConfirmationReasoning)
|
||||
.addGroup(layout.createSequentialGroup()
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
|
||||
.addComponent(lblServer)
|
||||
.addComponent(lblUserName)
|
||||
.addComponent(lblPort)
|
||||
.addComponent(lblPassword)
|
||||
.addComponent(lblPasswordConfirmation)
|
||||
.addComponent(lblEmail))
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.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()
|
||||
.addComponent(btnRegister)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addComponent(btnCancel))
|
||||
.addComponent(txtUserName, javax.swing.GroupLayout.Alignment.LEADING)
|
||||
.addComponent(txtPassword, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 292, 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))
|
||||
.addComponent(btnCancel)))
|
||||
.addComponent(lblStatus, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
|
||||
.addContainerGap(22, Short.MAX_VALUE))
|
||||
);
|
||||
layout.setVerticalGroup(
|
||||
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
|
||||
|
@ -142,13 +167,24 @@ public class RegisterUserDialog extends MageDialog {
|
|||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(lblPassword)
|
||||
.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)
|
||||
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
|
||||
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
|
||||
.addComponent(btnRegister)
|
||||
.addComponent(btnCancel))
|
||||
.addContainerGap(14, Short.MAX_VALUE))
|
||||
.addComponent(btnCancel)
|
||||
.addComponent(btnRegister))
|
||||
.addContainerGap())
|
||||
);
|
||||
|
||||
pack();
|
||||
|
@ -163,11 +199,16 @@ public class RegisterUserDialog extends MageDialog {
|
|||
}//GEN-LAST:event_btnCancelActionPerformed
|
||||
|
||||
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.setHost(this.txtServer.getText().trim());
|
||||
connection.setPort(Integer.valueOf(this.txtPort.getText().trim()));
|
||||
connection.setUsername(this.txtUserName.getText().trim());
|
||||
connection.setPassword(this.txtPassword.getText().trim());
|
||||
connection.setEmail(this.txtEmail.getText().trim());
|
||||
PreferencesDialog.setProxyInformation(connection);
|
||||
task = new ConnectTask();
|
||||
task.execute();
|
||||
|
@ -218,12 +259,18 @@ public class RegisterUserDialog extends MageDialog {
|
|||
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||
private javax.swing.JButton btnCancel;
|
||||
private javax.swing.JButton btnRegister;
|
||||
private javax.swing.JLabel lblEmail;
|
||||
private javax.swing.JLabel lblEmailReasoning;
|
||||
private javax.swing.JLabel lblPassword;
|
||||
private javax.swing.JLabel lblPasswordConfirmation;
|
||||
private javax.swing.JLabel lblPasswordConfirmationReasoning;
|
||||
private javax.swing.JLabel lblPort;
|
||||
private javax.swing.JLabel lblServer;
|
||||
private javax.swing.JLabel lblStatus;
|
||||
private javax.swing.JLabel lblUserName;
|
||||
private javax.swing.JTextField txtEmail;
|
||||
private javax.swing.JPasswordField txtPassword;
|
||||
private javax.swing.JPasswordField txtPasswordConfirmation;
|
||||
private javax.swing.JTextField txtPort;
|
||||
private javax.swing.JTextField txtServer;
|
||||
private javax.swing.JTextField txtUserName;
|
||||
|
|
|
@ -45,6 +45,7 @@ public class Connection {
|
|||
private int port;
|
||||
private String username;
|
||||
private String password;
|
||||
private String email;
|
||||
private String adminPassword;
|
||||
private ProxyType proxyType;
|
||||
private String proxyHost;
|
||||
|
@ -173,6 +174,14 @@ public class Connection {
|
|||
this.password = password;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getAdminPassword() {
|
||||
return adminPassword;
|
||||
}
|
||||
|
|
|
@ -195,7 +195,7 @@ public class SessionImpl implements Session {
|
|||
public boolean run() throws Throwable {
|
||||
logger.info("Trying to register as " + getUserName() + " to XMAGE server at " + connection.getHost() + ":" + connection.getPort());
|
||||
boolean registerResult = server.registerUser(sessionId, connection.getUsername(),
|
||||
connection.getPassword(), "");
|
||||
connection.getPassword(), connection.getEmail());
|
||||
if (registerResult) {
|
||||
logger.info("Registered as " + getUserName() + " to MAGE server at " + connection.getHost() + ":" + connection.getPort());
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
userNamePattern="[^a-z0-9_]"
|
||||
maxAiOpponents="15"
|
||||
saveGameActivated="false"
|
||||
authenticationActivated="false"
|
||||
googleAccount=""
|
||||
/>
|
||||
<playerTypes>
|
||||
<playerType name="Human" jar="mage-player-human.jar" className="mage.player.human.HumanPlayer"/>
|
||||
|
|
|
@ -154,6 +154,36 @@
|
|||
<version>1.2.4</version>
|
||||
<type>jar</type>
|
||||
</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>
|
||||
|
||||
<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;
|
||||
}
|
||||
}
|
|
@ -107,7 +107,18 @@ public class Main {
|
|||
fastDbMode = Boolean.valueOf(arg.replace(fastDBModeArg, ""));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
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...");
|
||||
if (fastDbMode) {
|
||||
CardScanner.scanned = true;
|
||||
|
@ -117,7 +128,6 @@ public class Main {
|
|||
logger.info("Done.");
|
||||
|
||||
deleteSavedGames();
|
||||
ConfigSettings config = ConfigSettings.getInstance();
|
||||
for (GamePlugin plugin: config.getGameTypes()) {
|
||||
GameFactory.getInstance().addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin));
|
||||
}
|
||||
|
|
|
@ -87,6 +87,12 @@ public class Session {
|
|||
return returnMessage;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,7 +94,7 @@ public class ConfigSettings {
|
|||
public int getBacklogSize() {
|
||||
return config.getServer().getBacklogSize().intValue();
|
||||
}
|
||||
|
||||
|
||||
public int getMaxGameThreads() {
|
||||
return config.getServer().getMaxGameThreads().intValue();
|
||||
}
|
||||
|
@ -114,14 +114,22 @@ public class ConfigSettings {
|
|||
public String getUserNamePattern() {
|
||||
return config.getServer().getUserNamePattern();
|
||||
}
|
||||
|
||||
|
||||
public String getMaxAiOpponents() {
|
||||
return config.getServer().getMaxAiOpponents();
|
||||
}
|
||||
|
||||
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() {
|
||||
return config.getPlayerTypes().getPlayerType();
|
||||
|
|
|
@ -2,19 +2,19 @@
|
|||
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
||||
|
||||
<xs:element name="config">
|
||||
<xs:element name="config">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element ref="server"/>
|
||||
<xs:element ref="playerTypes"/>
|
||||
<xs:element ref="gameTypes"/>
|
||||
<xs:element ref="tournamentTypes"/>
|
||||
<xs:element ref="draftCubes"/>
|
||||
<xs:element ref="draftCubes"/>
|
||||
<xs:element ref="deckTypes"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
|
||||
<xs:element name="server">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="serverAddress" type="xs:string" use="required"/>
|
||||
|
@ -22,16 +22,18 @@
|
|||
<xs:attribute name="port" 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="secondaryBindPort" type="xs:integer" use="required"/>
|
||||
<xs:attribute name="backlogSize" 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="leasePeriod" 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="userNamePattern" type="xs:string" use="required"/>
|
||||
<xs:attribute name="maxAiOpponents" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="saveGameActivated" type="xs:boolean" use="optional"/>
|
||||
<xs:attribute name="secondaryBindPort" type="xs:integer" use="required"/>
|
||||
<xs:attribute name="backlogSize" 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="leasePeriod" 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="userNamePattern" type="xs:string" use="required"/>
|
||||
<xs:attribute name="maxAiOpponents" type="xs:string" 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:element>
|
||||
|
||||
|
@ -56,7 +58,7 @@
|
|||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
|
||||
<xs:element name="gameTypes">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
|
|
Loading…
Reference in a new issue