Commit c37ce6fa authored by Administrator's avatar Administrator

hack to make strava_flutter multi user

parent 1bda7476
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"macos":[{"name":"package_info","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]},{"name":"shared_preferences_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+8/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"url_launcher_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+5/","dependencies":[]}],"linux":[{"name":"url_launcher_linux","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.0.1+1/","dependencies":[]}],"windows":[],"web":[{"name":"shared_preferences_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+5/","dependencies":[]},{"name":"url_launcher_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.1+5/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"uni_links","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_linux","url_launcher_macos"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-08-03 12:50:19.356654","version":"1.17.3"}
\ No newline at end of file
{"info":"This is a generated file; do not edit or check into version control.","plugins":{"ios":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"android":[{"name":"flutter_secure_storage","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-3.3.3/","dependencies":[]},{"name":"package_info","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider-1.6.8/","dependencies":[]},{"name":"shared_preferences","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences-0.5.7+2/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"uni_links","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/uni_links-0.4.0/","dependencies":[]},{"name":"url_launcher","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher-5.5.0/","dependencies":[]}],"macos":[{"name":"package_info","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/package_info-0.4.1/","dependencies":[]},{"name":"path_provider_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/path_provider_macos-0.0.4+2/","dependencies":[]},{"name":"shared_preferences_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_macos-0.0.1+8/","dependencies":[]},{"name":"sqflite","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/sqflite-1.3.0+1/","dependencies":[]},{"name":"url_launcher_macos","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_macos-0.0.1+5/","dependencies":[]}],"linux":[{"name":"url_launcher_linux","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_linux-0.0.1+1/","dependencies":[]}],"windows":[],"web":[{"name":"shared_preferences_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/shared_preferences_web-0.1.2+5/","dependencies":[]},{"name":"url_launcher_web","path":"/home/stefan/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/url_launcher_web-0.1.1+5/","dependencies":[]}]},"dependencyGraph":[{"name":"flutter_secure_storage","dependencies":[]},{"name":"package_info","dependencies":[]},{"name":"path_provider","dependencies":["path_provider_macos"]},{"name":"path_provider_macos","dependencies":[]},{"name":"shared_preferences","dependencies":["shared_preferences_macos","shared_preferences_web"]},{"name":"shared_preferences_macos","dependencies":[]},{"name":"shared_preferences_web","dependencies":[]},{"name":"sqflite","dependencies":[]},{"name":"uni_links","dependencies":[]},{"name":"url_launcher","dependencies":["url_launcher_web","url_launcher_linux","url_launcher_macos"]},{"name":"url_launcher_linux","dependencies":[]},{"name":"url_launcher_macos","dependencies":[]},{"name":"url_launcher_web","dependencies":[]}],"date_created":"2020-08-03 15:05:19.132316","version":"1.17.3"}
\ No newline at end of file
......@@ -25,6 +25,10 @@ const SqfEntityTable tableAthlete = SqfEntityTable(
SqfEntityField('geoState', DbType.text),
SqfEntityField('downloadInterval', DbType.integer),
SqfEntityField('recordAggregationCount', DbType.integer),
SqfEntityField('stravaAccessToken', DbType.text),
SqfEntityField('stravaScope', DbType.text),
SqfEntityField('stravaRefreshToken', DbType.text),
SqfEntityField('stravaExpire', DbType.integer),
],
);
......
......@@ -43,6 +43,10 @@ class TableDbAthlete extends SqfEntityTableBase {
SqfEntityFieldBase('downloadInterval', DbType.integer, isNotNull: false),
SqfEntityFieldBase('recordAggregationCount', DbType.integer,
isNotNull: false),
SqfEntityFieldBase('stravaAccessToken', DbType.text, isNotNull: false),
SqfEntityFieldBase('stravaScope', DbType.text, isNotNull: false),
SqfEntityFieldBase('stravaRefreshToken', DbType.text, isNotNull: false),
SqfEntityFieldBase('stravaExpire', DbType.integer, isNotNull: false),
];
super.init();
}
......@@ -782,7 +786,11 @@ class DbAthlete {
this.stravaId,
this.geoState,
this.downloadInterval,
this.recordAggregationCount}) {
this.recordAggregationCount,
this.stravaAccessToken,
this.stravaScope,
this.stravaRefreshToken,
this.stravaExpire}) {
_setDefaultValues();
}
DbAthlete.withFields(
......@@ -794,7 +802,11 @@ class DbAthlete {
this.stravaId,
this.geoState,
this.downloadInterval,
this.recordAggregationCount) {
this.recordAggregationCount,
this.stravaAccessToken,
this.stravaScope,
this.stravaRefreshToken,
this.stravaExpire) {
_setDefaultValues();
}
DbAthlete.withId(
......@@ -807,7 +819,11 @@ class DbAthlete {
this.stravaId,
this.geoState,
this.downloadInterval,
this.recordAggregationCount) {
this.recordAggregationCount,
this.stravaAccessToken,
this.stravaScope,
this.stravaRefreshToken,
this.stravaExpire) {
_setDefaultValues();
}
DbAthlete.fromMap(Map<String, dynamic> o, {bool setDefaultValues = true}) {
......@@ -843,6 +859,18 @@ class DbAthlete {
recordAggregationCount =
int.tryParse(o['recordAggregationCount'].toString());
}
if (o['stravaAccessToken'] != null) {
stravaAccessToken = o['stravaAccessToken'] as String;
}
if (o['stravaScope'] != null) {
stravaScope = o['stravaScope'] as String;
}
if (o['stravaRefreshToken'] != null) {
stravaRefreshToken = o['stravaRefreshToken'] as String;
}
if (o['stravaExpire'] != null) {
stravaExpire = int.tryParse(o['stravaExpire'].toString());
}
}
// FIELDS (DbAthlete)
int id;
......@@ -855,6 +883,10 @@ class DbAthlete {
String geoState;
int downloadInterval;
int recordAggregationCount;
String stravaAccessToken;
String stravaScope;
String stravaRefreshToken;
int stravaExpire;
BoolResult saveResult;
// end FIELDS (DbAthlete)
......@@ -1014,6 +1046,22 @@ class DbAthlete {
map['recordAggregationCount'] = recordAggregationCount;
}
if (stravaAccessToken != null) {
map['stravaAccessToken'] = stravaAccessToken;
}
if (stravaScope != null) {
map['stravaScope'] = stravaScope;
}
if (stravaRefreshToken != null) {
map['stravaRefreshToken'] = stravaRefreshToken;
}
if (stravaExpire != null) {
map['stravaExpire'] = stravaExpire;
}
return map;
}
......@@ -1061,6 +1109,22 @@ class DbAthlete {
map['recordAggregationCount'] = recordAggregationCount;
}
if (stravaAccessToken != null) {
map['stravaAccessToken'] = stravaAccessToken;
}
if (stravaScope != null) {
map['stravaScope'] = stravaScope;
}
if (stravaRefreshToken != null) {
map['stravaRefreshToken'] = stravaRefreshToken;
}
if (stravaExpire != null) {
map['stravaExpire'] = stravaExpire;
}
// COLLECTIONS (DbAthlete)
if (!forQuery) {
map['DbActivities'] = await getDbActivities().toMapList();
......@@ -1106,7 +1170,11 @@ class DbAthlete {
stravaId,
geoState,
downloadInterval,
recordAggregationCount
recordAggregationCount,
stravaAccessToken,
stravaScope,
stravaRefreshToken,
stravaExpire
];
}
......@@ -1121,7 +1189,11 @@ class DbAthlete {
stravaId,
geoState,
downloadInterval,
recordAggregationCount
recordAggregationCount,
stravaAccessToken,
stravaScope,
stravaRefreshToken,
stravaExpire
];
}
......@@ -1362,7 +1434,7 @@ class DbAthlete {
///
/// Returns a <List<BoolResult>>
Future<List<dynamic>> saveAll(List<DbAthlete> dbathletes) async {
// final results = _mnDbAthlete.saveAll('INSERT OR REPLACE INTO athletes (id,state, firstName, lastName, stravaUsername, photoPath, stravaId, geoState, downloadInterval, recordAggregationCount) VALUES (?,?,?,?,?,?,?,?,?,?)',dbathletes);
// final results = _mnDbAthlete.saveAll('INSERT OR REPLACE INTO athletes (id,state, firstName, lastName, stravaUsername, photoPath, stravaId, geoState, downloadInterval, recordAggregationCount, stravaAccessToken, stravaScope, stravaRefreshToken, stravaExpire) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)',dbathletes);
// return results; removed in sqfentity_gen 1.3.0+6
DbEncrateia().batchStart();
for (final obj in dbathletes) {
......@@ -1377,7 +1449,7 @@ class DbAthlete {
Future<int> upsert() async {
try {
if (await _mnDbAthlete.rawInsert(
'INSERT OR REPLACE INTO athletes (id,state, firstName, lastName, stravaUsername, photoPath, stravaId, geoState, downloadInterval, recordAggregationCount) VALUES (?,?,?,?,?,?,?,?,?,?)',
'INSERT OR REPLACE INTO athletes (id,state, firstName, lastName, stravaUsername, photoPath, stravaId, geoState, downloadInterval, recordAggregationCount, stravaAccessToken, stravaScope, stravaRefreshToken, stravaExpire) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
[
id,
state,
......@@ -1388,7 +1460,11 @@ class DbAthlete {
stravaId,
geoState,
downloadInterval,
recordAggregationCount
recordAggregationCount,
stravaAccessToken,
stravaScope,
stravaRefreshToken,
stravaExpire
]) ==
1) {
saveResult = BoolResult(
......@@ -1414,7 +1490,7 @@ class DbAthlete {
/// Returns a BoolCommitResult
Future<BoolCommitResult> upsertAll(List<DbAthlete> dbathletes) async {
final results = await _mnDbAthlete.rawInsertAll(
'INSERT OR REPLACE INTO athletes (id,state, firstName, lastName, stravaUsername, photoPath, stravaId, geoState, downloadInterval, recordAggregationCount) VALUES (?,?,?,?,?,?,?,?,?,?)',
'INSERT OR REPLACE INTO athletes (id,state, firstName, lastName, stravaUsername, photoPath, stravaId, geoState, downloadInterval, recordAggregationCount, stravaAccessToken, stravaScope, stravaRefreshToken, stravaExpire) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
dbathletes);
return results;
}
......@@ -1957,6 +2033,29 @@ class DbAthleteFilterBuilder extends SearchCriteria {
_recordAggregationCount, 'recordAggregationCount', DbType.integer);
}
DbAthleteField _stravaAccessToken;
DbAthleteField get stravaAccessToken {
return _stravaAccessToken =
setField(_stravaAccessToken, 'stravaAccessToken', DbType.text);
}
DbAthleteField _stravaScope;
DbAthleteField get stravaScope {
return _stravaScope = setField(_stravaScope, 'stravaScope', DbType.text);
}
DbAthleteField _stravaRefreshToken;
DbAthleteField get stravaRefreshToken {
return _stravaRefreshToken =
setField(_stravaRefreshToken, 'stravaRefreshToken', DbType.text);
}
DbAthleteField _stravaExpire;
DbAthleteField get stravaExpire {
return _stravaExpire =
setField(_stravaExpire, 'stravaExpire', DbType.integer);
}
bool _getIsDeleted;
void _buildParameters() {
......@@ -2414,6 +2513,32 @@ class DbAthleteFields {
SqlSyntax.setField(
_fRecordAggregationCount, 'recordAggregationCount', DbType.integer);
}
static TableField _fStravaAccessToken;
static TableField get stravaAccessToken {
return _fStravaAccessToken = _fStravaAccessToken ??
SqlSyntax.setField(
_fStravaAccessToken, 'stravaAccessToken', DbType.text);
}
static TableField _fStravaScope;
static TableField get stravaScope {
return _fStravaScope = _fStravaScope ??
SqlSyntax.setField(_fStravaScope, 'stravaScope', DbType.text);
}
static TableField _fStravaRefreshToken;
static TableField get stravaRefreshToken {
return _fStravaRefreshToken = _fStravaRefreshToken ??
SqlSyntax.setField(
_fStravaRefreshToken, 'stravaRefreshToken', DbType.text);
}
static TableField _fStravaExpire;
static TableField get stravaExpire {
return _fStravaExpire = _fStravaExpire ??
SqlSyntax.setField(_fStravaExpire, 'stravaExpire', DbType.integer);
}
}
// endregion DbAthleteFields
......
import 'dart:io';
import 'package:encrateia/models/power_zone_schema.dart';
import 'package:encrateia/models/strava_token.dart';
import 'package:encrateia/models/tag_group.dart';
import 'package:encrateia/model/model.dart'
show
......@@ -34,14 +35,22 @@ class Athlete {
String get photoPath => _db.photoPath;
String get state => _db.state;
String get stravaUsername => _db.stravaUsername;
String get stravaAccessToken => _db.stravaAccessToken;
String get stravaScope => _db.stravaScope;
String get stravaRefreshToken => _db.stravaRefreshToken;
int get downloadInterval => _db.downloadInterval;
int get recordAggregationCount => _db.recordAggregationCount;
int get stravaExpire => _db.stravaExpire;
int get stravaId => _db.stravaId;
set downloadInterval(int value) => _db.downloadInterval = value;
set firstName(String value) => _db.firstName = value;
set lastName(String value) => _db.lastName = value;
set recordAggregationCount(int value) => _db.recordAggregationCount = value;
set stravaAccessToken(String value) => _db.stravaAccessToken = value;
set stravaScope(String value) => _db.stravaScope = value;
set stravaRefreshToken(String value) => _db.stravaRefreshToken = value;
set stravaExpire(int value) => _db.stravaExpire = value;
@override
String toString() => '< Athlete | $firstName $lastName | $stravaId >';
......@@ -95,6 +104,12 @@ class Athlete {
password = await storage.read(key: 'password-$stravaId');
}
Future<void> loadStravaToken() async =>
await StravaToken.loadTokenData(athlete: this);
Future<void> persistStravaToken() async =>
await StravaToken.persistTokenData(athlete: this);
static Future<List<Athlete>> all() async {
final List<DbAthlete> dbAthleteList = await DbAthlete().select().toList();
return dbAthleteList.map(Athlete.exDb).toList();
......
import 'package:strava_flutter/globals.dart' as globals;
import 'package:shared_preferences/shared_preferences.dart';
import 'athlete.dart';
class StravaToken {
static Future<void> persistTokenData({Athlete athlete}) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
athlete
..stravaAccessToken = prefs.getString('strava_accessToken')
..stravaExpire = prefs.getInt('strava_expire')
..stravaScope = prefs.getString('strava_scope')
..stravaRefreshToken = prefs.getString('strava_refreshToken');
await athlete.save();
}
static Future<void> loadTokenData({Athlete athlete}) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
await prefs.setString('strava_accessToken', athlete.stravaAccessToken);
await prefs.setInt('strava_expire', athlete.stravaExpire);
await prefs.setString('strava_scope', athlete.stravaScope);
await prefs.setString('strava_refreshToken', athlete.stravaRefreshToken);
globals.token
..accessToken = athlete.stravaAccessToken
..scope = athlete.stravaScope
..expiresAt = athlete.stravaExpire
..refreshToken = athlete.stravaRefreshToken;
}
}
......@@ -49,6 +49,7 @@ class _DashboardState extends State<Dashboard> {
title: Text('${athlete.firstName} ${athlete.lastName}'),
onTap: () async {
await athlete.readCredentials();
await athlete.loadStravaToken();
await Navigator.push(
context,
MaterialPageRoute<BuildContext>(
......@@ -56,7 +57,8 @@ class _DashboardState extends State<Dashboard> {
ShowAthleteScreen(athlete: athlete),
),
);
getData();
await athlete.persistStravaToken();
await getData();
},
),
),
......@@ -80,7 +82,7 @@ class _DashboardState extends State<Dashboard> {
const OnboardingCreateUserScreen(),
),
);
getData();
await getData();
},
),
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment