Skip to content

Commit

Permalink
💄 Login improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
LNA-DEV committed Nov 1, 2024
1 parent a4e4c8b commit e5a63d7
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 46 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"cSpell.words": [
"autofocus",
"Focusable",
"fullscreen"
"fullscreen",
"grey"
],
"cmake.sourceDirectory": "/home/lna-dev/Documents/Repos/OpenMediaStation.FE.MovieTV/windows/runner"
}
4 changes: 2 additions & 2 deletions lib/apis/auth_info_api.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'dart:convert';
import 'package:open_media_server_app/apis/base_api.dart';
import 'package:http/http.dart' as http;
import 'package:open_media_server_app/globals/preference_globals.dart';
import 'package:open_media_server_app/helpers/preferences.dart';
import 'package:open_media_server_app/models/auth/auth_info.dart';

class AuthInfoApi {
Future<AuthInfo> getAuthInfo() async {
String apiUrl = "${PreferenceGlobals.BaseUrl}/auth/info";
String apiUrl = "${Preferences.prefs?.getString("BaseUrl")}/auth/info";

var headers = BaseApi.getHeaders();

Expand Down
12 changes: 6 additions & 6 deletions lib/apis/inventory_api.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:convert';
import 'package:open_media_server_app/apis/base_api.dart';
import 'package:open_media_server_app/globals/preference_globals.dart';
import 'package:open_media_server_app/helpers/preferences.dart';
import 'package:open_media_server_app/models/inventory/episode.dart';
import 'package:open_media_server_app/models/inventory/inventory_item.dart';
import 'package:http/http.dart' as http;
Expand All @@ -10,7 +10,7 @@ import 'package:open_media_server_app/models/inventory/show.dart';

class InventoryApi {
Future<List<InventoryItem>> listItems(String category) async {
String apiUrl = "${PreferenceGlobals.BaseUrl}/api/inventory/items?";
String apiUrl = "${Preferences.prefs?.getString("BaseUrl")}/api/inventory/items?";

var headers = BaseApi.getHeaders();

Expand All @@ -26,7 +26,7 @@ class InventoryApi {
}

Future<Movie> getMovie(String id) async {
String apiUrl = "${PreferenceGlobals.BaseUrl}/api/inventory/movie?";
String apiUrl = "${Preferences.prefs?.getString("BaseUrl")}/api/inventory/movie?";

var headers = BaseApi.getHeaders();

Expand All @@ -42,7 +42,7 @@ class InventoryApi {
}

Future<Show> getShow(String id) async {
String apiUrl = "${PreferenceGlobals.BaseUrl}/api/inventory/show?";
String apiUrl = "${Preferences.prefs?.getString("BaseUrl")}/api/inventory/show?";

var headers = BaseApi.getHeaders();

Expand All @@ -58,7 +58,7 @@ class InventoryApi {
}

Future<Season> getSeason(String id) async {
String apiUrl = "${PreferenceGlobals.BaseUrl}/api/inventory/season?";
String apiUrl = "${Preferences.prefs?.getString("BaseUrl")}/api/inventory/season?";

var headers = BaseApi.getHeaders();

Expand All @@ -74,7 +74,7 @@ class InventoryApi {
}

Future<Episode> getEpisode(String id) async {
String apiUrl = "${PreferenceGlobals.BaseUrl}/api/inventory/episode?";
String apiUrl = "${Preferences.prefs?.getString("BaseUrl")}/api/inventory/episode?";

var headers = BaseApi.getHeaders();

Expand Down
4 changes: 2 additions & 2 deletions lib/apis/metadata_api.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'dart:convert';
import 'package:open_media_server_app/apis/base_api.dart';
import 'package:open_media_server_app/globals/preference_globals.dart';
import 'package:open_media_server_app/helpers/preferences.dart';
import 'package:open_media_server_app/models/metadata/metadata_model.dart';
import 'package:http/http.dart' as http;

class MetadataApi {
Future<MetadataModel> getMetadata(String id, String category) async {
String apiUrl = "${PreferenceGlobals.BaseUrl}/api/metadata?";
String apiUrl = "${Preferences.prefs?.getString("BaseUrl")}/api/metadata?";

var headers = BaseApi.getHeaders();

Expand Down
4 changes: 2 additions & 2 deletions lib/globals/auth_globals.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import 'package:flutter/foundation.dart';
import 'package:open_media_server_app/globals/preference_globals.dart';
import 'package:open_media_server_app/helpers/preferences.dart';

class AuthGlobals {
static String get redirectUriWeb {
if (kDebugMode) {
return "http://localhost:8000/redirect.html";
} else {
return "https://${PreferenceGlobals.BaseUrl}/redirect.html";
return "https://${Preferences.prefs?.getString("BaseUrl")}/redirect.html";
}
}

Expand Down
5 changes: 0 additions & 5 deletions lib/globals/preference_globals.dart

This file was deleted.

4 changes: 2 additions & 2 deletions lib/views/detail_views/episode_detail.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:open_media_server_app/globals/globals.dart';
import 'package:open_media_server_app/globals/preference_globals.dart';
import 'package:open_media_server_app/helpers/preferences.dart';
import 'package:open_media_server_app/models/internal/grid_item_model.dart';
import 'package:open_media_server_app/views/player.dart';
import 'package:open_media_server_app/widgets/custom_image.dart';
Expand Down Expand Up @@ -72,7 +72,7 @@ class EpisodeDetailView extends StatelessWidget {
MaterialPageRoute(
builder: (context) => PlayerView(
url:
"${PreferenceGlobals.BaseUrl}/stream/${itemModel.inventoryItem?.category}/${itemModel.inventoryItem?.id}"),
"${Preferences.prefs?.getString("BaseUrl")}/stream/${itemModel.inventoryItem?.category}/${itemModel.inventoryItem?.id}"),
),
);
},
Expand Down
4 changes: 2 additions & 2 deletions lib/views/detail_views/movie_detail.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:open_media_server_app/globals/globals.dart';
import 'package:open_media_server_app/globals/preference_globals.dart';
import 'package:open_media_server_app/helpers/preferences.dart';
import 'package:open_media_server_app/models/internal/grid_item_model.dart';
import 'package:open_media_server_app/views/player.dart';
import 'package:open_media_server_app/widgets/custom_image.dart';
Expand Down Expand Up @@ -71,7 +71,7 @@ class MovieDetailView extends StatelessWidget {
MaterialPageRoute(
builder: (context) => PlayerView(
url:
"${PreferenceGlobals.BaseUrl}/stream/${itemModel.inventoryItem?.category}/${itemModel.inventoryItem?.id}"),
"${Preferences.prefs?.getString("BaseUrl")}/stream/${itemModel.inventoryItem?.category}/${itemModel.inventoryItem?.id}"),
),
);
},
Expand Down
114 changes: 90 additions & 24 deletions lib/views/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ class LoginView extends StatelessWidget {

@override
Widget build(BuildContext context) {
if (Preferences.prefs?.getString("BaseUrl") != null) {
return FutureBuilder(
future: authenticate(context),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
} else if (snapshot.hasError) {
return Center(child: Text('Error: ${snapshot.error}'));
}

return widget;
},
);
}

return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).scaffoldBackgroundColor,
Expand All @@ -22,32 +37,83 @@ class LoginView extends StatelessWidget {
),
body: Form(
key: _formKey,
child: Column(
children: [
TextFormField(
controller: domainController,
decoration: const InputDecoration(
hintText: 'Domain',
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: [
TextFormField(
controller: domainController,
decoration: InputDecoration(
hintText: 'Host',
contentPadding: const EdgeInsets.symmetric(
vertical: 16.0,
horizontal: 16.0,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(12.0),
borderSide: BorderSide(
color: Colors.grey[400]!,
width: 1.5,
),
),
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12.0),
borderSide: const BorderSide(
color: Colors.blue,
width: 2.0,
),
),
enabledBorder: OutlineInputBorder(
borderRadius: BorderRadius.circular(12.0),
borderSide: BorderSide(
color: Colors.grey[400]!,
width: 1.5,
),
),
),
validator: (String? value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}

if (!value.contains("http://") && !value.contains("https://")) {
return 'You need to specify the host in this format\nExample: https://example.com';
}

return null;
},
),
validator: (String? value) {
if (value == null || value.isEmpty) {
return 'Please enter some text';
}
return null;
},
),
ElevatedButton(
onPressed: () async {
if (_formKey.currentState!.validate()) {
Preferences.prefs!
.setString("BaseUrl", domainController.text);
const SizedBox(
height: 16,
),
SizedBox(
width: double.infinity,
height: 40,
child: ElevatedButton(
onPressed: () async {
if (_formKey.currentState!.validate()) {
await Preferences.prefs!
.setString("BaseUrl", domainController.text);

authenticate(context);
}
},
child: const Text("Submit"),
),
],
await authenticate(context);
}
},
style: ElevatedButton.styleFrom(
padding: const EdgeInsets.symmetric(
vertical: 8,
),
textStyle: const TextStyle(
fontSize: 18,
fontWeight: FontWeight.w400,
),
backgroundColor: Colors.white,
foregroundColor: Colors.black,
),
child: const Text("Connect"),
),
),
],
),
),
),
);
Expand Down

0 comments on commit e5a63d7

Please sign in to comment.