-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from euseanwoon2016/ming/task/profile-stuff
✨: Added Profile Functionality
- Loading branch information
Showing
10 changed files
with
609 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
src/main/java/com/oodj/vaccspace/controllers/profile/ChangePasswordController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package com.oodj.vaccspace.controllers.profile; | ||
|
||
import com.oodj.vaccspace.Global; | ||
import com.oodj.vaccspace.controllers.BaseController; | ||
import com.oodj.vaccspace.models.Person; | ||
import com.oodj.vaccspace.utils.Navigator; | ||
import com.oodj.vaccspace.utils.Page; | ||
import io.github.euseanwoon.MFXPillButton; | ||
import io.github.palexdev.materialfx.controls.MFXPasswordField; | ||
import io.github.palexdev.materialfx.controls.MFXTextField; | ||
import io.github.palexdev.materialfx.controls.enums.DialogType; | ||
import javafx.event.ActionEvent; | ||
import javafx.fxml.FXML; | ||
import javafx.fxml.Initializable; | ||
import javafx.scene.control.ButtonType; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.input.MouseEvent; | ||
import javafx.scene.paint.Color; | ||
import org.kordamp.ikonli.javafx.FontIcon; | ||
|
||
import java.net.URL; | ||
import java.util.Optional; | ||
import java.util.ResourceBundle; | ||
|
||
public class ChangePasswordController extends BaseController implements Initializable { | ||
|
||
Person person = new Person(); | ||
|
||
@FXML | ||
private MFXPillButton btnSaveChanges; | ||
|
||
@FXML | ||
private Label lblClose; | ||
|
||
@FXML | ||
private MFXPasswordField txtNewPassword; | ||
|
||
@FXML | ||
private MFXPasswordField txtOldPassword; | ||
|
||
@FXML | ||
private MFXPasswordField txtRepeatPassword; | ||
|
||
@FXML | ||
void onClosePressed(MouseEvent event) { | ||
getStageDialog().close(); | ||
Navigator.showInDialog(lblClose.getScene().getWindow(),"view_profile", null); | ||
} | ||
|
||
@FXML | ||
void onSaveChangesPressed(ActionEvent event) { | ||
if (!validateInput()) { | ||
return; | ||
} | ||
|
||
Optional<ButtonType> result = Page.showDialogAndWait( | ||
txtNewPassword.getScene().getWindow(), | ||
"Changing password", | ||
"You are about to change your password", | ||
"Do you want to proceed?" | ||
); | ||
if (result.isPresent() && result.get() == ButtonType.OK) { | ||
person.setPassword(txtNewPassword.getPassword()); | ||
person.save(); | ||
|
||
getStageDialog().close(); | ||
Navigator.showInDialog(lblClose.getScene().getWindow(),"view_profile", null); | ||
} | ||
} | ||
|
||
private boolean validateInput() { | ||
person = Global.getLoggedInUser(); | ||
|
||
//Empty Fields Validation | ||
if (txtNewPassword.getPassword().equals("") || | ||
txtOldPassword.getPassword().equals("") || | ||
txtRepeatPassword.getPassword().equals("") | ||
) { | ||
Page.showDialog( | ||
txtNewPassword.getScene().getWindow(), | ||
DialogType.ERROR, | ||
"Error: Empty fields", | ||
"All fields must be filled in!" | ||
); | ||
return false; | ||
} | ||
|
||
if (!txtRepeatPassword.getPassword().equals(txtNewPassword.getPassword())) { | ||
Page.showDialog( | ||
txtRepeatPassword.getScene().getWindow(), | ||
DialogType.ERROR, | ||
"Error: Repeat password is wrong", | ||
"Please ensure the repeated password is correct!" | ||
); | ||
return false; | ||
} | ||
|
||
if (!txtOldPassword.getPassword().equals(person.getPassword())) { | ||
Page.showDialog( | ||
txtOldPassword.getScene().getWindow(), | ||
DialogType.ERROR, | ||
"Error: Wrong Password", | ||
"Old Password is wrong!" | ||
); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public void initialize(URL location, ResourceBundle resources) { | ||
FontIcon icon = new FontIcon("fas-arrow-left"); | ||
icon.setIconColor(Color.WHITE); | ||
icon.setIconSize(18); | ||
|
||
lblClose.setGraphic(icon); | ||
} | ||
} |
181 changes: 181 additions & 0 deletions
181
src/main/java/com/oodj/vaccspace/controllers/profile/ViewProfileController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
package com.oodj.vaccspace.controllers.profile; | ||
|
||
import com.oodj.vaccspace.Global; | ||
import com.oodj.vaccspace.controllers.BaseController; | ||
import com.oodj.vaccspace.models.Person; | ||
import com.oodj.vaccspace.utils.Navigator; | ||
import com.oodj.vaccspace.utils.Page; | ||
import com.oodj.vaccspace.utils.ValidationHelper; | ||
import io.github.euseanwoon.MFXPillButton; | ||
import io.github.palexdev.materialfx.controls.MFXCheckbox; | ||
import io.github.palexdev.materialfx.controls.MFXTextField; | ||
import io.github.palexdev.materialfx.controls.enums.DialogType; | ||
import javafx.event.ActionEvent; | ||
import javafx.fxml.FXML; | ||
import javafx.fxml.Initializable; | ||
import javafx.scene.control.ButtonType; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.input.MouseEvent; | ||
import javafx.scene.paint.Color; | ||
import org.kordamp.ikonli.javafx.FontIcon; | ||
import textorm.TextORM; | ||
|
||
import java.net.URL; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.ResourceBundle; | ||
|
||
public class ViewProfileController extends BaseController implements Initializable { | ||
|
||
Person person = new Person(); | ||
|
||
@FXML | ||
private MFXPillButton btnChangePassword; | ||
|
||
@FXML | ||
private MFXPillButton btnDelete; | ||
|
||
@FXML | ||
private MFXPillButton btnEditPerson; | ||
|
||
@FXML | ||
private MFXPillButton btnSaveChanges; | ||
|
||
@FXML | ||
private MFXCheckbox chkIsNonCitizen; | ||
|
||
@FXML | ||
private Label lblClose; | ||
|
||
@FXML | ||
private MFXTextField txtEmail; | ||
|
||
@FXML | ||
private MFXTextField txtName; | ||
|
||
@FXML | ||
private MFXTextField txtPhoneNumber; | ||
|
||
@FXML | ||
void onClosePressed(MouseEvent event) { | ||
getStageDialog().close(); | ||
} | ||
|
||
@FXML | ||
void onChangePasswordPressed(ActionEvent event) { | ||
Navigator.showInDialog(btnChangePassword.getScene().getWindow(),"change_password", null); | ||
} | ||
|
||
@FXML | ||
void onEditPersonPressed(ActionEvent event) { | ||
btnEditPerson.setManaged(false); | ||
btnSaveChanges.setManaged(true); | ||
|
||
txtPhoneNumber.setDisable(false); | ||
txtEmail.setDisable(false); | ||
chkIsNonCitizen.setDisable(false); | ||
|
||
txtPhoneNumber.setStyle("-fx-opacity: 0.99"); | ||
txtEmail.setStyle("-fx-opacity: 0.99"); | ||
} | ||
|
||
@FXML | ||
void onSaveChangesPressed(ActionEvent event) { | ||
if (!validateInput()) { | ||
return; | ||
} | ||
|
||
|
||
Optional<ButtonType> result = Page.showDialogAndWait( | ||
txtEmail.getScene().getWindow(), | ||
"Edit Profile", | ||
"You are about to edit your profile details", | ||
"Do you want to proceed?" | ||
); | ||
if (result.isPresent() && result.get() == ButtonType.OK) { | ||
person.setPhone(txtPhoneNumber.getText()); | ||
person.setEmail(txtEmail.getText()); | ||
person.setNonCitizen(chkIsNonCitizen.isSelected()); | ||
person.save(); | ||
|
||
getStageDialog().close(); | ||
} | ||
} | ||
|
||
private boolean validateInput() { | ||
//Empty Fields Validation | ||
if (txtEmail.getText().equals("") || | ||
txtPhoneNumber.getText().equals("") | ||
) { | ||
Page.showDialog( | ||
txtName.getScene().getWindow(), | ||
DialogType.ERROR, | ||
"Error: Empty fields", | ||
"All fields must be filled in!" | ||
); | ||
return false; | ||
} | ||
|
||
//Phone Validation | ||
if (!txtPhoneNumber.getText().matches("^[0-9]{4,}$")) { | ||
Page.showDialog( | ||
txtName.getScene().getWindow(), | ||
DialogType.ERROR, | ||
"Error: Invalid Phone", | ||
"Phone number must only have numbers!" | ||
); | ||
return false; | ||
} | ||
|
||
//Email Validation | ||
if (!ValidationHelper.isValidEmail(txtEmail.getText())) { | ||
Page.showDialog( | ||
txtName.getScene().getWindow(), | ||
DialogType.ERROR, | ||
"Error: Invalid Email", | ||
"Invalid Email Address!" | ||
); | ||
return false; | ||
} | ||
|
||
//Email Duplication Validation | ||
Person duplicate = TextORM.getOne( | ||
Person.class, | ||
data -> Objects.equals(data.get("email"), txtEmail.getText()) && | ||
Integer.parseInt(data.get("id")) != person.getId() | ||
); | ||
|
||
if (duplicate != null) { | ||
Page.showDialog( | ||
txtName.getScene().getWindow(), | ||
DialogType.ERROR, | ||
"Error: Duplicate Email", | ||
"The given email is already registered!" | ||
); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public void initialize(URL location, ResourceBundle resources) { | ||
FontIcon icon = new FontIcon("fas-times"); | ||
icon.setIconColor(Color.WHITE); | ||
icon.setIconSize(18); | ||
|
||
lblClose.setGraphic(icon); | ||
} | ||
|
||
@Override | ||
public void onLoaded() { | ||
btnSaveChanges.setManaged(false); | ||
|
||
person = Global.getLoggedInUser(); | ||
|
||
txtName.setText(person.getName()); | ||
txtPhoneNumber.setText(person.getPhone()); | ||
txtEmail.setText(person.getEmail()); | ||
chkIsNonCitizen.setSelected(person.isNonCitizen()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.