You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.3 KiB
46 lines
1.3 KiB
package controller;
|
|
import service.*;
|
|
import view.*;
|
|
|
|
public class AuthController {
|
|
private UserService userService = new UserService();
|
|
private EmailService emailService = new EmailService();
|
|
private MainController mainController;
|
|
private String currentUser;
|
|
|
|
public AuthController(MainController mainController) {
|
|
this.mainController = mainController;
|
|
}
|
|
|
|
public boolean login(String email, String password) {
|
|
if (userService.login(email, password)) {
|
|
currentUser = email;
|
|
mainController.showMainFrame();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public String register(String email) {
|
|
String code = userService.registerUser(email);
|
|
if (code != null) {
|
|
int sendResult = emailService.sendRegistrationCode(email, code);
|
|
if (sendResult == 1) {
|
|
return code;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public boolean completeRegistration(String email, String code, String password, String confirmPassword) {
|
|
return password.equals(confirmPassword) && userService.completeRegistration(email, code, password);
|
|
}
|
|
|
|
public void showLogin() {
|
|
new LoginFrame(this);
|
|
}
|
|
|
|
public void showRegister() {
|
|
new RegisterFrame(this);
|
|
}
|
|
} |