Skip to content

Commit

Permalink
Merge pull request #37 from NODO-UH/develop
Browse files Browse the repository at this point in the history
Release v1.2.0
  • Loading branch information
leynier authored Apr 27, 2021
2 parents 70571ba + bd9c605 commit 302f41b
Show file tree
Hide file tree
Showing 13 changed files with 476 additions and 158 deletions.
7 changes: 4 additions & 3 deletions lib/src/data/api/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,17 @@ class GestionApi {
);
}

Future<SecurityQuestions> getUserSecurityQuestions(String ci) async {
Future<SecurityQuestions> getUserSecurityQuestions(
String ci, String email) async {
if (Constants.testMode) {
return SecurityQuestions(
questions: SampleData.userSecurityQuestions,
);
}

final UserCi user = UserCi(ci: ci);
final UserCi user = UserCi(ci: ci, email: email);

final params = {'ci': user.ci};
final params = user.toJson();

return apiRequest<SecurityQuestions, UserCi>(
Constants.userSecurityQuestionsUrl,
Expand Down
12 changes: 9 additions & 3 deletions lib/src/data/models/password_reset_data.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'package:json_annotation/json_annotation.dart';

import 'package:gestionuh/src/data/models/base_model.dart';
import 'package:json_annotation/json_annotation.dart';

part 'password_reset_data.g.dart';

Expand All @@ -10,8 +9,15 @@ class PasswordResetData extends BaseModel {
String? ci;
String? newPassword;
List<String>? questions;
String? email;

PasswordResetData({this.answers, this.ci, this.newPassword, this.questions});
PasswordResetData({
this.answers,
this.ci,
this.newPassword,
this.questions,
this.email,
});

static PasswordResetData fromJson(Map<String, dynamic> json) =>
_$PasswordResetDataFromJson(json);
Expand Down
2 changes: 2 additions & 0 deletions lib/src/data/models/password_reset_data.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions lib/src/data/models/user_ci.dart
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import 'package:json_annotation/json_annotation.dart';

import 'package:gestionuh/src/data/models/base_model.dart';
import 'package:json_annotation/json_annotation.dart';

part 'user_ci.g.dart';

@JsonSerializable(explicitToJson: true)
class UserCi extends BaseModel {
String? ci;
String? email;

UserCi({this.ci});
UserCi({this.ci, this.email});

static UserCi fromJson(Map<String, dynamic> json) => _$UserCiFromJson(json);

Expand Down
2 changes: 2 additions & 0 deletions lib/src/data/models/user_ci.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions lib/src/data/repositories/recover_password_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ class RecoverPasswordRepository {

RecoverPasswordRepository({required this.api});

Future<SecurityQuestions?> getUserSecurityQuestions(String ci) async {
Future<SecurityQuestions?> getUserSecurityQuestions(
String ci, String email) async {
try {
final result = await api.getUserSecurityQuestions(ci);
final result = await api.getUserSecurityQuestions(ci, email);
if (result.error != null) {
log(result.error!);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class RecoverPasswordBloc
final RecoverPasswordRepository recoverPasswordRepository;

RecoverPasswordBloc({required this.recoverPasswordRepository})
: super(RecoverPasswordState.initial(TextEditingController()));
: super(RecoverPasswordState.initial(
TextEditingController(),
TextEditingController(),
));

@override
Stream<RecoverPasswordState> mapEventToState(
Expand All @@ -28,20 +31,25 @@ class RecoverPasswordBloc
);
}

Stream<RecoverPasswordState> handleCISubmit(TextEditingController ci) async* {
yield RecoverPasswordState.ciLoading(ci);
Stream<RecoverPasswordState> handleCISubmit(
TextEditingController ci,
TextEditingController email,
) async* {
yield RecoverPasswordState.ciLoading(ci, email);
final result = await recoverPasswordRepository.getUserSecurityQuestions(
ci.text.trim(),
email.text.trim(),
);
if (result == null) {
yield RecoverPasswordState.ciError(ci, Errors.DefaultError);
yield RecoverPasswordState.ciError(ci, email, Errors.DefaultError);
} else if (result.error != null) {
yield RecoverPasswordState.ciError(ci, result.error!);
yield RecoverPasswordState.ciError(ci, email, result.error!);
} else if (result.questions == null) {
yield RecoverPasswordState.ciError(ci, Errors.DefaultError);
yield RecoverPasswordState.ciError(ci, email, Errors.DefaultError);
} else {
yield RecoverPasswordState.questions(
ci.text.trim(),
email.text.trim(),
result.questions!,
result.questions!.map((_) => TextEditingController()).toList(),
TextEditingController(),
Expand All @@ -51,12 +59,14 @@ class RecoverPasswordBloc

Stream<RecoverPasswordState> handleFinalSubmit(
String ci,
String email,
List<String> questions,
List<TextEditingController> answers,
TextEditingController password,
) async* {
yield RecoverPasswordState.questionsLoading(
ci,
email,
questions,
answers,
password,
Expand All @@ -67,11 +77,13 @@ class RecoverPasswordBloc
questions: questions,
answers: answers.map((e) => e.text.trim()).toList(),
newPassword: password.text.trim(),
email: email,
),
);
if (result == null) {
yield RecoverPasswordState.questionsError(
ci,
email,
questions,
answers,
password,
Expand All @@ -80,6 +92,7 @@ class RecoverPasswordBloc
} else if (result.error != null) {
yield RecoverPasswordState.questionsError(
ci,
email,
questions,
answers,
password,
Expand All @@ -88,6 +101,7 @@ class RecoverPasswordBloc
} else if (result.userId == null) {
yield RecoverPasswordState.questionsError(
ci,
email,
questions,
answers,
password,
Expand Down
Loading

0 comments on commit 302f41b

Please sign in to comment.