mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-11-27 14:44:56 +00:00
auth UI and Api
This commit is contained in:
@ -1,23 +0,0 @@
|
||||
class LoginWithEmailModel {
|
||||
final String email;
|
||||
final String password;
|
||||
|
||||
LoginWithEmailModel({
|
||||
required this.email,
|
||||
required this.password,
|
||||
});
|
||||
|
||||
factory LoginWithEmailModel.fromJson(Map<String, dynamic> json) {
|
||||
return LoginWithEmailModel(
|
||||
email: json['email'],
|
||||
password: json['password'],
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'email': email,
|
||||
'password': password,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
class SignUpModel {
|
||||
final String email;
|
||||
final String password;
|
||||
final String firstName;
|
||||
final String lastName;
|
||||
|
||||
SignUpModel(
|
||||
{required this.email,
|
||||
required this.password,
|
||||
required this.firstName,
|
||||
required this.lastName});
|
||||
|
||||
factory SignUpModel.fromJson(Map<String, dynamic> json) {
|
||||
return SignUpModel(
|
||||
email: json['email'],
|
||||
password: json['password'],
|
||||
firstName: json['firstName'],
|
||||
lastName: json['lastName']);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'email': email,
|
||||
'password': password,
|
||||
'firstName': firstName,
|
||||
'lastName': lastName,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,69 +0,0 @@
|
||||
import 'dart:convert';
|
||||
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
||||
import 'package:syncrow_web/utils/helpers/decodeBase64.dart';
|
||||
|
||||
class Token {
|
||||
static const String loginAccessTokenKey = 'accessToken';
|
||||
static const String loginRefreshTokenKey = 'refreshToken';
|
||||
final String accessToken;
|
||||
final String refreshToken;
|
||||
final String sessionId;
|
||||
final int iat;
|
||||
final int exp;
|
||||
|
||||
Token.emptyConstructor()
|
||||
: accessToken = '',
|
||||
refreshToken = '',
|
||||
sessionId = '',
|
||||
iat = 0,
|
||||
exp = 0;
|
||||
|
||||
bool get accessTokenIsNotEmpty => accessToken.isNotEmpty;
|
||||
|
||||
bool get refreshTokenIsNotEmpty => refreshToken.isNotEmpty;
|
||||
|
||||
bool get isNotEmpty => accessToken.isNotEmpty && refreshToken.isNotEmpty;
|
||||
|
||||
Token(
|
||||
this.accessToken,
|
||||
this.refreshToken,
|
||||
this.sessionId,
|
||||
this.iat,
|
||||
this.exp,
|
||||
);
|
||||
|
||||
Token.refreshToken(this.refreshToken)
|
||||
: accessToken = '',
|
||||
sessionId = '',
|
||||
iat = 0,
|
||||
exp = 0;
|
||||
|
||||
factory Token.fromJson(Map<String, dynamic> json) {
|
||||
//save token to secure storage
|
||||
var storage = const FlutterSecureStorage();
|
||||
storage.write(
|
||||
key: loginAccessTokenKey,
|
||||
value: json[loginAccessTokenKey] ?? '');
|
||||
storage.write(
|
||||
key: loginRefreshTokenKey,
|
||||
value: json[loginRefreshTokenKey] ?? '');
|
||||
//create token object ?
|
||||
return Token(
|
||||
json[loginAccessTokenKey] ?? '',
|
||||
json[loginRefreshTokenKey] ?? '', '', 0, 0);
|
||||
}
|
||||
|
||||
Map<String, String> refreshTokenToJson() =>
|
||||
{loginRefreshTokenKey: refreshToken};
|
||||
|
||||
Map<String, String> accessTokenToJson() => {loginAccessTokenKey: accessToken};
|
||||
|
||||
static Map<String, dynamic> decodeToken(String accessToken) {
|
||||
final parts = accessToken.split('.');
|
||||
if (parts.length != 3) {
|
||||
throw Exception('invalid access token');
|
||||
}
|
||||
final payload = decodeBase64(parts[1]);
|
||||
return json.decode(payload);
|
||||
}
|
||||
}
|
||||
@ -1,66 +0,0 @@
|
||||
import 'package:syncrow_web/pages/auth/model/token.dart';
|
||||
|
||||
class UserModel {
|
||||
static String userUuidKey = 'userUuid';
|
||||
final String? uuid;
|
||||
final String? email;
|
||||
final String? name;
|
||||
final String? photoUrl;
|
||||
|
||||
final String? phoneNumber;
|
||||
|
||||
final bool? isEmailVerified;
|
||||
|
||||
final bool? isAgreementAccepted;
|
||||
|
||||
UserModel({
|
||||
required this.uuid,
|
||||
required this.email,
|
||||
required this.name,
|
||||
required this.photoUrl,
|
||||
required this.phoneNumber,
|
||||
required this.isEmailVerified,
|
||||
required this.isAgreementAccepted,
|
||||
});
|
||||
|
||||
factory UserModel.fromJson(Map<String, dynamic> json) {
|
||||
return UserModel(
|
||||
uuid: json['id'],
|
||||
email: json['email'],
|
||||
name: json['name'],
|
||||
photoUrl: json['photoUrl'],
|
||||
phoneNumber: json['phoneNumber'],
|
||||
isEmailVerified: json['isEmailVerified'],
|
||||
isAgreementAccepted: json['isAgreementAccepted'],
|
||||
);
|
||||
}
|
||||
|
||||
//uuid to json
|
||||
|
||||
//from token
|
||||
factory UserModel.fromToken(Token token) {
|
||||
Map<String, dynamic> tempJson = Token.decodeToken(token.accessToken);
|
||||
|
||||
return UserModel(
|
||||
uuid: tempJson['uuid'].toString(),
|
||||
email: tempJson['email'],
|
||||
name: null,
|
||||
photoUrl: null,
|
||||
phoneNumber: null,
|
||||
isEmailVerified: null,
|
||||
isAgreementAccepted: null,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> toJson() {
|
||||
return {
|
||||
'id': uuid,
|
||||
'email': email,
|
||||
'name': name,
|
||||
'photoUrl': photoUrl,
|
||||
'phoneNumber': phoneNumber,
|
||||
'isEmailVerified': isEmailVerified,
|
||||
'isAgreementAccepted': isAgreementAccepted,
|
||||
};
|
||||
}
|
||||
}
|
||||
@ -1,27 +0,0 @@
|
||||
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