forked from alexvasl/drifter_app
Authorization for entering a private key has been set up.
This commit is contained in:
parent
d25e5074f6
commit
a5fc25ddec
@ -1,5 +1,6 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:drifter/pages/login_screen/login_screen.dart';
|
||||||
import 'package:drifter/pages/main_screen/main_screen_widget.dart';
|
import 'package:drifter/pages/main_screen/main_screen_widget.dart';
|
||||||
import 'package:drifter/pages/splash_screen/splash_screen.dart';
|
import 'package:drifter/pages/splash_screen/splash_screen.dart';
|
||||||
import 'package:drifter/theme/app_colors.dart';
|
import 'package:drifter/theme/app_colors.dart';
|
||||||
@ -25,7 +26,10 @@ class MyApp extends StatelessWidget {
|
|||||||
unselectedItemColor: Colors.grey,
|
unselectedItemColor: Colors.grey,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
home: const Splash(),
|
routes: {
|
||||||
|
'/': (context) => const Splash(),
|
||||||
|
'/login': (context) => const LoginScreen(),
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,10 @@ import 'package:drifter/pages/profile_screen/widgets/message_snack_bar.dart';
|
|||||||
import 'package:drifter/pages/profile_screen/widgets/ok_button_widget.dart';
|
import 'package:drifter/pages/profile_screen/widgets/ok_button_widget.dart';
|
||||||
|
|
||||||
import 'package:drifter/theme/app_colors.dart';
|
import 'package:drifter/theme/app_colors.dart';
|
||||||
|
import 'package:drifter/utilities/assets.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||||
|
import 'package:flutter_svg/svg.dart';
|
||||||
import 'package:nostr_tools/nostr_tools.dart';
|
import 'package:nostr_tools/nostr_tools.dart';
|
||||||
|
|
||||||
class LoginScreen extends StatefulWidget {
|
class LoginScreen extends StatefulWidget {
|
||||||
@ -25,9 +27,34 @@ class LoginScreenState extends State<LoginScreen> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListView(
|
return Scaffold(
|
||||||
|
appBar: AppBar(
|
||||||
|
title: Row(
|
||||||
|
// mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
SizedBox(
|
SvgPicture.asset(
|
||||||
|
Assets.svg.drifterIcon,
|
||||||
|
height: 30,
|
||||||
|
width: 30,
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
),
|
||||||
|
const SizedBox(
|
||||||
|
width: 125,
|
||||||
|
),
|
||||||
|
const Text(
|
||||||
|
"Login",
|
||||||
|
style: TextStyle(
|
||||||
|
color: AppColors.mainAccent,
|
||||||
|
),
|
||||||
|
// textAlign: TextAlign.center,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
centerTitle: true,
|
||||||
|
),
|
||||||
|
body: ListView(
|
||||||
|
children: [
|
||||||
|
const SizedBox(
|
||||||
height: 200,
|
height: 200,
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
@ -54,8 +81,8 @@ class LoginScreenState extends State<LoginScreen> {
|
|||||||
return 'Please enter your private key';
|
return 'Please enter your private key';
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
bool isValidHexKey =
|
bool isValidHexKey = Nostr.instance.keysService
|
||||||
Nostr.instance.keysService.isValidPrivateKey(value);
|
.isValidPrivateKey(value);
|
||||||
bool isValidNSec = value.trim().startsWith('nsec') &&
|
bool isValidNSec = value.trim().startsWith('nsec') &&
|
||||||
Nostr.instance.keysService.isValidPrivateKey(Nostr
|
Nostr.instance.keysService.isValidPrivateKey(Nostr
|
||||||
.instance.keysService
|
.instance.keysService
|
||||||
@ -119,25 +146,17 @@ class LoginScreenState extends State<LoginScreen> {
|
|||||||
nsecKey = nip19.nsecEncode(privateKeyHex);
|
nsecKey = nip19.nsecEncode(privateKeyHex);
|
||||||
npubKey = nip19.npubEncode(publicKeyHex);
|
npubKey = nip19.npubEncode(publicKeyHex);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
ProfileScreenState().addKeyToStorage(
|
||||||
|
privateKeyHex, publicKeyHex, nsecKey, npubKey);
|
||||||
|
|
||||||
ProfileScreenState()
|
|
||||||
.addKeyToStorage(
|
|
||||||
privateKeyHex, publicKeyHex, nsecKey, npubKey)
|
|
||||||
.then((keysAdded) {
|
|
||||||
if (keysAdded) {
|
|
||||||
keyController.clear();
|
keyController.clear();
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
MessageSnackBar(label: 'Congratulations! Keys Stored!'),
|
MessageSnackBar(label: 'Congratulations! Keys Stored!'),
|
||||||
);
|
);
|
||||||
// setState() {
|
|
||||||
// Keys.privateKey = privateKeyHex;
|
Navigator.of(context).pop(true);
|
||||||
// Keys.publicKey = publicKeyHex;
|
} catch (e) {}
|
||||||
// Keys.nsecKey = nsecKey;
|
|
||||||
// Keys.npubKey = npubKey;
|
|
||||||
// Keys.keysExist = true;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
formKey.currentState?.setState(() {});
|
formKey.currentState?.setState(() {});
|
||||||
}
|
}
|
||||||
@ -145,6 +164,6 @@ class LoginScreenState extends State<LoginScreen> {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ import 'package:drifter/pages/login_screen/login_screen.dart';
|
|||||||
import 'package:drifter/pages/message_screen/message_screen_widget.dart';
|
import 'package:drifter/pages/message_screen/message_screen_widget.dart';
|
||||||
import 'package:drifter/pages/profile_screen/profile_screen.dart';
|
import 'package:drifter/pages/profile_screen/profile_screen.dart';
|
||||||
import 'package:drifter/theme/app_colors.dart';
|
import 'package:drifter/theme/app_colors.dart';
|
||||||
|
import 'package:drifter/main.dart';
|
||||||
import 'package:drifter/utilities/assets.dart';
|
import 'package:drifter/utilities/assets.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_svg/svg.dart';
|
import 'package:flutter_svg/svg.dart';
|
||||||
@ -59,7 +60,7 @@ class _MainScreenWidgetState extends State<MainScreenWidget> {
|
|||||||
HomeScreen(),
|
HomeScreen(),
|
||||||
MessageScreen(),
|
MessageScreen(),
|
||||||
ProfileScreen(),
|
ProfileScreen(),
|
||||||
LoginScreen(),
|
// LoginScreen(),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
bottomNavigationBar: BottomNavigationBar(
|
bottomNavigationBar: BottomNavigationBar(
|
||||||
@ -77,10 +78,10 @@ class _MainScreenWidgetState extends State<MainScreenWidget> {
|
|||||||
icon: Icon(Icons.person),
|
icon: Icon(Icons.person),
|
||||||
label: 'Profile',
|
label: 'Profile',
|
||||||
),
|
),
|
||||||
BottomNavigationBarItem(
|
// BottomNavigationBarItem(
|
||||||
icon: Icon(Icons.login),
|
// icon: Icon(Icons.login),
|
||||||
label: 'Login',
|
// label: 'Login',
|
||||||
),
|
// ),
|
||||||
],
|
],
|
||||||
onTap: onSelectedtap,
|
onTap: onSelectedtap,
|
||||||
),
|
),
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:dart_nostr/dart_nostr.dart';
|
import 'package:dart_nostr/dart_nostr.dart';
|
||||||
import 'package:drifter/models/keys.dart';
|
import 'package:drifter/models/keys.dart';
|
||||||
import 'package:drifter/pages/profile_screen/widgets/delete_keys_dialog.dart';
|
import 'package:drifter/pages/profile_screen/widgets/delete_keys_dialog.dart';
|
||||||
|
import 'package:drifter/main.dart';
|
||||||
import 'package:drifter/pages/profile_screen/widgets/key_exist_dialog.dart';
|
import 'package:drifter/pages/profile_screen/widgets/key_exist_dialog.dart';
|
||||||
import 'package:drifter/pages/profile_screen/widgets/keys_option_modal_bottom_sheet.dart';
|
import 'package:drifter/pages/profile_screen/widgets/keys_option_modal_bottom_sheet.dart';
|
||||||
import 'package:drifter/pages/profile_screen/widgets/message_snack_bar.dart';
|
import 'package:drifter/pages/profile_screen/widgets/message_snack_bar.dart';
|
||||||
@ -174,10 +175,12 @@ class ProfileScreenState extends State<ProfileScreen> {
|
|||||||
// 'Keys',
|
// 'Keys',
|
||||||
// ),
|
// ),
|
||||||
// )
|
// )
|
||||||
: ElevatedButton(
|
: Row(
|
||||||
|
children: [
|
||||||
|
ElevatedButton(
|
||||||
style: ButtonStyle(
|
style: ButtonStyle(
|
||||||
backgroundColor:
|
backgroundColor: MaterialStateProperty.all(
|
||||||
MaterialStateProperty.all(AppColors.background)),
|
AppColors.background)),
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
modalBottomSheet();
|
modalBottomSheet();
|
||||||
},
|
},
|
||||||
@ -185,6 +188,22 @@ class ProfileScreenState extends State<ProfileScreen> {
|
|||||||
'Generate Keys',
|
'Generate Keys',
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
SizedBox(width: 100),
|
||||||
|
ElevatedButton(
|
||||||
|
style: ButtonStyle(
|
||||||
|
backgroundColor: MaterialStateProperty.all(
|
||||||
|
AppColors.background)),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pushNamed(context, '/login').then((_) {
|
||||||
|
initState();
|
||||||
|
});
|
||||||
|
},
|
||||||
|
child: const Text(
|
||||||
|
'Login',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
Keys.keysExist
|
Keys.keysExist
|
||||||
? Row(
|
? Row(
|
||||||
children: [
|
children: [
|
||||||
|
Loading…
Reference in New Issue
Block a user