Skip to content

Commit

Permalink
chore: clean up and format code
Browse files Browse the repository at this point in the history
  • Loading branch information
sashatalalasha committed Oct 2, 2023
1 parent e631a1f commit 6917e92
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 68 deletions.
3 changes: 3 additions & 0 deletions flutter-ory-network/lib/blocs/auth/auth_bloc.freezed.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
Expand Down
2 changes: 0 additions & 2 deletions flutter-ory-network/lib/blocs/auth/auth_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ final class ChangeAuthStatus extends AuthEvent {
List<Object> get props => [status];
}

//get current session information
final class GetCurrentSessionInformation extends AuthEvent {}

//log out
final class LogOut extends AuthEvent {}
2 changes: 2 additions & 0 deletions flutter-ory-network/lib/blocs/login/login_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class LoginBloc extends Bloc<LoginEvent, LoginState> {
} on CustomException catch (e) {
if (e case BadRequestException<LoginFlow> _) {
emit(state.copyWith(loginFlow: e.flow, isLoading: false));
} else if (e case UnauthorizedException _) {
authBloc.add(ChangeAuthStatus(status: AuthStatus.unauthenticated));
} else if (e case FlowExpiredException _) {
add(GetLoginFlow(flowId: e.flowId));
} else if (e case TwoFactorAuthRequiredException _) {
Expand Down
3 changes: 3 additions & 0 deletions flutter-ory-network/lib/blocs/login/login_bloc.freezed.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
Expand Down
18 changes: 8 additions & 10 deletions flutter-ory-network/lib/pages/login.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:ory_client/ory_client.dart';
Expand Down Expand Up @@ -123,20 +126,18 @@ class LoginForm extends StatelessWidget {
message.text,
style: TextStyle(color: getMessageColor(message.type)),
),
// build progress indicator when state is loading
// show logout button if aal2 requested, otherwise sign up
BlocSelector<AuthBloc, AuthState, bool>(
bloc: (context).read<AuthBloc>(),
selector: (AuthState state) =>
state.status == AuthStatus.aal2Requested,
builder: (BuildContext context, bool booleanState) {
print(booleanState);
if (booleanState) {
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
const Text('Something\'s not working?'),
TextButton(
// disable button when state is loading
onPressed: () =>
(context).read<AuthBloc>().add(LogOut()),
child: const Text('Logout'))
Expand All @@ -148,13 +149,10 @@ class LoginForm extends StatelessWidget {
children: [
const Text('No account?'),
TextButton(
// disable button when state is loading
onPressed: state.isLoading
? null
: () => Navigator.of(context).pushReplacement(
MaterialPageRoute(
builder: (context) =>
const RegistrationPage())),
onPressed: () => Navigator.of(context)
.pushReplacement(MaterialPageRoute(
builder: (context) =>
const RegistrationPage())),
child: const Text('Sign up'))
],
);
Expand Down
13 changes: 5 additions & 8 deletions flutter-ory-network/lib/pages/registration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,11 @@ class RegistrationFormState extends State<RegistrationForm> {
children: [
const Text('Already have an account?'),
TextButton(
// disable button when state is loading
onPressed: state.isLoading
? null
: () => Navigator.of(context)
.pushReplacement(MaterialPageRoute(
builder: (context) => const LoginPage(
aal: 'aal1',
))),
onPressed: () => Navigator.of(context)
.pushReplacement(MaterialPageRoute(
builder: (context) => const LoginPage(
aal: 'aal1',
))),
child: const Text('Sign in'))
],
)
Expand Down
24 changes: 0 additions & 24 deletions flutter-ory-network/lib/repositories/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class AuthRepository {
final body = _createRequestBody(
group: group, name: name, value: value, nodes: nodes);
// submit login
print(body);
final login = await service.updateLoginFlow(
flowId: flowId, group: group, value: body);
return login;
Expand Down Expand Up @@ -119,29 +118,6 @@ class AuthRepository {
}
}

LoginFlow resetButtonValues({required LoginFlow loginFlow}) {
final submitInputNodes = loginFlow.ui.nodes.where((p0) {
if (p0.attributes.oneOf.isType(UiNodeInputAttributes)) {
final attributes = p0.attributes.oneOf.value as UiNodeInputAttributes;
final type = attributes.type;
if ((type == UiNodeInputAttributesTypeEnum.button ||
type == UiNodeInputAttributesTypeEnum.submit) &&
attributes.value?.asString == 'true') {
return true;
}
}
return false;
});
for (var node in submitInputNodes) {
final attributes = node.attributes.oneOf.value as UiNodeInputAttributes;
// reset button value to false
// to prevent submitting values that were not selected
loginFlow = changeLoginNodeValue(
settings: loginFlow, name: attributes.name, value: 'false');
}
return loginFlow;
}

RegistrationFlow changeRegistrationNodeValue(
{required RegistrationFlow settings,
required String name,
Expand Down
28 changes: 8 additions & 20 deletions flutter-ory-network/lib/services/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ class AuthService {
case UiNodeGroupEnum.lookupSecret:
oneOf = OneOf.fromValue1(
value: UpdateLoginFlowWithLookupSecretMethod((b) => b
..method = group.name
// use pre-defined string as enum value doesn't include an underscore
..method = 'lookup_secret'
..lookupSecret = value['lookup_secret']));
case UiNodeGroupEnum.totp:
oneOf = OneOf.fromValue1(
Expand All @@ -118,8 +119,8 @@ class AuthService {
if (response.data!.session.identity != null) {
return response.data!;
} else {
throw CustomException.twoFactorAuthRequired(
session: response.data!.session);
// identity is null, aal2 is required
throw const CustomException.twoFactorAuthRequired();
}
} else {
throw const CustomException.unknown();
Expand All @@ -137,7 +138,7 @@ class AuthService {
throw const CustomException.unknown();
}
} else if (e.response?.statusCode == 410) {
// settings flow expired, use new flow id and add error message
// settings flow expired, use new flow id
throw CustomException.flowExpired(
flowId: e.response?.data['use_flow_id']);
} else {
Expand All @@ -158,12 +159,7 @@ class AuthService {
throw const CustomException.unknown();
}
} on DioException catch (e) {
if (e.response?.statusCode == 401) {
await storage.deleteToken();
throw const CustomException.unauthorized();
} else {
throw _handleUnknownException(e.response?.data);
}
throw _handleUnknownException(e.response?.data);
}
}

Expand All @@ -179,12 +175,7 @@ class AuthService {
throw const CustomException.unknown();
}
} on DioException catch (e) {
if (e.response?.statusCode == 401) {
await storage.deleteToken();
throw const CustomException.unauthorized();
} else {
throw _handleUnknownException(e.response?.data);
}
throw _handleUnknownException(e.response?.data);
}
}

Expand Down Expand Up @@ -223,10 +214,7 @@ class AuthService {
throw const CustomException.unknown();
}
} on DioException catch (e) {
if (e.response?.statusCode == 401) {
await storage.deleteToken();
throw const CustomException.unauthorized();
} else if (e.response?.statusCode == 400) {
if (e.response?.statusCode == 400) {
final registrationFlow = standardSerializers.deserializeWith(
RegistrationFlow.serializer, e.response?.data);
if (registrationFlow != null) {
Expand Down
3 changes: 3 additions & 0 deletions flutter-ory-network/lib/services/exceptions.freezed.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
Expand Down
3 changes: 3 additions & 0 deletions flutter-ory-network/lib/widgets/helpers.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

import 'package:bloc/bloc.dart';
import 'package:flutter/material.dart';
import 'package:ory_client/ory_client.dart';
Expand Down
6 changes: 4 additions & 2 deletions flutter-ory-network/lib/widgets/nodes/input.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

import 'package:collection/collection.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
Expand All @@ -23,7 +26,6 @@ class _InputNodeState<T extends Bloc> extends State<InputNode> {
@override
void initState() {
super.initState();
// assign node value to text controller on init
final attributes =
widget.node.attributes.oneOf.value as UiNodeInputAttributes;
// if this is a password field, hide the text
Expand All @@ -33,6 +35,7 @@ class _InputNodeState<T extends Bloc> extends State<InputNode> {
});
}
final fieldValue = attributes.value;
// assign node value to text controller on init
textEditingController.text = fieldValue != null ? fieldValue.asString : '';
}

Expand Down Expand Up @@ -62,7 +65,6 @@ class _InputNodeState<T extends Bloc> extends State<InputNode> {

@override
Widget build(BuildContext context) {
print(widget.node.attributes.oneOf.value);
final attributes =
widget.node.attributes.oneOf.value as UiNodeInputAttributes;

Expand Down
5 changes: 4 additions & 1 deletion flutter-ory-network/lib/widgets/nodes/input_submit.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

import 'package:flutter/material.dart';
import 'package:ory_client/ory_client.dart';

Expand Down Expand Up @@ -27,7 +30,7 @@ class InputSubmitNode extends StatelessWidget {
final attributes =
node.attributes.oneOf.value as UiNodeInputAttributes;
final type = attributes.type;
// if attribute type is a button, set its value to true on submit
// if attribute type is a button with value 'false', set its value to true on submit
if (type == UiNodeInputAttributesTypeEnum.button ||
type == UiNodeInputAttributesTypeEnum.submit &&
attributes.value?.value == 'false') {
Expand Down
4 changes: 3 additions & 1 deletion flutter-ory-network/lib/widgets/nodes/provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ class SocialProviderInput extends StatelessWidget {
icon: Image.asset(
'assets/images/flows-auth-buttons-social-$provider.png'),
label: Text(node.meta.label?.text ?? ''),
onPressed: () {},
onPressed: () {
//TODO
},
),
);
}
Expand Down
3 changes: 3 additions & 0 deletions flutter-ory-network/lib/widgets/nodes/text.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright © 2023 Ory Corp
// SPDX-License-Identifier: Apache-2.0

import 'package:flutter/material.dart';
import 'package:ory_client/ory_client.dart';

Expand Down

0 comments on commit 6917e92

Please sign in to comment.