Remove checkUrl function
This commit is contained in:
parent
0520b3017a
commit
a1e0dac4f4
|
|
@ -118,7 +118,7 @@ class AuthRepository {
|
||||||
Future<dynamic> addCompany({
|
Future<dynamic> addCompany({
|
||||||
@required Credentials credentials,
|
@required Credentials credentials,
|
||||||
}) async {
|
}) async {
|
||||||
final url = formatApiUrl(credentials.url) + '/companies';
|
final url = '${credentials.url}/companies';
|
||||||
final data = {
|
final data = {
|
||||||
'token_name': _tokenName,
|
'token_name': _tokenName,
|
||||||
};
|
};
|
||||||
|
|
@ -131,7 +131,7 @@ class AuthRepository {
|
||||||
@required String companyId,
|
@required String companyId,
|
||||||
@required String password,
|
@required String password,
|
||||||
}) async {
|
}) async {
|
||||||
final url = formatApiUrl(credentials.url) + '/companies/$companyId';
|
final url = '${credentials.url}/companies/$companyId';
|
||||||
return webClient.delete(url, credentials.token, password: password);
|
return webClient.delete(url, credentials.token, password: password);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,9 @@ class WebClient {
|
||||||
throw 'Server requests are not supported in the demo';
|
throw 'Server requests are not supported in the demo';
|
||||||
}
|
}
|
||||||
|
|
||||||
url = _checkUrl(url);
|
if (!url.contains('?')) {
|
||||||
|
url += '?';
|
||||||
|
}
|
||||||
print('GET: $url');
|
print('GET: $url');
|
||||||
|
|
||||||
if (url.contains('invoiceninja.com')) {
|
if (url.contains('invoiceninja.com')) {
|
||||||
|
|
@ -56,7 +58,10 @@ class WebClient {
|
||||||
throw 'Server requests are not supported in the demo';
|
throw 'Server requests are not supported in the demo';
|
||||||
}
|
}
|
||||||
|
|
||||||
url = _checkUrl(url);
|
if (!url.contains('?')) {
|
||||||
|
url += '?';
|
||||||
|
}
|
||||||
|
|
||||||
print('POST: $url');
|
print('POST: $url');
|
||||||
printWrapped('Data: $data');
|
printWrapped('Data: $data');
|
||||||
http.Response response;
|
http.Response response;
|
||||||
|
|
@ -94,7 +99,10 @@ class WebClient {
|
||||||
throw 'Server requests are not supported in the demo';
|
throw 'Server requests are not supported in the demo';
|
||||||
}
|
}
|
||||||
|
|
||||||
url = _checkUrl(url);
|
if (!url.contains('?')) {
|
||||||
|
url += '?';
|
||||||
|
}
|
||||||
|
|
||||||
print('PUT: $url');
|
print('PUT: $url');
|
||||||
printWrapped('Data: $data');
|
printWrapped('Data: $data');
|
||||||
|
|
||||||
|
|
@ -121,7 +129,10 @@ class WebClient {
|
||||||
throw 'Server requests are not supported in the demo';
|
throw 'Server requests are not supported in the demo';
|
||||||
}
|
}
|
||||||
|
|
||||||
url = _checkUrl(url);
|
if (!url.contains('?')) {
|
||||||
|
url += '?';
|
||||||
|
}
|
||||||
|
|
||||||
print('Delete: $url');
|
print('Delete: $url');
|
||||||
|
|
||||||
final http.Response response = await http.Client().delete(
|
final http.Response response = await http.Client().delete(
|
||||||
|
|
@ -135,24 +146,6 @@ class WebClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String _checkUrl(String url) {
|
|
||||||
print('## _checkUrl (PRE): $url');
|
|
||||||
if (!url.contains('/api/v1')) {
|
|
||||||
url = '/api/v1' + url;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!url.startsWith('http')) {
|
|
||||||
url = Constants.hostedApiUrl + url;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!url.contains('?')) {
|
|
||||||
url += '?';
|
|
||||||
}
|
|
||||||
|
|
||||||
print('## _checkUrl (POST): $url');
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, String> _getHeaders(String url, String token,
|
Map<String, String> _getHeaders(String url, String token,
|
||||||
{String secret, String password}) {
|
{String secret, String password}) {
|
||||||
if (url.startsWith(Constants.hostedApiUrl)) {
|
if (url.startsWith(Constants.hostedApiUrl)) {
|
||||||
|
|
|
||||||
|
|
@ -563,7 +563,6 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
|
||||||
//return 'Account: $account';
|
//return 'Account: $account';
|
||||||
//return 'Payment Terms: ${paymentTermState.map}';
|
//return 'Payment Terms: ${paymentTermState.map}';
|
||||||
//return 'Selected client: ${uiState.clientUIState.selectedId}, Filter: ${uiState.filterEntityType} ${uiState.filterEntityId}';
|
//return 'Selected client: ${uiState.clientUIState.selectedId}, Filter: ${uiState.filterEntityType} ${uiState.filterEntityId}';
|
||||||
return 'Columns: ${userCompany?.settings?.tableColumns ?? 'null'}';
|
|
||||||
return 'Layout: ${prefState.appLayout}, Route: ${uiState.currentRoute} Prev: ${uiState.previousRoute}';
|
return 'Layout: ${prefState.appLayout}, Route: ${uiState.currentRoute} Prev: ${uiState.previousRoute}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -52,10 +52,6 @@ void _saveAuthLocal(
|
||||||
}
|
}
|
||||||
|
|
||||||
void _loadAuthLocal(Store<AppState> store) async {
|
void _loadAuthLocal(Store<AppState> store) async {
|
||||||
if (kIsWeb) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
final SharedPreferences prefs = await SharedPreferences.getInstance();
|
||||||
final String email = kReleaseMode
|
final String email = kReleaseMode
|
||||||
? (prefs.getString(kSharedPrefEmail) ?? '')
|
? (prefs.getString(kSharedPrefEmail) ?? '')
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import 'package:invoiceninja_flutter/constants.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
||||||
import 'package:redux/redux.dart';
|
import 'package:redux/redux.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/auth/auth_actions.dart';
|
import 'package:invoiceninja_flutter/redux/auth/auth_actions.dart';
|
||||||
|
|
@ -7,6 +8,7 @@ Reducer<AuthState> authReducer = combineReducers([
|
||||||
TypedReducer<AuthState, UserLoginLoaded>(userLoginLoadedReducer),
|
TypedReducer<AuthState, UserLoginLoaded>(userLoginLoadedReducer),
|
||||||
TypedReducer<AuthState, UserLoginRequest>(userLoginRequestReducer),
|
TypedReducer<AuthState, UserLoginRequest>(userLoginRequestReducer),
|
||||||
TypedReducer<AuthState, OAuthLoginRequest>(oauthLoginRequestReducer),
|
TypedReducer<AuthState, OAuthLoginRequest>(oauthLoginRequestReducer),
|
||||||
|
TypedReducer<AuthState, OAuthSignUpRequest>(oauthSignUpRequestReducer),
|
||||||
TypedReducer<AuthState, UserSignUpRequest>(userSignUpRequestReducer),
|
TypedReducer<AuthState, UserSignUpRequest>(userSignUpRequestReducer),
|
||||||
TypedReducer<AuthState, UserLoginSuccess>(userLoginSuccessReducer),
|
TypedReducer<AuthState, UserLoginSuccess>(userLoginSuccessReducer),
|
||||||
TypedReducer<AuthState, UserVerifiedPassword>(userVerifiedPasswordReducer),
|
TypedReducer<AuthState, UserVerifiedPassword>(userVerifiedPasswordReducer),
|
||||||
|
|
@ -15,7 +17,7 @@ Reducer<AuthState> authReducer = combineReducers([
|
||||||
AuthState userSignUpRequestReducer(
|
AuthState userSignUpRequestReducer(
|
||||||
AuthState authState, UserSignUpRequest action) {
|
AuthState authState, UserSignUpRequest action) {
|
||||||
return authState.rebuild((b) => b
|
return authState.rebuild((b) => b
|
||||||
..url = ''
|
..url = formatApiUrl(kAppProductionUrl)
|
||||||
..secret = '');
|
..secret = '');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -42,6 +44,13 @@ AuthState oauthLoginRequestReducer(
|
||||||
..secret = action.secret);
|
..secret = action.secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AuthState oauthSignUpRequestReducer(
|
||||||
|
AuthState authState, OAuthSignUpRequest action) {
|
||||||
|
return authState.rebuild((b) => b
|
||||||
|
..url = formatApiUrl(kAppProductionUrl)
|
||||||
|
..secret = '');
|
||||||
|
}
|
||||||
|
|
||||||
AuthState userLoginSuccessReducer(
|
AuthState userLoginSuccessReducer(
|
||||||
AuthState authState, UserLoginSuccess action) {
|
AuthState authState, UserLoginSuccess action) {
|
||||||
return authState.rebuild((b) => b
|
return authState.rebuild((b) => b
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ class _UpgradeDialogState extends State<UpgradeDialog> {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final dynamic response = await webClient.post(
|
final dynamic response = await webClient.post(
|
||||||
'/api/v1/upgrade', state.credentials.token,
|
'$kAppProductionUrl/api/v1/upgrade', state.credentials.token,
|
||||||
data: json.encode(data));
|
data: json.encode(data));
|
||||||
final String message = response['message'];
|
final String message = response['message'];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -264,7 +264,7 @@ class _LoginState extends State<LoginView> {
|
||||||
context,
|
context,
|
||||||
completer,
|
completer,
|
||||||
email: _emailController.text,
|
email: _emailController.text,
|
||||||
url: _isSelfHosted ? _urlController.text : '',
|
url: _isSelfHosted ? _urlController.text : kAppProductionUrl,
|
||||||
secret: _isSelfHosted ? _secretController.text : '',
|
secret: _isSelfHosted ? _secretController.text : '',
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -273,14 +273,14 @@ class _LoginState extends State<LoginView> {
|
||||||
completer,
|
completer,
|
||||||
email: _emailController.text,
|
email: _emailController.text,
|
||||||
password: _passwordController.text,
|
password: _passwordController.text,
|
||||||
url: _isSelfHosted ? _urlController.text : '',
|
url: _isSelfHosted ? _urlController.text : kAppProductionUrl,
|
||||||
secret: _isSelfHosted ? _secretController.text : '',
|
secret: _isSelfHosted ? _secretController.text : '',
|
||||||
oneTimePassword: _oneTimePasswordController.text,
|
oneTimePassword: _oneTimePasswordController.text,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
viewModel.onGoogleLoginPressed(context, completer,
|
viewModel.onGoogleLoginPressed(context, completer,
|
||||||
url: _isSelfHosted ? _urlController.text : '',
|
url: _isSelfHosted ? _urlController.text : kAppProductionUrl,
|
||||||
secret: _isSelfHosted ? _secretController.text : '',
|
secret: _isSelfHosted ? _secretController.text : '',
|
||||||
oneTimePassword: _oneTimePasswordController.text);
|
oneTimePassword: _oneTimePasswordController.text);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/dashboard/dashboard_actions.dart';
|
import 'package:invoiceninja_flutter/redux/dashboard/dashboard_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/ui/pref_state.dart';
|
import 'package:invoiceninja_flutter/redux/ui/pref_state.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/app_builder.dart';
|
import 'package:invoiceninja_flutter/ui/app/app_builder.dart';
|
||||||
|
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/platforms.dart';
|
import 'package:invoiceninja_flutter/utils/platforms.dart';
|
||||||
import 'package:redux/redux.dart';
|
import 'package:redux/redux.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||||
|
|
@ -124,7 +125,7 @@ class LoginVM {
|
||||||
accessToken: value.accessToken,
|
accessToken: value.accessToken,
|
||||||
serverAuthCode: account
|
serverAuthCode: account
|
||||||
.displayName, // TODO fix this once PR is merged https://github.com/flutter/plugins/pull/2116
|
.displayName, // TODO fix this once PR is merged https://github.com/flutter/plugins/pull/2116
|
||||||
url: url.trim(),
|
url: formatApiUrl(url.trim()),
|
||||||
secret: secret.trim(),
|
secret: secret.trim(),
|
||||||
platform: getPlatform(context),
|
platform: getPlatform(context),
|
||||||
oneTimePassword: oneTimePassword,
|
oneTimePassword: oneTimePassword,
|
||||||
|
|
@ -194,7 +195,7 @@ class LoginVM {
|
||||||
store.dispatch(RecoverPasswordRequest(
|
store.dispatch(RecoverPasswordRequest(
|
||||||
completer: completer,
|
completer: completer,
|
||||||
email: email.trim(),
|
email: email.trim(),
|
||||||
url: url.trim(),
|
url: formatApiUrl(url.trim()),
|
||||||
secret: secret.trim(),
|
secret: secret.trim(),
|
||||||
));
|
));
|
||||||
completer.future.then((_) {
|
completer.future.then((_) {
|
||||||
|
|
@ -222,7 +223,7 @@ class LoginVM {
|
||||||
completer: completer,
|
completer: completer,
|
||||||
email: email.trim(),
|
email: email.trim(),
|
||||||
password: password.trim(),
|
password: password.trim(),
|
||||||
url: url.trim(),
|
url: formatApiUrl(url.trim()),
|
||||||
secret: secret.trim(),
|
secret: secret.trim(),
|
||||||
platform: getPlatform(context),
|
platform: getPlatform(context),
|
||||||
oneTimePassword: oneTimePassword.trim(),
|
oneTimePassword: oneTimePassword.trim(),
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,6 @@ import 'package:invoiceninja_flutter/ui/app/forms/app_form.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/edit_scaffold.dart';
|
import 'package:invoiceninja_flutter/ui/app/edit_scaffold.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/settings/account_management_vm.dart';
|
import 'package:invoiceninja_flutter/ui/settings/account_management_vm.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/dialogs.dart';
|
import 'package:invoiceninja_flutter/utils/dialogs.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
|
||||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||||
import 'package:url_launcher/url_launcher.dart';
|
import 'package:url_launcher/url_launcher.dart';
|
||||||
|
|
||||||
|
|
@ -171,8 +170,7 @@ class _AccountOverview extends StatelessWidget {
|
||||||
callback: (value) {
|
callback: (value) {
|
||||||
final state = viewModel.state;
|
final state = viewModel.state;
|
||||||
final credentials = state.credentials;
|
final credentials = state.credentials;
|
||||||
final url = formatApiUrl(credentials.url) +
|
final url = '${credentials.url}/claim_license?license_key=$value';
|
||||||
'/claim_license?license_key=$value';
|
|
||||||
WebClient()
|
WebClient()
|
||||||
.post(
|
.post(
|
||||||
url,
|
url,
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@ import 'package:invoiceninja_flutter/data/models/design_model.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/serializers.dart';
|
import 'package:invoiceninja_flutter/data/models/serializers.dart';
|
||||||
import 'package:invoiceninja_flutter/data/web_client.dart';
|
import 'package:invoiceninja_flutter/data/web_client.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
|
||||||
import 'package:invoiceninja_flutter/.env.dart';
|
import 'package:invoiceninja_flutter/.env.dart';
|
||||||
|
|
||||||
import 'dialogs.dart';
|
import 'dialogs.dart';
|
||||||
|
|
@ -24,7 +23,7 @@ void loadDesign({
|
||||||
final webClient = WebClient();
|
final webClient = WebClient();
|
||||||
final state = StoreProvider.of<AppState>(context).state;
|
final state = StoreProvider.of<AppState>(context).state;
|
||||||
final credentials = state.credentials;
|
final credentials = state.credentials;
|
||||||
final url = formatApiUrl(credentials.url) + '/preview';
|
final url = '${credentials.url}/preview';
|
||||||
|
|
||||||
final request = DesignPreviewRequest(design: design);
|
final request = DesignPreviewRequest(design: design);
|
||||||
final data =
|
final data =
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import 'package:flutter_redux/flutter_redux.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/invoice_model.dart';
|
import 'package:invoiceninja_flutter/data/models/invoice_model.dart';
|
||||||
import 'package:invoiceninja_flutter/data/web_client.dart';
|
import 'package:invoiceninja_flutter/data/web_client.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
|
||||||
import 'package:invoiceninja_flutter/.env.dart';
|
import 'package:invoiceninja_flutter/.env.dart';
|
||||||
import 'dialogs.dart';
|
import 'dialogs.dart';
|
||||||
|
|
||||||
|
|
@ -24,7 +23,7 @@ void loadEmailTemplate({
|
||||||
final webClient = WebClient();
|
final webClient = WebClient();
|
||||||
final state = StoreProvider.of<AppState>(context).state;
|
final state = StoreProvider.of<AppState>(context).state;
|
||||||
final credentials = state.credentials;
|
final credentials = state.credentials;
|
||||||
final url = formatApiUrl(credentials.url) + '/templates';
|
final url = '${credentials.url}/templates';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
final invoice = state.invoiceState.list.isEmpty
|
final invoice = state.invoiceState.list.isEmpty
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue