-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 893 - 4 new fields for user (#903)
* feat: 893 - 4 new fields for user Impacted files: * `login_status.dart`: added 4 fields and deprecated "email" * `open_food_api_client.dart`: upgraded the max length of user name (60) and user id (40) * `user_management_test_prod.dart`: tested the new 4 login status fields * `user_management_test_test_env.dart`: tested the new 4 login status fields and remove a test on "email" * feat: 893 - 'cc' json field instead of 'country' * Minor changes
- Loading branch information
1 parent
c370e19
commit a7e195b
Showing
4 changed files
with
63 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import '../interface/json_object.dart'; | ||
import '../utils/country_helper.dart'; | ||
import '../utils/json_helper.dart'; | ||
import '../utils/language_helper.dart'; | ||
|
||
/// Status after an attempt to log in. | ||
/// | ||
|
@@ -14,40 +17,60 @@ import '../interface/json_object.dart'; | |
/// "status_verbose":"user signed-in", | ||
/// "user_id":"gqwbgsvvod", | ||
/// "user":{ | ||
/// "email":"[email protected]", | ||
/// "name":"Mr. John Doe" | ||
/// "name":"Mr. John Doe", | ||
/// "preferred_language":"fr", | ||
/// "cc":"be", | ||
/// "country":"en:belgium", | ||
/// "admin":0, | ||
/// "moderator":1 | ||
/// } | ||
/// } | ||
class LoginStatus { | ||
LoginStatus({ | ||
required this.status, | ||
required this.statusVerbose, | ||
this.userEmail, | ||
String? userEmail, | ||
this.userName, | ||
this.userId, | ||
this.preferredLanguage, | ||
this.country, | ||
this.isModerator, | ||
this.isAdmin, | ||
this.cookie, | ||
}); | ||
|
||
final int status; | ||
final String statusVerbose; | ||
final String? userEmail; | ||
// TODO: deprecated from 2024-04-09; remove when old enough | ||
@Deprecated('Not retrieved anymore from the server') | ||
final String? userEmail = null; | ||
final String? userName; | ||
final String? userId; | ||
final OpenFoodFactsLanguage? preferredLanguage; | ||
final OpenFoodFactsCountry? country; | ||
final bool? isModerator; | ||
final bool? isAdmin; | ||
|
||
/// The cookie is necessary for some GET requests that require an | ||
/// authenticated user. | ||
final String? cookie; | ||
|
||
factory LoginStatus.fromJson(Map<String, dynamic> json, | ||
[Map<String, String>? headers]) => | ||
LoginStatus( | ||
status: JsonObject.parseInt(json['status'])!, | ||
statusVerbose: json['status_verbose'] as String, | ||
userId: json['user_id'] as String?, | ||
userEmail: json['user']?['email'] as String?, | ||
userName: json['user']?['name'] as String?, | ||
cookie: headers?['set-cookie'], | ||
); | ||
[Map<String, String>? headers]) { | ||
final details = json['user']; | ||
return LoginStatus( | ||
status: JsonObject.parseInt(json['status'])!, | ||
statusVerbose: json['status_verbose'] as String, | ||
userId: json['user_id'] as String?, | ||
userName: details?['name'] as String?, | ||
preferredLanguage: | ||
OpenFoodFactsLanguage.fromOffTag(details?['preferred_language']), | ||
country: OpenFoodFactsCountry.fromOffTag(details?['cc']), | ||
isModerator: JsonHelper.boolFromJSON(details?['moderator']), | ||
isAdmin: JsonHelper.boolFromJSON(details?['admin']), | ||
cookie: headers?['set-cookie'], | ||
); | ||
} | ||
|
||
/// Was the login successful? | ||
bool get successful => status == 1; | ||
|
@@ -57,8 +80,11 @@ class LoginStatus { | |
'status:$status' | ||
',statusVerbose:$statusVerbose' | ||
'${userId == null ? '' : ',userId:$userId'}' | ||
'${userEmail == null ? '' : ',userEmail:$userEmail'}' | ||
'${userName == null ? '' : ',userName:$userName'}' | ||
'${preferredLanguage == null ? '' : ',preferredLanguage:$preferredLanguage'}' | ||
'${country == null ? '' : ',country:$country'}' | ||
'${isAdmin == null ? '' : ',isAdmin:$isAdmin'}' | ||
'${isModerator == null ? '' : ',isModerator:$isModerator'}' | ||
'${cookie == null ? '' : ',cookie:$cookie'}' | ||
')'; | ||
} |
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