рефакторинг
This commit is contained in:
64
src/_VisualDVM/Passes/All/ConfirmEmail.java
Normal file
64
src/_VisualDVM/Passes/All/ConfirmEmail.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package _VisualDVM.Passes.All;
|
||||
import Common.Utils.Utils_;
|
||||
import Common.Visual.UI;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.UI.UserAccountDialog;
|
||||
import _VisualDVM.ComponentsServer.UserAccount.UserAccount;
|
||||
import _VisualDVM.Global;
|
||||
import _VisualDVM.Passes.Server.ComponentsServerPass;
|
||||
import _VisualDVM.Repository.EmailMessage;
|
||||
import _VisualDVM.Repository.Server.ServerCode;
|
||||
|
||||
import javax.swing.*;
|
||||
public class ConfirmEmail extends ComponentsServerPass<UserAccount> {
|
||||
String password;
|
||||
UserAccountDialog f = new UserAccountDialog() {
|
||||
{
|
||||
fields.tfName.setText(Global.normalProperties.Email);
|
||||
fields.tfAddress.setText(Global.normalProperties.Email);
|
||||
fields.cbRole.setEnabled(false);
|
||||
}
|
||||
};
|
||||
public static int getRandomIntegerBetweenRange(int min, int max) {
|
||||
return (int) ((Math.random() * ((max - min) + 1)) + min);
|
||||
}
|
||||
@Override
|
||||
protected boolean isSafe() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected boolean canStart(Object... args) throws Exception {
|
||||
target = new UserAccount(); // объект для заполнения полей.не более.
|
||||
password = null;
|
||||
if (f.ShowDialog("Регистрация", target)) {
|
||||
if (!Utils_.validateEmail(target.email, Log)) {
|
||||
return false;
|
||||
}
|
||||
password = String.valueOf(getRandomIntegerBetweenRange(1111, 9999));
|
||||
return SendRequest(ServerCode.Email,
|
||||
target.email,
|
||||
new EmailMessage("Код подтверждения визуализатора для: " + Utils_.Brackets(target.name), password));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected boolean validate() {
|
||||
String attempt = null;
|
||||
do {
|
||||
attempt = JOptionPane.showInputDialog(null,
|
||||
new String[]{"Введите код активации, полученный по почте"},
|
||||
"Подтверждение адреса почты",
|
||||
JOptionPane.INFORMATION_MESSAGE);
|
||||
if (attempt != null) {
|
||||
if (attempt.equals(password)) {
|
||||
UI.Info("Почта успешно подтверждена!");
|
||||
return true;
|
||||
} else {
|
||||
UI.Error("Неверный код активации.\nПовторите попытку.");
|
||||
}
|
||||
} else {
|
||||
UI.Info("Подтверждение почты отменено");
|
||||
return false;
|
||||
}
|
||||
} while (true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user