Skip to content

Commit

Permalink
Added mechanism of required password change of new user's first login (
Browse files Browse the repository at this point in the history
…#272)

* Deprecate login scenarios that support pre-web era

* refactor and simplify setup

* Added user info to change password form

* change isFistLogin column to shouldChangePassword

* Implemented change user password

* Implement the change password page for mobile

* Change label

* Added changes log and up minor version

* Fixed typo in the release note

* Up server version
  • Loading branch information
alextran1502 authored Jun 27, 2022
1 parent 2e85e18 commit 5f00d8b
Show file tree
Hide file tree
Showing 33 changed files with 742 additions and 566 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Fixed app does not resume back up when reopening a closed app
* Fixed wrong asset count on the upload page
* Added mechanism to change the password of new user on the first login (except Admin)
2 changes: 1 addition & 1 deletion mobile/ios/fastlane/Fastfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ platform :ios do
desc "iOS Beta"
lane :beta do
increment_version_number(
version_number: "1.13.0"
version_number: "1.14.0"
)
increment_build_number(
build_number: latest_testflight_build_number + 1,
Expand Down
2 changes: 1 addition & 1 deletion mobile/lib/modules/home/ui/profile_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class ProfileDrawer extends HookConsumerWidget {
),
onTap: () async {
bool res =
await ref.read(authenticationProvider.notifier).logout();
await ref.watch(authenticationProvider.notifier).logout();

if (res) {
ref.watch(backupProvider.notifier).cancelBackup();
Expand Down
26 changes: 13 additions & 13 deletions mobile/lib/modules/login/models/authentication_state.model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AuthenticationState {
final String firstName;
final String lastName;
final bool isAdmin;
final bool isFirstLogin;
final bool shouldChangePassword;
final String profileImagePath;
final DeviceInfoRemote deviceInfo;

Expand All @@ -24,7 +24,7 @@ class AuthenticationState {
required this.firstName,
required this.lastName,
required this.isAdmin,
required this.isFirstLogin,
required this.shouldChangePassword,
required this.profileImagePath,
required this.deviceInfo,
});
Expand All @@ -38,7 +38,7 @@ class AuthenticationState {
String? firstName,
String? lastName,
bool? isAdmin,
bool? isFirstLoggedIn,
bool? shouldChangePassword,
String? profileImagePath,
DeviceInfoRemote? deviceInfo,
}) {
Expand All @@ -51,17 +51,12 @@ class AuthenticationState {
firstName: firstName ?? this.firstName,
lastName: lastName ?? this.lastName,
isAdmin: isAdmin ?? this.isAdmin,
isFirstLogin: isFirstLoggedIn ?? isFirstLogin,
shouldChangePassword: shouldChangePassword ?? this.shouldChangePassword,
profileImagePath: profileImagePath ?? this.profileImagePath,
deviceInfo: deviceInfo ?? this.deviceInfo,
);
}

@override
String toString() {
return 'AuthenticationState(deviceId: $deviceId, deviceType: $deviceType, userId: $userId, userEmail: $userEmail, isAuthenticated: $isAuthenticated, firstName: $firstName, lastName: $lastName, isAdmin: $isAdmin, isFirstLoggedIn: $isFirstLogin, profileImagePath: $profileImagePath, deviceInfo: $deviceInfo)';
}

Map<String, dynamic> toMap() {
final result = <String, dynamic>{};

Expand All @@ -73,7 +68,7 @@ class AuthenticationState {
result.addAll({'firstName': firstName});
result.addAll({'lastName': lastName});
result.addAll({'isAdmin': isAdmin});
result.addAll({'isFirstLogin': isFirstLogin});
result.addAll({'shouldChangePassword': shouldChangePassword});
result.addAll({'profileImagePath': profileImagePath});
result.addAll({'deviceInfo': deviceInfo.toMap()});

Expand All @@ -90,7 +85,7 @@ class AuthenticationState {
firstName: map['firstName'] ?? '',
lastName: map['lastName'] ?? '',
isAdmin: map['isAdmin'] ?? false,
isFirstLogin: map['isFirstLogin'] ?? false,
shouldChangePassword: map['shouldChangePassword'] ?? false,
profileImagePath: map['profileImagePath'] ?? '',
deviceInfo: DeviceInfoRemote.fromMap(map['deviceInfo']),
);
Expand All @@ -101,6 +96,11 @@ class AuthenticationState {
factory AuthenticationState.fromJson(String source) =>
AuthenticationState.fromMap(json.decode(source));

@override
String toString() {
return 'AuthenticationState(deviceId: $deviceId, deviceType: $deviceType, userId: $userId, userEmail: $userEmail, isAuthenticated: $isAuthenticated, firstName: $firstName, lastName: $lastName, isAdmin: $isAdmin, shouldChangePassword: $shouldChangePassword, profileImagePath: $profileImagePath, deviceInfo: $deviceInfo)';
}

@override
bool operator ==(Object other) {
if (identical(this, other)) return true;
Expand All @@ -114,7 +114,7 @@ class AuthenticationState {
other.firstName == firstName &&
other.lastName == lastName &&
other.isAdmin == isAdmin &&
other.isFirstLogin == isFirstLogin &&
other.shouldChangePassword == shouldChangePassword &&
other.profileImagePath == profileImagePath &&
other.deviceInfo == deviceInfo;
}
Expand All @@ -129,7 +129,7 @@ class AuthenticationState {
firstName.hashCode ^
lastName.hashCode ^
isAdmin.hashCode ^
isFirstLogin.hashCode ^
shouldChangePassword.hashCode ^
profileImagePath.hashCode ^
deviceInfo.hashCode;
}
Expand Down
18 changes: 9 additions & 9 deletions mobile/lib/modules/login/models/login_response.model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class LogInReponse {
final String lastName;
final String profileImagePath;
final bool isAdmin;
final bool isFirstLogin;
final bool shouldChangePassword;

LogInReponse({
required this.accessToken,
Expand All @@ -18,7 +18,7 @@ class LogInReponse {
required this.lastName,
required this.profileImagePath,
required this.isAdmin,
required this.isFirstLogin,
required this.shouldChangePassword,
});

LogInReponse copyWith({
Expand All @@ -29,7 +29,7 @@ class LogInReponse {
String? lastName,
String? profileImagePath,
bool? isAdmin,
bool? isFirstLogin,
bool? shouldChangePassword,
}) {
return LogInReponse(
accessToken: accessToken ?? this.accessToken,
Expand All @@ -39,7 +39,7 @@ class LogInReponse {
lastName: lastName ?? this.lastName,
profileImagePath: profileImagePath ?? this.profileImagePath,
isAdmin: isAdmin ?? this.isAdmin,
isFirstLogin: isFirstLogin ?? this.isFirstLogin,
shouldChangePassword: shouldChangePassword ?? this.shouldChangePassword,
);
}

Expand All @@ -53,7 +53,7 @@ class LogInReponse {
result.addAll({'lastName': lastName});
result.addAll({'profileImagePath': profileImagePath});
result.addAll({'isAdmin': isAdmin});
result.addAll({'isFirstLogin': isFirstLogin});
result.addAll({'shouldChangePassword': shouldChangePassword});

return result;
}
Expand All @@ -67,7 +67,7 @@ class LogInReponse {
lastName: map['lastName'] ?? '',
profileImagePath: map['profileImagePath'] ?? '',
isAdmin: map['isAdmin'] ?? false,
isFirstLogin: map['isFirstLogin'] ?? false,
shouldChangePassword: map['shouldChangePassword'] ?? false,
);
}

Expand All @@ -78,7 +78,7 @@ class LogInReponse {

@override
String toString() {
return 'LogInReponse(accessToken: $accessToken, userId: $userId, userEmail: $userEmail, firstName: $firstName, lastName: $lastName, profileImagePath: $profileImagePath, isAdmin: $isAdmin, isFirstLogin: $isFirstLogin)';
return 'LogInReponse(accessToken: $accessToken, userId: $userId, userEmail: $userEmail, firstName: $firstName, lastName: $lastName, profileImagePath: $profileImagePath, isAdmin: $isAdmin, shouldChangePassword: $shouldChangePassword)';
}

@override
Expand All @@ -93,7 +93,7 @@ class LogInReponse {
other.lastName == lastName &&
other.profileImagePath == profileImagePath &&
other.isAdmin == isAdmin &&
other.isFirstLogin == isFirstLogin;
other.shouldChangePassword == shouldChangePassword;
}

@override
Expand All @@ -105,6 +105,6 @@ class LogInReponse {
lastName.hashCode ^
profileImagePath.hashCode ^
isAdmin.hashCode ^
isFirstLogin.hashCode;
shouldChangePassword.hashCode;
}
}
32 changes: 27 additions & 5 deletions mobile/lib/modules/login/providers/authentication.provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
lastName: '',
profileImagePath: '',
isAdmin: false,
isFirstLogin: false,
shouldChangePassword: false,
isAuthenticated: false,
deviceInfo: DeviceInfoRemote(
id: 0,
Expand Down Expand Up @@ -87,7 +87,7 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
lastName: payload.lastName,
profileImagePath: payload.profileImagePath,
isAdmin: payload.isAdmin,
isFirstLoggedIn: payload.isFirstLogin,
shouldChangePassword: payload.shouldChangePassword,
);

if (isSavedLoginInfo) {
Expand All @@ -111,8 +111,12 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
// Register device info
try {
Response res = await _networkService.postRequest(
url: 'device-info',
data: {'deviceId': state.deviceId, 'deviceType': state.deviceType});
url: 'device-info',
data: {
'deviceId': state.deviceId,
'deviceType': state.deviceType,
},
);

DeviceInfoRemote deviceInfo = DeviceInfoRemote.fromJson(res.toString());
state = state.copyWith(deviceInfo: deviceInfo);
Expand All @@ -133,7 +137,7 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
firstName: '',
lastName: '',
profileImagePath: '',
isFirstLogin: false,
shouldChangePassword: false,
isAuthenticated: false,
isAdmin: false,
deviceInfo: DeviceInfoRemote(
Expand Down Expand Up @@ -163,6 +167,24 @@ class AuthenticationNotifier extends StateNotifier<AuthenticationState> {
updateUserProfileImagePath(String path) {
state = state.copyWith(profileImagePath: path);
}

Future<bool> changePassword(String newPassword) async {
Response res = await _networkService.putRequest(
url: 'user',
data: {
'id': state.userId,
'password': newPassword,
'shouldChangePassword': false,
},
);

if (res.statusCode == 200) {
state = state.copyWith(shouldChangePassword: false);
return true;
} else {
return false;
}
}
}

final authenticationProvider =
Expand Down
Loading

0 comments on commit 5f00d8b

Please sign in to comment.