-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc21b4f
commit 8781940
Showing
17 changed files
with
562 additions
and
103 deletions.
There are no files selected for viewing
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// ignore_for_file: prefer_const_constructors | ||
|
||
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | ||
import 'dart:developer' as developer; | ||
|
||
class SecureStorage { | ||
final FlutterSecureStorage storage = FlutterSecureStorage(); | ||
|
||
writeSecureData(String key, value) async{ | ||
await storage.write(key: key, value: value); | ||
} | ||
|
||
readSecureData(String key) async{ | ||
String value = await storage.read(key: key) ?? 'No data found!'; | ||
developer.log('Data read from secure storage: $value'); | ||
|
||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// ignore_for_file: prefer_const_constructors | ||
|
||
import 'package:auth_screen_ui_challenge/core/configs/theme/app_colors.dart'; | ||
import 'package:flutter/material.dart'; | ||
|
||
class Home extends StatelessWidget { | ||
const Home({super.key}); | ||
|
||
@override | ||
Widget build(BuildContext context) { | ||
return Scaffold( | ||
appBar: AppBar( | ||
title: Text( | ||
'Home', | ||
style: TextStyle( | ||
color: Colors.white | ||
), | ||
), | ||
centerTitle: true, | ||
backgroundColor: AppColors.primary, | ||
), | ||
body: Center( | ||
child: Text( | ||
'you\'ve logged in successfuly:)', | ||
style: TextStyle( | ||
fontSize: 30, | ||
fontFamily: 'Poppins', | ||
fontWeight: FontWeight.w600, | ||
color: Colors.black87 | ||
), | ||
textAlign: TextAlign.center, | ||
), | ||
), | ||
); | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
lib/presentation/registration&login/login/API/login_api.dart
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// ignore_for_file: use_build_context_synchronously, prefer_const_constructors, prefer_const_literals_to_create_immutables | ||
|
||
import 'dart:developer' as developer; | ||
import 'package:auth_screen_ui_challenge/core/configs/theme/app_colors.dart'; | ||
import 'package:auth_screen_ui_challenge/data/local%20storage/secure_storage.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:http/http.dart'; | ||
|
||
class LoginApi { | ||
final SecureStorage secureStorage = SecureStorage(); | ||
|
||
static Future<Object?> login(String email, password, BuildContext context) async{ | ||
|
||
try{ | ||
Response response = await post( | ||
Uri.parse('https://reqres.in/api/login'), | ||
body: { | ||
'email': email, | ||
'password': password | ||
} | ||
); | ||
|
||
if(response.statusCode == 200){ | ||
final String token = response.body; | ||
SecureStorage().writeSecureData('auth_token', token); | ||
SecureStorage().readSecureData('auth_token'); | ||
|
||
|
||
return Navigator.of(context).pushNamedAndRemoveUntil( | ||
'/home', | ||
(route) => false | ||
); | ||
}else{ | ||
return showDialog( | ||
context: context, | ||
builder: (context) => CupertinoAlertDialog( | ||
title: Text('Login Failed'), | ||
content: Text('The email or password is incorrect'), | ||
actions: [ | ||
CupertinoDialogAction( | ||
onPressed: () => Navigator.of(context).pushNamedAndRemoveUntil( | ||
'/register', | ||
(route) => false | ||
), | ||
textStyle: TextStyle( | ||
color: Colors.red | ||
), | ||
child: Text('Register'), | ||
), | ||
CupertinoDialogAction( | ||
textStyle: TextStyle( | ||
color: AppColors.primary | ||
), | ||
child: Text('Try again'), | ||
onPressed: () => Navigator.of(context).pop(), | ||
), | ||
], | ||
) | ||
); | ||
} | ||
|
||
}catch(e){ | ||
developer.log(e.toString()); | ||
} | ||
return null; | ||
} | ||
|
||
} |
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
66 changes: 66 additions & 0 deletions
66
lib/presentation/registration&login/sign up/API/sign_up_api.dart
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// ignore_for_file: empty_catches, unused_local_variable | ||
// ignore_for_file: use_build_context_synchronously, prefer_const_constructors, prefer_const_literals_to_create_immutables | ||
|
||
import 'package:auth_screen_ui_challenge/core/configs/theme/app_colors.dart'; | ||
import 'package:flutter/cupertino.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:http/http.dart'; | ||
import 'dart:developer' as developer; | ||
|
||
class SignUpApi { | ||
|
||
static Future<Object?> signUp(String email, password, BuildContext context) async{ | ||
|
||
try{ | ||
Response response = await post( | ||
Uri.parse('https://reqres.in/api/register'), | ||
body: { | ||
'email': email, | ||
'password': password | ||
} | ||
); | ||
|
||
if(response.statusCode == 200){ | ||
return showDialog( | ||
context: context, | ||
builder: (context) => CupertinoAlertDialog( | ||
title: Text('Registration is done'), | ||
content: Text('go to login page and login to your account'), | ||
actions: [ | ||
CupertinoDialogAction( | ||
onPressed: () => Navigator.of(context).pushNamedAndRemoveUntil( | ||
'/login', | ||
(route) => false | ||
), | ||
textStyle: TextStyle( | ||
color: AppColors.primary | ||
), | ||
child: Text('Login'), | ||
), | ||
], | ||
) | ||
); | ||
}else{ | ||
return showDialog( | ||
context: context, | ||
builder: (context) => CupertinoAlertDialog( | ||
title: Text('account doesn\'t exist'), | ||
content: Text('the email or the password are uncorrect'), | ||
actions: [ | ||
CupertinoDialogAction( | ||
textStyle: TextStyle( | ||
color: AppColors.primary | ||
), | ||
child: Text('Try again'), | ||
onPressed: () => Navigator.of(context).pop(), | ||
), | ||
], | ||
) | ||
); | ||
} | ||
}catch(e){ | ||
developer.log(e.toString()); | ||
} | ||
return null; | ||
} | ||
} |
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
Oops, something went wrong.