Skip to content

Commit

Permalink
Fixing pipeline upload failure
Browse files Browse the repository at this point in the history
Fixed login page transition to app
  • Loading branch information
subygan committed Mar 26, 2024
1 parent 98c704e commit 2205028
Show file tree
Hide file tree
Showing 6 changed files with 254 additions and 92 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/01_build_release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Flutter CI

on:
push:
branches:
- main
tags:
- "*"

Expand Down
2 changes: 1 addition & 1 deletion lib/const/consts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const String isProcessedColumn = "isProcessed";
const String insightsDirPathColumn = "zipPath";

// consts for network calls
const String baseUrl = "http://127.0.0.1:8000";
const String baseUrl = "http://52.72.143.117:8000";
const String loginUri = "/auth/login/";


Expand Down
3 changes: 2 additions & 1 deletion lib/db/db_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ class DatabaseHelper {
$nameColumn TEXT NOT NULL,
$usernameColumn TEXT NOT NULL,
$cookieColumn TEXT NOT NULL,
$emailColumn TEXT NOT NULL
$emailColumn TEXT NOT NULL,
$csrfTokenColumn TEXT NOT NULL
);
''');
await db.execute('''
Expand Down
24 changes: 19 additions & 5 deletions lib/db/user_models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:sqflite/sqflite.dart';
// Open the database and store the reference.

class User {
final int id;
int? id;
final String name;
final String userName;
final String email;
Expand All @@ -17,7 +17,7 @@ class User {
final String csrfToken;

User({
required this.id,
this.id,
required this.name,
required this.userName,
required this.email,
Expand All @@ -40,17 +40,30 @@ class User {

class UserProvider {
UserProvider();

//get csrf token from cookie
String parseCookie(String cookie) {
List<String> cookies = cookie.split(';');
for (var c in cookies) {
if (c.contains('csrftoken')) {
return c.split('=')[1];
}
}
return '';
}

Future<User> createUser(String name,String username,String email,String cookie) async {

Database db = await DatabaseHelper().database;
String csrfToken = parseCookie(cookie);
debugPrint('csrfToken: $csrfToken');
User user = User(
// TODO : check if id is autoincremented
id: 1,
name: name,
userName: username,
email: email,
cookie: cookie,
csrfToken: '',
csrfToken: csrfToken,
);
print(user.toMap());
var r = await db.insert(userTable, user.toMap(), conflictAlgorithm: ConflictAlgorithm.replace);
Expand All @@ -74,7 +87,8 @@ class UserProvider {
try {
Database db = await DatabaseHelper().database;
List<Map> maps = await db.query(userTable,
columns: [userIdColumn, nameColumn, usernameColumn, emailColumn, cookieColumn]);
columns: [userIdColumn, nameColumn, usernameColumn, emailColumn, cookieColumn, csrfTokenColumn]);
debugPrint('maps: $maps');
if (maps.isNotEmpty) {
return User(
id: maps[0][userIdColumn] as int,
Expand Down
156 changes: 73 additions & 83 deletions lib/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import 'package:flutter/material.dart';
import 'package:lang_fe/db/user_models.dart';
import 'package:lang_fe/login_screen.dart';

import 'color_palettes_screen.dart';
import 'component_screen.dart';
Expand Down Expand Up @@ -108,8 +109,7 @@ class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
one: FirstComponentList(
showNavBottomBar: showNavBarExample,
scaffoldKey: scaffoldKey,
showSecondList:
showMediumSizeLayout || showLargeSizeLayout),
showSecondList: showMediumSizeLayout || showLargeSizeLayout),
two: SecondComponentList(
scaffoldKey: scaffoldKey,
),
Expand All @@ -131,7 +131,6 @@ class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
}
}


PreferredSizeWidget createAppBar() {
return AppBar(
title: const Text(''),
Expand All @@ -158,99 +157,91 @@ class _HomeState extends State<Home> with SingleTickerProviderStateMixin {
],
);

bool isLoggedIn() {
UserProvider().getUser().then((user) {
if (user == null) {
Future<bool> isLoggedIn() async {
return await UserProvider().getUser().then((user) {
if (user != null) {
// Navigator.pushReplacementNamed(context, '/login');
debugPrint('User is not logged in');
return false;
debugPrint('true user');
return true;
}
return true;
debugPrint('false user');
return false;
});
return true;
}

void _showLoginModal() {
TextEditingController _controller =
TextEditingController(); // Controller for input

showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: const Text('Add context'),
content: TextField(
controller: _controller,
autofocus: true,
),
actions: <Widget>[
TextButton(
child: const Text('Don\'t save'),
onPressed: () {
Navigator.pop(context); // Close the modal
},
),
TextButton(
child: const Text('Save audio'),
onPressed: () {
setState(() {
// commentText = _controller.text;
// AudioRecordingProvider()
// .createRecording(path, commentText, "", getCurrentTime());
});
Navigator.pop(context); // Close the modal after submission
},
),
],
);
},
void homeRenderCallback() {
debugPrint("Home render callback");
setState(() {});
}

Widget LoginPage() {

return LoginScreen(
callback: homeRenderCallback,
);
}

Future<Widget> createScreen() async {
bool loggedin = await isLoggedIn();
return loggedin ? createScreenFor(ScreenSelected.values[screenIndex], false) : LoginPage();
}

@override
Widget build(BuildContext context) {
return AnimatedBuilder(
animation: controller,
builder: (context, child) {
return NavigationTransition(
scaffoldKey: scaffoldKey,
animationController: controller,
railAnimation: railAnimation,
appBar: createAppBar(),
body: createScreenFor(
ScreenSelected.values[screenIndex], controller.value == 1),
navigationRail: NavigationRail(
extended: showLargeSizeLayout,
destinations: navRailDestinations,
selectedIndex: screenIndex,
onDestinationSelected: (index) {
setState(() {
screenIndex = index;
handleScreenChanged(screenIndex);
});
},
trailing: Expanded(
child: Padding(
padding: const EdgeInsets.only(bottom: 20),
child: showLargeSizeLayout
? _ExpandedTrailingActions(
useLightMode: widget.useLightMode,
handleBrightnessChange: widget.handleBrightnessChange,
)
: _trailingActions(),
),
),
),
navigationBar: NavigationBars(
onSelectItem: (index) {
setState(() {
screenIndex = index;
handleScreenChanged(screenIndex);
});
},
selectedIndex: screenIndex,
isExampleBar: false,
),
scaffoldKey: scaffoldKey,
animationController: controller,
railAnimation: railAnimation,
appBar: createAppBar(),
body: FutureBuilder(
future: createScreen(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(
child: CircularProgressIndicator(),
);
} else if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else {
return snapshot.data!;
}
}),

navigationRail: NavigationRail(
extended: showLargeSizeLayout,
destinations: navRailDestinations,
selectedIndex: screenIndex,
onDestinationSelected: (index) {
setState(() {
screenIndex = index;
handleScreenChanged(screenIndex);
});
},
trailing: Expanded(
child: Padding(
padding: const EdgeInsets.only(bottom: 20),
child: showLargeSizeLayout
? _ExpandedTrailingActions(
useLightMode: widget.useLightMode,
handleBrightnessChange: widget.handleBrightnessChange,
)
: _trailingActions(),
),
),
),
navigationBar: NavigationBars(
onSelectItem: (index) {
setState(() {
screenIndex = index;
handleScreenChanged(screenIndex);
});
},
selectedIndex: screenIndex,
isExampleBar: false,
),
);
},
);
Expand Down Expand Up @@ -284,7 +275,6 @@ class _BrightnessButton extends StatelessWidget {
}
}


class _ExpandedTrailingActions extends StatelessWidget {
const _ExpandedTrailingActions({
required this.useLightMode,
Expand Down
Loading

0 comments on commit 2205028

Please sign in to comment.