mirror of
https://github.com/go-vikunja/app
synced 2024-06-02 18:49:47 +00:00
fixed self-signed cert ignoring
This commit is contained in:
parent
03a131e7dc
commit
57dd1d3e85
|
@ -9,15 +9,8 @@ import 'package:vikunja_app/api/response.dart';
|
|||
import 'package:vikunja_app/components/string_extension.dart';
|
||||
import 'package:vikunja_app/global.dart';
|
||||
|
||||
class IgnoreCertHttpOverrides extends HttpOverrides {
|
||||
bool ignoreCertificates = false;
|
||||
IgnoreCertHttpOverrides(bool ignore) {ignoreCertificates = ignore;}
|
||||
@override
|
||||
HttpClient createHttpClient(SecurityContext context) {
|
||||
return super.createHttpClient(context)
|
||||
..badCertificateCallback = (_, __, ___) => ignoreCertificates;
|
||||
}
|
||||
}
|
||||
import '../main.dart';
|
||||
|
||||
|
||||
class Client {
|
||||
GlobalKey<ScaffoldMessengerState> global;
|
||||
|
@ -39,14 +32,19 @@ class Client {
|
|||
return otherClient._token == _token;
|
||||
}
|
||||
|
||||
Client(this.global, {String token, String base, bool authenticated = false})
|
||||
{
|
||||
Client(this.global, {String token, String base, bool authenticated = false}) {
|
||||
configure(token: token, base: base, authenticated: authenticated);
|
||||
//client.badCertificateCallback = (_,__,___) => ignoreCertificates;
|
||||
HttpOverrides.global = IgnoreCertHttpOverrides(ignoreCertificates);
|
||||
}
|
||||
|
||||
get _headers => {
|
||||
void reload_ignore_certs(bool val) {
|
||||
ignoreCertificates = val;
|
||||
HttpOverrides.global = new IgnoreCertHttpOverrides(ignoreCertificates);
|
||||
VikunjaGlobal.of(global.currentContext).settingsManager.setIgnoreCertificates(val);
|
||||
|
||||
}
|
||||
|
||||
get _headers =>
|
||||
{
|
||||
'Authorization': _token != null ? 'Bearer $_token' : '',
|
||||
'Content-Type': 'application/json'
|
||||
};
|
||||
|
@ -55,16 +53,15 @@ class Client {
|
|||
int get hashCode => _token.hashCode;
|
||||
|
||||
void configure({String token, String base, bool authenticated}) {
|
||||
if(token != null)
|
||||
if (token != null)
|
||||
_token = token;
|
||||
if(base != null)
|
||||
if (base != null)
|
||||
_base = base.endsWith('/api/v1') ? base : '$base/api/v1';
|
||||
if(authenticated != null)
|
||||
if (authenticated != null)
|
||||
this.authenticated = authenticated;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void reset() {
|
||||
_token = _base = null;
|
||||
authenticated = false;
|
||||
|
@ -87,7 +84,7 @@ class Client {
|
|||
fragment: uri.fragment);
|
||||
return http.get(newUri, headers: _headers)
|
||||
.then(_handleResponse, onError: _handleError);
|
||||
}
|
||||
}
|
||||
|
||||
Future<Response> delete(String url) {
|
||||
return http
|
||||
|
@ -99,6 +96,7 @@ class Client {
|
|||
}
|
||||
|
||||
Future<Response> post(String url, {dynamic body}) {
|
||||
log('post');
|
||||
return http
|
||||
.post(
|
||||
'${this.base}$url'.toUri(),
|
||||
|
@ -120,13 +118,16 @@ class Client {
|
|||
|
||||
void _handleError(dynamic e) {
|
||||
log(e.toString());
|
||||
SnackBar snackBar = SnackBar(content: Text("Error on request: " + e.toString()));
|
||||
SnackBar snackBar = SnackBar(
|
||||
content: Text("Error on request: " + e.toString()));
|
||||
global.currentState?.showSnackBar(snackBar);
|
||||
}
|
||||
|
||||
Map<String,String> headersToMap(HttpHeaders headers) {
|
||||
Map<String,String> map = {};
|
||||
headers.forEach((name, values) {map[name] = values[0].toString();});
|
||||
Map<String, String> headersToMap(HttpHeaders headers) {
|
||||
Map<String, String> map = {};
|
||||
headers.forEach((name, values) {
|
||||
map[name] = values[0].toString();
|
||||
});
|
||||
return map;
|
||||
}
|
||||
|
||||
|
@ -159,6 +160,7 @@ class Client {
|
|||
response.statusCode >= 400 ||
|
||||
json == null) {
|
||||
Map<String, dynamic> error;
|
||||
log(response.body);
|
||||
error = _decoder.convert(response.body);
|
||||
if (response.statusCode ~/ 100 == 4) {
|
||||
throw new InvalidRequestApiException(
|
||||
|
@ -167,15 +169,16 @@ class Client {
|
|||
error["message"] ?? "Unknown Error");
|
||||
}
|
||||
final SnackBar snackBar = SnackBar(
|
||||
content: Text("Error code "+response.statusCode.toString()+" received."),
|
||||
content: Text(
|
||||
"Error code " + response.statusCode.toString() + " received."),
|
||||
action: SnackBarAction(
|
||||
label: ("Show Details"),
|
||||
onPressed: (){
|
||||
onPressed: () {
|
||||
Builder(
|
||||
builder: (BuildContext context) =>
|
||||
Dialog(
|
||||
child: Text(error["message"]),
|
||||
)
|
||||
Dialog(
|
||||
child: Text(error["message"]),
|
||||
)
|
||||
);
|
||||
},
|
||||
),
|
||||
|
|
|
@ -1,13 +1,28 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:vikunja_app/global.dart';
|
||||
import 'package:vikunja_app/pages/home.dart';
|
||||
import 'package:vikunja_app/pages/user/login.dart';
|
||||
import 'package:vikunja_app/theme/theme.dart';
|
||||
//import 'package:alice/alice.dart';
|
||||
import 'package:http/http.dart';
|
||||
|
||||
class IgnoreCertHttpOverrides extends HttpOverrides {
|
||||
bool ignoreCerts;
|
||||
IgnoreCertHttpOverrides(bool _ignore) {ignoreCerts = _ignore;}
|
||||
@override
|
||||
HttpClient createHttpClient(SecurityContext context) {
|
||||
return super.createHttpClient(context)
|
||||
..badCertificateCallback = (_, __, ___) => ignoreCerts;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
runApp(VikunjaGlobal(
|
||||
child: new VikunjaApp(home: HomePage()),
|
||||
login: new VikunjaApp(home: LoginPage())));
|
||||
}
|
||||
|
||||
void main() => runApp(VikunjaGlobal(
|
||||
child: new VikunjaApp(home: HomePage()),
|
||||
login: new VikunjaApp(home: LoginPage())));
|
||||
|
||||
class VikunjaApp extends StatelessWidget {
|
||||
final Widget home;
|
||||
|
@ -15,7 +30,7 @@ class VikunjaApp extends StatelessWidget {
|
|||
const VikunjaApp({Key key, this.home}) : super(key: key);
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
|
||||
return new MaterialApp(
|
||||
title: 'Vikunja',
|
||||
theme: buildVikunjaTheme(),
|
||||
|
|
|
@ -42,8 +42,7 @@ class SettingsPageState extends State<SettingsPage> {
|
|||
ignoreCertificates != null ?
|
||||
CheckboxListTile(title: Text("Ignore Certificates"), value: ignoreCertificates, onChanged: (value) {
|
||||
setState(() => ignoreCertificates = value);
|
||||
VikunjaGlobal.of(context).settingsManager.setIgnoreCertificates(value);
|
||||
VikunjaGlobal.of(context).client.ignoreCertificates = value;
|
||||
VikunjaGlobal.of(context).client.reload_ignore_certs(value);
|
||||
}) : ListTile(title: Text("..."))
|
||||
],
|
||||
),
|
||||
|
|
|
@ -25,7 +25,6 @@ class _LoginPageState extends State<LoginPage> {
|
|||
final _formKey = GlobalKey<FormState>();
|
||||
bool _loading = false;
|
||||
bool _rememberMe = false;
|
||||
bool ignoreCertificates;
|
||||
|
||||
final _serverController = TextEditingController();
|
||||
final _usernameController = TextEditingController();
|
||||
|
@ -53,8 +52,9 @@ class _LoginPageState extends State<LoginPage> {
|
|||
|
||||
@override
|
||||
Widget build(BuildContext ctx) {
|
||||
if(ignoreCertificates == null)
|
||||
VikunjaGlobal.of(context).settingsManager.getIgnoreCertificates().then((value) => setState(() => ignoreCertificates = value == "1" ? true:false));
|
||||
Client client = VikunjaGlobal.of(context).client;
|
||||
if(client.ignoreCertificates == null)
|
||||
VikunjaGlobal.of(context).settingsManager.getIgnoreCertificates().then((value) => setState(() => client.ignoreCertificates = value == "1" ? true:false));
|
||||
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
|
@ -156,9 +156,9 @@ class _LoginPageState extends State<LoginPage> {
|
|||
}
|
||||
},
|
||||
child: VikunjaButtonText("Login with Frontend"))),
|
||||
ignoreCertificates != null ?
|
||||
CheckboxListTile(title: Text("Ignore Certificates"), value: ignoreCertificates, onChanged: (value) {
|
||||
setState(() => ignoreCertificates = value);
|
||||
client.ignoreCertificates != null ?
|
||||
CheckboxListTile(title: Text("Ignore Certificates"), value: client.ignoreCertificates, onChanged: (value) {
|
||||
setState(() => client.reload_ignore_certs(value));
|
||||
VikunjaGlobal.of(context).settingsManager.setIgnoreCertificates(value);
|
||||
VikunjaGlobal.of(context).client.ignoreCertificates = value;
|
||||
}) : ListTile(title: Text("..."))
|
||||
|
@ -216,7 +216,9 @@ class _LoginPageState extends State<LoginPage> {
|
|||
}
|
||||
}
|
||||
vGlobal.changeUser(newUser.user, token: newUser.token, base: _server);
|
||||
} catch (ex) {
|
||||
} catch (ex, stacktrace) {
|
||||
log(stacktrace.toString());
|
||||
throw ex;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => new AlertDialog(
|
||||
|
|
Loading…
Reference in New Issue
Block a user