/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package club.ui;
import club.data.DataAdmin;
import club.data.DataConfig;
import club.data.DataMember;
import club.ulti.Validator;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
/**
*
* @author Quang
*/
public class Password extends javax.swing.JDialog {
/**
* Creates new form Password
*/
public Password(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
this.setLocation(500,200);
}
private ArrayList validateForm(){
ArrayList errors = new ArrayList();
if (!Validator.checkPassword(tfNewPassword.getPassword())){
errors.add("Password has at least 5 characters!");
}
if (!Validator.checkMatchPassword(tfNewPassword.getText(), tfConfirmPassword.getText())){
errors.add("Password does not match the confirm!");
}
return errors;
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
tfOldPassword = new javax.swing.JPasswordField();
jLabel3 = new javax.swing.JLabel();
tfNewPassword = new javax.swing.JPasswordField();
jLabel4 = new javax.swing.JLabel();
tfConfirmPassword = new javax.swing.JPasswordField();
btn_Submit = new javax.swing.JButton();
btnCancel = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Change your password");
setResizable(false);
jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
jLabel1.setText("Change password");
jLabel2.setText("Old password");
tfOldPassword.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
tfOldPasswordFocusGained(evt);
}
});
jLabel3.setText("New password");
tfNewPassword.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
tfNewPasswordFocusGained(evt);
}
});
tfNewPassword.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
tfNewPasswordKeyReleased(evt);
}
});
jLabel4.setText("Confirm ");
tfConfirmPassword.addFocusListener(new java.awt.event.FocusAdapter() {
public void focusGained(java.awt.event.FocusEvent evt) {
tfConfirmPasswordFocusGained(evt);
}
});
tfConfirmPassword.addKeyListener(new java.awt.event.KeyAdapter() {
public void keyReleased(java.awt.event.KeyEvent evt) {
tfConfirmPasswordKeyReleased(evt);
}
});
btn_Submit.setText("Submit");
btn_Submit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_SubmitActionPerformed(evt);
}
});
btnCancel.setText("Cancel");
btnCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnCancelActionPerformed(evt);
}
});
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(29, 29, 29)
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel2)
.addComponent(jLabel4))
.addGap(25, 25, 25)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(tfNewPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
.addComponent(tfOldPassword)
.addComponent(tfConfirmPassword))))
.addContainerGap(20, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(btn_Submit)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(btnCancel)
.addGap(79, 79, 79))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCancel, btn_Submit});
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(tfOldPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(tfNewPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(tfConfirmPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(btnCancel)
.addComponent(btn_Submit, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.linkSize(javax.swing.SwingConstants.VERTICAL, new java.awt.Component[] {btnCancel, btn_Submit});
pack();
}// </editor-fold>//GEN-END:initComponents
private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
// TODO add your handling code here:
this.dispose();
}//GEN-LAST:event_btnCancelActionPerformed
private void tfOldPasswordFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfOldPasswordFocusGained
// TODO add your handling code herethi
tfOldPassword.selectAll();
}//GEN-LAST:event_tfOldPasswordFocusGained
private void tfNewPasswordFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfNewPasswordFocusGained
// TODO add your handling code here:
tfNewPassword.selectAll();
}//GEN-LAST:event_tfNewPasswordFocusGained
private void tfConfirmPasswordFocusGained(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfConfirmPasswordFocusGained
// TODO add your handling code here:
tfConfirmPassword.selectAll();
}//GEN-LAST:event_tfConfirmPasswordFocusGained
private void tfNewPasswordKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfNewPasswordKeyReleased
// TODO add your handling code here:
Validator.Validate(tfNewPassword, Validator.checkPassword(tfNewPassword.getPassword()));
}//GEN-LAST:event_tfNewPasswordKeyReleased
private void tfConfirmPasswordKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tfConfirmPasswordKeyReleased
// TODO add your handling code here:
Validator.Validate(tfConfirmPassword, Validator.checkMatchPassword(tfNewPassword.getText(), tfConfirmPassword.getText()));
}//GEN-LAST:event_tfConfirmPasswordKeyReleased
private void btn_SubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_SubmitActionPerformed
// TODO add your handling code here:
DataConfig dt = new DataConfig();
int adminID = dt.getCurrentAdminID();
String rightPass = DataAdmin.getAdminByID(adminID).getPassword();
if (rightPass.equals(tfOldPassword.getText())){
if (validateForm().size() == 0){
if (DataAdmin.updateAdminByID("Password", tfNewPassword.getText(), adminID)){
JOptionPane.showMessageDialog(rootPane, ("OK!"));
this.dispose();
} else{
JOptionPane.showMessageDialog(rootPane, "Unknown Error! Please try again", "Error", JOptionPane.ERROR_MESSAGE);
}
} else{
Validator.showErrors(validateForm());
}
} else{
JOptionPane.showMessageDialog(rootPane, "Wrong password", "Error", JOptionPane.ERROR_MESSAGE);
}
}//GEN-LAST:event_btn_SubmitActionPerformed
/**
* @param args the command line arguments
*/
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnCancel;
private javax.swing.JButton btn_Submit;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JPasswordField tfConfirmPassword;
private javax.swing.JPasswordField tfNewPassword;
private javax.swing.JPasswordField tfOldPassword;
// End of variables declaration//GEN-END:variables
}