mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2026-10-25 06:17:55 +00:00
Initialized Auth pages for future work
Implemented Login functionality
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
|
||||
class Token {
|
||||
static const String loginAccessToken = 'access_token';
|
||||
static const String loginRefreshToken = 'refreshToken';
|
||||
|
||||
final String accessToken;
|
||||
final String refreshToken;
|
||||
|
||||
Token.emptyConstructor()
|
||||
: accessToken = '',
|
||||
refreshToken = '';
|
||||
|
||||
Token(
|
||||
this.accessToken,
|
||||
this.refreshToken,
|
||||
);
|
||||
|
||||
Token.refreshToken(this.refreshToken) : accessToken = '';
|
||||
|
||||
factory Token.fromJson(Map<String, dynamic> json) {
|
||||
//save token to secure storage
|
||||
var storage = const FlutterSecureStorage();
|
||||
storage.write(key: loginAccessToken, value: json[loginAccessToken] ?? '');
|
||||
|
||||
//create token object ?
|
||||
return Token(json[loginAccessToken] ?? '', json[loginRefreshToken] ?? '');
|
||||
}
|
||||
|
||||
Map<String, String> toJson() => {loginRefreshToken: refreshToken};
|
||||
}
|
||||
@@ -6,19 +6,26 @@ class UserModel {
|
||||
|
||||
final String? phoneNumber;
|
||||
|
||||
final bool? isAnonymous;
|
||||
|
||||
final bool? isEmailVerified;
|
||||
|
||||
final bool? isAgreementAccepted;
|
||||
|
||||
//token decoded with jwt
|
||||
//{
|
||||
// "email": "[email protected]",
|
||||
// "userId": 2,
|
||||
// "uuid": "e145438c-4c62-4535-a0f4-f77958f9f9f4",
|
||||
// "sessionId": "0409a7a1-6ef5-42c5-b3a1-1f15c639b301",
|
||||
// "iat": 1709711675,
|
||||
// "exp": 1709711975
|
||||
// }
|
||||
|
||||
UserModel({
|
||||
required this.id,
|
||||
required this.email,
|
||||
required this.name,
|
||||
required this.photoUrl,
|
||||
required this.phoneNumber,
|
||||
required this.isAnonymous,
|
||||
required this.isEmailVerified,
|
||||
required this.isAgreementAccepted,
|
||||
});
|
||||
@@ -30,12 +37,24 @@ class UserModel {
|
||||
name: json['name'],
|
||||
photoUrl: json['photoUrl'],
|
||||
phoneNumber: json['phoneNumber'],
|
||||
isAnonymous: json['isAnonymous'],
|
||||
isEmailVerified: json['isEmailVerified'],
|
||||
isAgreementAccepted: json['isAgreementAccepted'],
|
||||
);
|
||||
}
|
||||
|
||||
//from token
|
||||
factory UserModel.fromToken(Map<String, dynamic> json) {
|
||||
return UserModel(
|
||||
id: json['userId'].toString(),
|
||||
email: json['email'],
|
||||
name: null,
|
||||
photoUrl: null,
|
||||
phoneNumber: null,
|
||||
isEmailVerified: null,
|
||||
isAgreementAccepted: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': id,
|
||||
@@ -43,7 +62,6 @@ class UserModel {
|
||||
'name': name,
|
||||
'photoUrl': photoUrl,
|
||||
'phoneNumber': phoneNumber,
|
||||
'isAnonymous': isAnonymous,
|
||||
'isEmailVerified': isEmailVerified,
|
||||
'isAgreementAccepted': isAgreementAccepted,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
class VerifyPassCode {
|
||||
static const String verificationPhone = 'phone';
|
||||
static const String verificationPassCode = 'passCode';
|
||||
static const String verificationAgent = 'agent';
|
||||
static const String verificationDeviceId = 'deviceId';
|
||||
|
||||
final String phone;
|
||||
final String passCode;
|
||||
final String agent;
|
||||
final String deviceId;
|
||||
|
||||
VerifyPassCode(
|
||||
{required this.phone, required this.passCode, required this.agent, required this.deviceId});
|
||||
|
||||
factory VerifyPassCode.fromJson(Map<String, dynamic> json) => VerifyPassCode(
|
||||
phone: json[verificationPhone],
|
||||
passCode: json[verificationPassCode],
|
||||
agent: json[verificationAgent],
|
||||
deviceId: json[verificationDeviceId]);
|
||||
|
||||
Map<String, dynamic> toJson() => {
|
||||
verificationPhone: phone,
|
||||
verificationPassCode: passCode,
|
||||
verificationAgent: agent,
|
||||
verificationDeviceId: deviceId,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user