Email login
This commit is contained in:
parent
e809b24f5b
commit
46f3aa30da
|
@ -1,3 +1,4 @@
|
|||
import 'package:crypto/crypto.dart';
|
||||
import 'package:freezer/api/definitions.dart';
|
||||
import 'package:freezer/api/spotify.dart';
|
||||
import 'package:freezer/settings.dart';
|
||||
|
@ -77,6 +78,32 @@ class DeezerAPI {
|
|||
return _authorizing;
|
||||
}
|
||||
|
||||
//Login with email
|
||||
static Future<String> getArlByEmail(String email, String password) async {
|
||||
//Get MD5 of password
|
||||
Digest digest = md5.convert(utf8.encode(password));
|
||||
String md5password = '$digest';
|
||||
//Get access token
|
||||
String url = "https://tv.deezer.com/smarttv/8caf9315c1740316053348a24d25afc7/user_auth.php?login=$email&password=$md5password&device=panasonic&output=json";
|
||||
http.Response response = await http.get(url);
|
||||
String accessToken = jsonDecode(response.body)["access_token"];
|
||||
//Get SID
|
||||
url = "https://api.deezer.com/platform/generic/track/42069";
|
||||
response = await http.get(url, headers: {"Authorization": "Bearer $accessToken"});
|
||||
String sid;
|
||||
for (String cookieHeader in response.headers['set-cookie'].split(';')) {
|
||||
if (cookieHeader.startsWith('sid=')) {
|
||||
sid = cookieHeader.split('=')[1];
|
||||
}
|
||||
}
|
||||
if (sid == null) return null;
|
||||
//Get ARL
|
||||
url = "https://deezer.com/ajax/gw-light.php?api_version=1.0&api_token=null&input=3&method=user.getArl";
|
||||
response = await http.get(url, headers: {"Cookie": "sid=$sid"});
|
||||
return jsonDecode(response.body)["results"];
|
||||
}
|
||||
|
||||
|
||||
//Authorize, bool = success
|
||||
Future<bool> rawAuthorize({Function onError}) async {
|
||||
try {
|
||||
|
@ -489,4 +516,3 @@ class DeezerAPI {
|
|||
return data['results']['EPISODES']['data'].map<ShowEpisode>((e) => ShowEpisode.fromPrivateJson(e)).toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:sqflite/sql.dart';
|
||||
import 'package:disk_space/disk_space.dart';
|
||||
import 'package:filesize/filesize.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -15,9 +15,7 @@ import 'package:permission_handler/permission_handler.dart';
|
|||
import 'package:freezer/translations.i18n.dart';
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:sqflite/sqflite.dart';
|
||||
import 'package:sqflite/sql.dart';
|
||||
import 'dart:async';
|
||||
|
||||
DownloadManager downloadManager = DownloadManager();
|
||||
|
||||
|
|
|
@ -343,6 +343,11 @@ const language_en_us = {
|
|||
//0.6.10
|
||||
"Deezer is unavailable in your country, Freezer might not work properly. Please use a VPN": "Deezer is unavailable in your country, Freezer might not work properly. Please use a VPN",
|
||||
"Deezer is unavailable": "Deezer is unavailable",
|
||||
"Continue": "Continue"
|
||||
"Continue": "Continue",
|
||||
"Email Login": "Email Login",
|
||||
"Email": "Email",
|
||||
"Missing email or password!": "Missing email or password!",
|
||||
"Error logging in using email, please check your credentials.\nError:": "Error logging in using email, please check your credentials.\nError:",
|
||||
"Error logging in!": "Error logging in!"
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:freezer/api/deezer.dart';
|
||||
import 'package:freezer/api/player.dart';
|
||||
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
|
||||
|
@ -186,6 +187,21 @@ class _LoginWidgetState extends State<LoginWidget> {
|
|||
),
|
||||
),
|
||||
Container(height: 16.0,),
|
||||
//Email login dialog
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 32.0),
|
||||
child: OutlineButton(
|
||||
child: Text(
|
||||
'Login using email'.i18n,
|
||||
),
|
||||
onPressed: () {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => EmailLogin(_update)
|
||||
);
|
||||
},
|
||||
)
|
||||
),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 32.0),
|
||||
child: OutlineButton(
|
||||
|
@ -312,3 +328,104 @@ class LoginBrowser extends StatelessWidget {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
class EmailLogin extends StatefulWidget {
|
||||
|
||||
Function callback;
|
||||
EmailLogin(this.callback, {Key key}): super(key: key);
|
||||
|
||||
@override
|
||||
_EmailLoginState createState() => _EmailLoginState();
|
||||
}
|
||||
|
||||
class _EmailLoginState extends State<EmailLogin> {
|
||||
|
||||
String _email;
|
||||
String _password;
|
||||
bool _loading = false;
|
||||
|
||||
void _login() async {
|
||||
setState(() => _loading = true);
|
||||
//Try logging in
|
||||
String arl;
|
||||
String exception;
|
||||
try {
|
||||
arl = await DeezerAPI.getArlByEmail(_email, _password);
|
||||
} catch (e, st) {
|
||||
exception = e.toString();
|
||||
print(e);
|
||||
print(st);
|
||||
}
|
||||
setState(() => _loading = false);
|
||||
|
||||
//Success
|
||||
if (arl != null) {
|
||||
settings.arl = arl;
|
||||
Navigator.of(context).pop();
|
||||
widget.callback();
|
||||
return;
|
||||
}
|
||||
|
||||
//Error
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text("Error logging in!".i18n),
|
||||
content: Text("Error logging in using email, please check your credentials.\nError: " + exception),
|
||||
actions: [
|
||||
TextButton(
|
||||
child: Text('Dismiss'.i18n),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
)
|
||||
],
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: Text('Email Login'.i18n),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children:
|
||||
_loading ? [
|
||||
CircularProgressIndicator()
|
||||
]: [
|
||||
TextField(
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Email'.i18n
|
||||
),
|
||||
onChanged: (s) => _email = s,
|
||||
),
|
||||
Container(height: 8.0,),
|
||||
TextField(
|
||||
obscureText: true,
|
||||
decoration: InputDecoration(
|
||||
labelText: "Password".i18n
|
||||
),
|
||||
onChanged: (s) => _password = s,
|
||||
)
|
||||
],
|
||||
),
|
||||
actions: [
|
||||
if (!_loading)
|
||||
TextButton(
|
||||
child: Text('Login'),
|
||||
onPressed: () async {
|
||||
if (_email != null && _password != null)
|
||||
await _login();
|
||||
else
|
||||
Fluttertoast.showToast(
|
||||
msg: "Missing email or password!".i18n,
|
||||
gravity: ToastGravity.BOTTOM,
|
||||
toastLength: Toast.LENGTH_SHORT
|
||||
);
|
||||
},
|
||||
)
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -219,7 +219,7 @@ packages:
|
|||
source: hosted
|
||||
version: "2.0.0"
|
||||
crypto:
|
||||
dependency: transitive
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: crypto
|
||||
url: "https://pub.dartlang.org"
|
||||
|
|
|
@ -27,6 +27,7 @@ dependencies:
|
|||
flutter_localizations:
|
||||
sdk: flutter
|
||||
|
||||
crypto: ^2.1.5
|
||||
http: ^0.12.2
|
||||
cookie_jar: ^1.0.1
|
||||
json_annotation: ^3.0.1
|
||||
|
|
Loading…
Reference in New Issue