login static method
Implementation
static Future<bool> login({
required String email,
required String password,
}) async {
try {
final authSessions = App().tryMake<List<AuthSession>>();
if (authSessions == null) return false;
final authSession = authSessions.firstWhereOrNull(
(session) => session.email == email,
);
if (authSession != null) {
authSession.lastActivity = DateTime.now();
return true;
} else {
final user = await Model.firstWhere<User>(field: "email", value: email);
if (user != null && Hasher.verifyPassword(password, user.password)) {
final newAuthSession = await Model.create<AuthSession>(
fromJson: {"email": user.email, "token": App.generateKey()},
);
if (newAuthSession == null) return false;
authSession?.lastActivity = DateTime.now();
authSessions.add(newAuthSession);
return true;
}
}
return false;
} catch (e) {
return false;
}
}