Skip to content

Commit afb411a

Browse files
committed
validation update on change password form
1 parent 003c8e1 commit afb411a

File tree

5 files changed

+61
-116
lines changed

5 files changed

+61
-116
lines changed

sormas-app/app/src/main/java/de/symeda/sormas/app/component/controls/ControlPasswordField.java

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,59 +15,60 @@
1515

1616
package de.symeda.sormas.app.component.controls;
1717

18-
import com.google.android.material.textfield.TextInputLayout;
19-
2018
import android.content.Context;
2119
import android.text.InputType;
2220
import android.util.AttributeSet;
2321
import android.view.LayoutInflater;
2422

23+
import com.google.android.material.textfield.TextInputLayout;
24+
2525
import de.symeda.sormas.app.R;
2626

2727
public class ControlPasswordField extends ControlTextEditField {
2828

29-
// Constructors
30-
31-
public ControlPasswordField(Context context) {
32-
super(context);
33-
}
34-
35-
public ControlPasswordField(Context context, AttributeSet attrs) {
36-
super(context, attrs);
37-
}
38-
39-
public ControlPasswordField(Context context, AttributeSet attrs, int defStyle) {
40-
super(context, attrs, defStyle);
41-
}
42-
43-
// Overrides
44-
45-
@Override
46-
protected void initialize(Context context, AttributeSet attrs, int defStyle) {
47-
super.initialize(context, attrs, defStyle);
48-
49-
setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
50-
}
51-
52-
@Override
53-
protected void inflateView(Context context, AttributeSet attrs, int defStyle) {
54-
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
55-
56-
if (inflater != null) {
57-
if (isSlim()) {
58-
inflater.inflate(R.layout.control_password_slim_layout, this);
59-
} else {
60-
inflater.inflate(R.layout.control_password_layout, this);
61-
}
62-
} else {
63-
throw new RuntimeException("Unable to inflate layout in " + getClass().getName());
64-
}
65-
}
66-
67-
@Override
68-
protected void onFinishInflate() {
69-
super.onFinishInflate();
70-
TextInputLayout inputLayout = (TextInputLayout) this.findViewById(R.id.text_input_layout);
71-
inputLayout.setPasswordVisibilityToggleEnabled(true);
72-
}
29+
// Constructors
30+
31+
public ControlPasswordField(Context context) {
32+
super(context);
33+
}
34+
35+
public ControlPasswordField(Context context, AttributeSet attrs) {
36+
super(context, attrs);
37+
}
38+
39+
public ControlPasswordField(Context context, AttributeSet attrs, int defStyle) {
40+
super(context, attrs, defStyle);
41+
}
42+
43+
// Overrides
44+
45+
@Override
46+
protected void initialize(Context context, AttributeSet attrs, int defStyle) {
47+
super.initialize(context, attrs, defStyle);
48+
49+
setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
50+
}
51+
52+
@Override
53+
protected void inflateView(Context context, AttributeSet attrs, int defStyle) {
54+
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
55+
56+
if (inflater != null) {
57+
if (isSlim()) {
58+
inflater.inflate(R.layout.control_password_slim_layout, this);
59+
} else {
60+
inflater.inflate(R.layout.control_password_layout, this);
61+
}
62+
} else {
63+
throw new RuntimeException("Unable to inflate layout in " + getClass().getName());
64+
}
65+
}
66+
67+
@Override
68+
protected void onFinishInflate() {
69+
super.onFinishInflate();
70+
TextInputLayout inputLayout = (TextInputLayout) this.findViewById(R.id.text_input_layout);
71+
inputLayout.setPasswordVisibilityToggleEnabled(true);
72+
}
73+
7374
}

sormas-app/app/src/main/java/de/symeda/sormas/app/login/ChangePasswordActivity.java

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -206,69 +206,52 @@ public void onFailure(Call<String> call, Throwable t) {
206206
* When clicked on submit
207207
**/
208208
public void savePassword(View view) {
209-
// Disable error states
210209
binding.changePasswordNewPassword.disableErrorState();
211210
binding.changePasswordCurrentPassword.disableErrorState();
212211
binding.changePasswordConfirmPassword.disableErrorState();
213212

214-
// Check if server URL is configured
215213
if (DataHelper.isNullOrEmpty(ConfigProvider.getServerRestUrl())) {
216214
NavigationHelper.goToSettings(this);
217215
return;
218216
}
219217

220-
// Retrieve password values
221218
String currentPassword = binding.changePasswordCurrentPassword.getValue();
222219
String newPassword = binding.changePasswordNewPassword.getValue();
223220
String confirmPassword = binding.changePasswordConfirmPassword.getValue();
224221
String configPassword = ConfigProvider.getPassword();
225222

226-
// Validate input fields
227223
boolean isValid = true;
224+
228225
if (currentPassword == null || currentPassword.trim().isEmpty()) {
229-
binding.incorrectCurrentPassword.setVisibility(View.VISIBLE);
230-
binding.incorrectCurrentPassword.setText("Current password cannot be empty.");
226+
binding.changePasswordCurrentPassword.enableErrorState(R.string.error_current_password_empty);
231227
isValid = false;
232228
}
233229
if (newPassword == null || newPassword.trim().isEmpty()) {
234-
binding.incorrectNewPassword.setVisibility(View.VISIBLE);
235-
binding.incorrectNewPassword.setText("New password cannot be empty.");
230+
binding.changePasswordNewPassword.enableErrorState(R.string.error_new_password_empty);
236231
isValid = false;
237232
}
238233
if (confirmPassword == null || confirmPassword.trim().isEmpty()) {
239-
binding.incorrectConfirmPassword.setVisibility(View.VISIBLE);
240-
binding.incorrectConfirmPassword.setText("Confirm password cannot be empty.");
234+
binding.changePasswordConfirmPassword.enableErrorState(R.string.error_confirm_password_empty);
241235
isValid = false;
242236
}
243237
if (!configPassword.equals(currentPassword)) {
244-
binding.incorrectCurrentPassword.setVisibility(View.VISIBLE);
245-
binding.incorrectCurrentPassword.setText("Current password is incorrect.");
238+
binding.changePasswordCurrentPassword.enableErrorState(R.string.error_current_password_incorrect);
246239
isValid = false;
247240
}
248241
if (!newPassword.equals(confirmPassword)) {
249-
binding.incorrectConfirmPassword.setVisibility(View.VISIBLE);
250-
binding.incorrectConfirmPassword.setText("Passwords do not match.");
242+
binding.changePasswordConfirmPassword.enableErrorState(R.string.error_passwords_do_not_match);
251243
isValid = false;
252244
}
253245

254-
// If all validations pass, proceed with the password change
255-
System.out.println("isValid: " + isValid);
256-
System.out.println("isGood: " + isGood);
257-
System.out.println("currentPassword: " + currentPassword);
258-
System.out.println("newPassword: " + newPassword);
259-
System.out.println("confirmPassword: " + confirmPassword);
260-
System.out.println("configPassword: " + configPassword);
261-
// Call registrationDataCheck if necessary
262246
if (isValid) {
263247
registrationDataCheck(view);
264248
}
265-
249+
266250
if (isValid && isGood) {
267251
RetroProvider.connectAsyncHandled(this, true, true, result -> {
268252
if (Boolean.TRUE.equals(result)) {
269253
try {
270254
executeSaveNewPasswordCall(UserDtoHelper.saveNewPassword(ConfigProvider.getUser().getUuid(), newPassword, currentPassword));
271-
// Cache the new password
272255
setNewPassword(newPassword);
273256
} catch (Exception e) {
274257
binding.actionPasswordStrength.setVisibility(View.VISIBLE);

sormas-app/app/src/main/res/layout/activity_change_password_layout.xml

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -78,20 +78,11 @@
7878
app:value="@={data.currentPassword}"
7979

8080
/>
81-
<!---for error-->
82-
<TextView
83-
android:id="@+id/incorrect_current_password"
84-
android:layout_width="match_parent"
85-
android:layout_height="wrap_content"
86-
android:visibility="gone"
87-
android:text="@string/message_incorrect_current_password"
88-
android:textColor="@color/errorBackground" />
8981

9082
<de.symeda.sormas.app.component.controls.ControlPasswordField
9183
android:id="@+id/change_password_new_password"
9284
style="@style/ControlSingleColumnStyle"
9385
android:layout_marginTop="10dp"
94-
9586
android:hint="@string/caption_enter_new_password"
9687
app:caption="@string/caption_enter_new_password"
9788
app:description="@string/caption_enter_new_password"
@@ -100,17 +91,6 @@
10091
app:required="true"
10192
app:value="@={data.newPassword}" />
10293

103-
<TextView
104-
android:id="@+id/incorrect_new_password"
105-
android:layout_width="match_parent"
106-
android:layout_height="wrap_content"
107-
android:text="@string/message_incorrect_new_password"
108-
android:visibility="gone"
109-
android:textColor="@color/errorBackground" />
110-
111-
<!-- android:onClick="registrationDataCheck"-->
112-
113-
11494
<de.symeda.sormas.app.component.controls.ControlPasswordField
11595
android:id="@+id/change_password_confirm_password"
11696
style="@style/ControlSingleColumnStyle"
@@ -123,15 +103,6 @@
123103
android:layout_marginTop="10dp"
124104
app:labelCaption="@string/caption_confirm_new_password"
125105
app:value="@={data.confirmPassword}" />
126-
<!---for error-->
127-
<TextView
128-
android:id="@+id/incorrect_confirm_password"
129-
android:layout_width="match_parent"
130-
android:layout_height="wrap_content"
131-
android:text="@string/message_not_match_password"
132-
android:visibility="gone"
133-
android:layout_marginBottom="15dp"
134-
android:textColor="@color/errorBackground" />
135106

136107
<Button
137108
android:id="@+id/btn_changePassword"
@@ -156,7 +127,6 @@
156127
android:layout_height="match_parent"
157128
android:text="@string/action_strength_password"
158129
android:textAlignment="viewStart" />
159-
<!-- android:onClick="registrationDataCheck"-->
160130

161131
</RelativeLayout>
162132

@@ -165,18 +135,6 @@
165135
android:layout_height="wrap_content"
166136
android:orientation="horizontal">
167137

168-
169-
<!-- <de.symeda.sormas.app.component.controls.ControlButton-->
170-
<!-- android:id="@+id/btn_changePassword"-->
171-
<!-- android:layout_width="match_parent"-->
172-
<!-- android:layout_height="wrap_content"-->
173-
<!-- android:layout_marginTop="@dimen/buttonControlMarginBottom"-->
174-
<!-- android:layout_marginBottom="@dimen/buttonControlMarginBottom"-->
175-
<!-- android:onClick="savePassword"-->
176-
<!-- android:text="@string/action_change_password"-->
177-
<!-- app:buttonType="@{ControlButtonType.SECONDARY}"-->
178-
<!-- app:rounded="true" />-->
179-
180138
<Button
181139
android:id="@+id/action_generatePassword"
182140
android:layout_alignParentEnd="true"

sormas-app/app/src/main/res/values/strings.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,9 +562,6 @@
562562
<string name="message_case_infrastructure_data_changed">You have changed the infrastructure data of this case. Do you want to transfer the case to the new health facility (the hospitalization data will be updated) or do you only want to edit the data to correct a mistake?</string>
563563
<string name="message_download_app_failed">The download of the new SORMAS version failed. Please make sure you have the best internet connection possible and try again or inform a supervisor if you keep getting this error despite a good internet connection.</string>
564564
<string name="message_empty_password">Please enter a password.</string>
565-
<string name="message_incorrect_current_password">Please your Current Password is incorrect.</string>
566-
<string name="message_incorrect_new_password">Please your New Password is incorrect.</string>
567-
<string name="message_not_match_password">Passwords does not match.</string>
568565
<string name="message_empty_username">Please enter a username.</string>
569566
<string name="message_encryption">SORMAS requires device encryption to be activated on your device to ensure data security.\n\nPlease note that you cannot use the application as long as device encryption is disabled.</string>
570567
<string name="message_enter_person_name">Please enter a first and last name for the new person.</string>
@@ -752,6 +749,11 @@
752749
<string name="hint_enter_confirm_new_password">"Enter Confirm Password"</string>
753750
<string name="caption_enter_current_password">"Enter Current Password"</string>
754751
<string name="caption_enter_new_password">"Enter new Password"</string>
755-
<string name="caption_confirm_new_password">"Confirm Password"</string>
752+
<string name="caption_confirm_new_password">"Enter Confirm Password"</string>
753+
<string name="error_current_password_empty">Current Password Cannot be Empty</string>
754+
<string name="error_new_password_empty">New Password Cannot be Empty</string>
755+
<string name="error_confirm_password_empty">Confirm Password Cannot be Empty</string>
756+
<string name="error_current_password_incorrect">Current Password is Incorrect</string>
757+
<string name="error_passwords_do_not_match">Passwords do not match</string>
756758

757759
</resources>

sormas-backend/src/main/java/de/symeda/sormas/backend/user/UserFacadeEjb.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,7 @@ public boolean validatePassword(String uuid, String password) {
940940
return false;
941941
}
942942

943+
@PermitAll
943944
public String checkPasswordStrength(String password) {
944945
return PasswordValidator.checkPasswordStrength(password);
945946
}

0 commit comments

Comments
 (0)