implementation attempt for multi user strava auth using a time stamp based uuid
parent
51aa5ae356
commit
8b3312ce6a
|
@ -26,6 +26,7 @@ const SqfEntityTable tableAthlete = SqfEntityTable(
|
|||
SqfEntityField('geoState', DbType.text),
|
||||
SqfEntityField('downloadInterval', DbType.integer),
|
||||
SqfEntityField('recordAggregationCount', DbType.integer),
|
||||
SqfEntityField('uuid', DbType.text),
|
||||
],
|
||||
);
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ class TableDbAthlete extends SqfEntityTableBase {
|
|||
SqfEntityFieldBase('geoState', DbType.text),
|
||||
SqfEntityFieldBase('downloadInterval', DbType.integer),
|
||||
SqfEntityFieldBase('recordAggregationCount', DbType.integer),
|
||||
SqfEntityFieldBase('uuid', DbType.text),
|
||||
];
|
||||
super.init();
|
||||
}
|
||||
|
@ -778,7 +779,8 @@ class DbAthlete extends TableBase {
|
|||
this.stravaId,
|
||||
this.geoState,
|
||||
this.downloadInterval,
|
||||
this.recordAggregationCount}) {
|
||||
this.recordAggregationCount,
|
||||
this.uuid}) {
|
||||
_setDefaultValues();
|
||||
softDeleteActivated = false;
|
||||
}
|
||||
|
@ -791,7 +793,8 @@ class DbAthlete extends TableBase {
|
|||
this.stravaId,
|
||||
this.geoState,
|
||||
this.downloadInterval,
|
||||
this.recordAggregationCount) {
|
||||
this.recordAggregationCount,
|
||||
this.uuid) {
|
||||
_setDefaultValues();
|
||||
}
|
||||
DbAthlete.withId(
|
||||
|
@ -804,7 +807,8 @@ class DbAthlete extends TableBase {
|
|||
this.stravaId,
|
||||
this.geoState,
|
||||
this.downloadInterval,
|
||||
this.recordAggregationCount) {
|
||||
this.recordAggregationCount,
|
||||
this.uuid) {
|
||||
_setDefaultValues();
|
||||
}
|
||||
// fromMap v2.0
|
||||
|
@ -841,6 +845,9 @@ class DbAthlete extends TableBase {
|
|||
recordAggregationCount =
|
||||
int.tryParse(o['recordAggregationCount'].toString());
|
||||
}
|
||||
if (o['uuid'] != null) {
|
||||
uuid = o['uuid'].toString();
|
||||
}
|
||||
}
|
||||
// FIELDS (DbAthlete)
|
||||
int? id;
|
||||
|
@ -853,6 +860,7 @@ class DbAthlete extends TableBase {
|
|||
String? geoState;
|
||||
int? downloadInterval;
|
||||
int? recordAggregationCount;
|
||||
String? uuid;
|
||||
|
||||
// end FIELDS (DbAthlete)
|
||||
|
||||
|
@ -1001,6 +1009,9 @@ class DbAthlete extends TableBase {
|
|||
if (recordAggregationCount != null || !forView) {
|
||||
map['recordAggregationCount'] = recordAggregationCount;
|
||||
}
|
||||
if (uuid != null || !forView) {
|
||||
map['uuid'] = uuid;
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
@ -1039,6 +1050,9 @@ class DbAthlete extends TableBase {
|
|||
if (recordAggregationCount != null || !forView) {
|
||||
map['recordAggregationCount'] = recordAggregationCount;
|
||||
}
|
||||
if (uuid != null || !forView) {
|
||||
map['uuid'] = uuid;
|
||||
}
|
||||
|
||||
// COLLECTIONS (DbAthlete)
|
||||
if (!forQuery) {
|
||||
|
@ -1088,7 +1102,8 @@ class DbAthlete extends TableBase {
|
|||
stravaId,
|
||||
geoState,
|
||||
downloadInterval,
|
||||
recordAggregationCount
|
||||
recordAggregationCount,
|
||||
uuid
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -1104,7 +1119,8 @@ class DbAthlete extends TableBase {
|
|||
stravaId,
|
||||
geoState,
|
||||
downloadInterval,
|
||||
recordAggregationCount
|
||||
recordAggregationCount,
|
||||
uuid
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -1394,7 +1410,7 @@ class DbAthlete extends TableBase {
|
|||
Future<int?> upsert({bool ignoreBatch = true}) async {
|
||||
try {
|
||||
final result = 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, uuid) VALUES (?,?,?,?,?,?,?,?,?,?,?)',
|
||||
[
|
||||
id,
|
||||
state,
|
||||
|
@ -1405,7 +1421,8 @@ class DbAthlete extends TableBase {
|
|||
stravaId,
|
||||
geoState,
|
||||
downloadInterval,
|
||||
recordAggregationCount
|
||||
recordAggregationCount,
|
||||
uuid
|
||||
],
|
||||
ignoreBatch);
|
||||
if (result! > 0) {
|
||||
|
@ -1431,7 +1448,7 @@ class DbAthlete extends TableBase {
|
|||
@override
|
||||
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, uuid) VALUES (?,?,?,?,?,?,?,?,?,?,?)',
|
||||
dbathletes);
|
||||
return results;
|
||||
}
|
||||
|
@ -1797,6 +1814,11 @@ class DbAthleteFilterBuilder extends ConjunctionBase {
|
|||
_recordAggregationCount, 'recordAggregationCount', DbType.integer);
|
||||
}
|
||||
|
||||
DbAthleteField? _uuid;
|
||||
DbAthleteField get uuid {
|
||||
return _uuid = _setField(_uuid, 'uuid', DbType.text);
|
||||
}
|
||||
|
||||
/// Deletes List<DbAthlete> bulk by query
|
||||
///
|
||||
/// <returns>BoolResult res.success= true (Deleted), false (Could not be deleted)
|
||||
|
@ -2206,6 +2228,11 @@ class DbAthleteFields {
|
|||
SqlSyntax.setField(
|
||||
_fRecordAggregationCount, 'recordAggregationCount', DbType.integer);
|
||||
}
|
||||
|
||||
static TableField? _fUuid;
|
||||
static TableField get uuid {
|
||||
return _fUuid = _fUuid ?? SqlSyntax.setField(_fUuid, 'uuid', DbType.text);
|
||||
}
|
||||
}
|
||||
// endregion DbAthleteFields
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:sqfentity_gen/sqfentity_gen.dart' show BoolResult;
|
||||
import 'package:strava_flutter/domain/model/model_detailed_athlete.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
import '/model/model.dart'
|
||||
show
|
||||
|
@ -28,7 +29,7 @@ class Athlete {
|
|||
String? email;
|
||||
String? password;
|
||||
|
||||
DbAthlete _db = DbAthlete();
|
||||
DbAthlete _db = DbAthlete(uuid: const Uuid().v1());
|
||||
List<int?> filters = <int?>[];
|
||||
|
||||
int? get id => _db.id;
|
||||
|
@ -38,6 +39,7 @@ class Athlete {
|
|||
String? get photoPath => _db.photoPath;
|
||||
String? get state => _db.state;
|
||||
String? get stravaUsername => _db.stravaUsername;
|
||||
String get uuid => _db.uuid!;
|
||||
int? get downloadInterval => _db.downloadInterval;
|
||||
int? get recordAggregationCount => _db.recordAggregationCount;
|
||||
int? get stravaId => _db.stravaId;
|
||||
|
@ -46,6 +48,7 @@ class Athlete {
|
|||
set firstName(String? value) => _db.firstName = value;
|
||||
set lastName(String? value) => _db.lastName = value;
|
||||
set recordAggregationCount(int? value) => _db.recordAggregationCount = value;
|
||||
set uuid(String value) => _db.uuid = value;
|
||||
|
||||
@override
|
||||
String toString() => '< Athlete | $firstName $lastName | $stravaId >';
|
||||
|
|
|
@ -8,9 +8,9 @@ import '/secrets/secrets.dart';
|
|||
import '/utils/my_color.dart';
|
||||
|
||||
class StravaGetUser extends StatefulWidget {
|
||||
const StravaGetUser({Key? key, this.athlete}) : super(key: key);
|
||||
const StravaGetUser({Key? key, required this.athlete}) : super(key: key);
|
||||
|
||||
final Athlete? athlete;
|
||||
final Athlete athlete;
|
||||
|
||||
@override
|
||||
_StravaGetUserState createState() => _StravaGetUserState();
|
||||
|
@ -35,15 +35,15 @@ class _StravaGetUserState extends State<StravaGetUser> {
|
|||
body: SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(20),
|
||||
child: Text(widget.athlete!.stateText),
|
||||
child: Text(widget.athlete.stateText),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> loginToStrava() async {
|
||||
final StravaClient stravaClient =
|
||||
StravaClient(clientId: clientId, secret: secret);
|
||||
Future<void> loginToStrava({required Athlete athlete}) async {
|
||||
final StravaClient stravaClient = StravaClient(
|
||||
clientId: clientId, secret: secret, applicationName: athlete.uuid);
|
||||
|
||||
await stravaClient.authentication
|
||||
.authenticate(scopes: <AuthenticationScope>[
|
||||
|
@ -54,15 +54,15 @@ class _StravaGetUserState extends State<StravaGetUser> {
|
|||
|
||||
final DetailedAthlete stravaAthlete =
|
||||
await stravaClient.athletes.getAuthenticatedAthlete();
|
||||
await widget.athlete!.updateFromStravaAthlete(stravaAthlete);
|
||||
await widget.athlete.updateFromStravaAthlete(stravaAthlete);
|
||||
}
|
||||
|
||||
Future<void> getData() async {
|
||||
if (widget.athlete!.firstName == null) {
|
||||
await loginToStrava();
|
||||
if (widget.athlete.firstName == null) {
|
||||
await loginToStrava(athlete: widget.athlete);
|
||||
setState(() {});
|
||||
}
|
||||
if (widget.athlete!.state == 'fromStrava') {
|
||||
if (widget.athlete.state == 'fromStrava') {
|
||||
Navigator.of(context).pop();
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue