Files
VisualSapfor/src/Visual_DVM_2021/Passes/All/EditAccount.java
2024-10-12 00:17:51 +03:00

70 lines
2.8 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package Visual_DVM_2021.Passes.All;
import Common.Utils.Utils_;
import Common.Visual.UI_;
import _VisualDVM.Current;
import _VisualDVM.Global;
import _VisualDVM.Repository.EmailMessage;
import _VisualDVM.Repository.Subscribes.Subscriber;
import _VisualDVM.Repository.Subscribes.UI.SubscriberForm;
import javax.swing.*;
import java.util.Vector;
public class EditAccount extends Email {
public String name;
public String email;
String password;
SubscriberForm f = new SubscriberForm(){
{
fields.cbRole.setEnabled(false);
}
};
public static int getRandomIntegerBetweenRange(int min, int max) {
return (int) ((Math.random() * ((max - min) + 1)) + min);
}
@Override
protected boolean canStart(Object... args) throws Exception {
Subscriber res = new Subscriber(); // объект для заполнения полей.не более.
if (f.ShowDialog("Регистрация", res)) {
if (!Utils_.validateEmail(res.address, Log)) {
return false;
}
name = res.name;
email = res.address;
Vector<String> rec = new Vector<>();
rec.add(email);
password = String.valueOf(getRandomIntegerBetweenRange(1111, 9999));
return super.canStart(new EmailMessage("Код подтверждения визуализатора для: " + Utils_.Brackets(name), password, rec));
}
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("Неверный код активации.\овторите попытку.");
}
} else {
UI_.Info("Подтверждение почты отменено");
return false;
}
} while (true);
}
@Override
protected void performDone() throws Exception {
super.performDone();
Current.getAccount().name = name;
Current.getAccount().email = email;
Global.mainModule.getDb().Update(Current.getAccount());
//это не регистрация. только заполнение почты в своей бд и ее подтверждение на реальность.
}
}