add: adding blank files refactor contracts.dart to auth.dart

This commit is contained in:
Patrick Stewart 2024-06-15 08:00:29 -07:00
parent c900303ee8
commit cf208dc7c1
136 changed files with 298 additions and 8 deletions

View file

@ -0,0 +1,21 @@
/// Support for doing something awesome.
///
/// More dartdocs go here.
library;
// Auth Contracts
export 'src/auth/access/authorizable.dart';
export 'src/auth/access/gate.dart';
export 'src/auth/middleware/authenticates_request.dart';
export 'src/auth/authenticatable.dart';
export 'src/auth/can_reset_password.dart';
export 'src/auth/factory.dart';
export 'src/auth/guard.dart';
export 'src/auth/must_verify_email.dart';
export 'src/auth/password_broker_factory.dart';
export 'src/auth/password_broker.dart';
export 'src/auth/stateful_guard.dart';
export 'src/auth/supports_basic_auth.dart';
export 'src/auth/user_provider.dart';
// TODO: Export any libraries intended for clients of this package.

View file

@ -1,8 +0,0 @@
/// Support for doing something awesome.
///
/// More dartdocs go here.
library;
// export 'src/fabric_contracts_base.dart';
// TODO: Export any libraries intended for clients of this package.

View file

@ -0,0 +1,37 @@
abstract class Authenticatable {
/// Get the name of the unique identifier for the user.
///
/// @return string
String getAuthIdentifierName();
/// Get the unique identifier for the user.
///
/// @return dynamic
dynamic getAuthIdentifier();
/// Get the name of the password attribute for the user.
///
/// @return string
String getAuthPasswordName();
/// Get the password for the user.
///
/// @return string
String getAuthPassword();
/// Get the token value for the "remember me" session.
///
/// @return string
String getRememberToken();
/// Set the token value for the "remember me" session.
///
/// @param string value
/// @return void
void setRememberToken(String value);
/// Get the column name for the "remember me" token.
///
/// @return string
String getRememberTokenName();
}

View file

@ -0,0 +1,12 @@
abstract class CanResetPassword {
/// Get the e-mail address where password reset links are sent.
///
/// @return string
String getEmailForPasswordReset();
/// Send the password reset notification.
///
/// @param string token
/// @return void
void sendPasswordResetNotification(String token);
}

View file

@ -0,0 +1,16 @@
//import 'package:your_project_path/contracts/auth/guard.dart';
//import 'package:your_project_path/contracts/auth/stateful_guard.dart';
import 'package:fabric_contracts/auth.dart';
abstract class Factory {
/// Get a guard instance by name.
///
/// @param [name] The name of the guard instance to retrieve.
/// @return An instance of [Guard] or [StatefulGuard].
Guard guard(String? name);
/// Set the default guard the factory should serve.
///
/// @param [name] The name of the default guard.
void shouldUse(String name);
}

View file

@ -0,0 +1,43 @@
import 'authenticatable.dart';
abstract class Guard {
/// Determine if the current user is authenticated.
///
/// @return bool
bool check();
/// Determine if the current user is a guest.
///
/// @return bool
bool guest();
/// Get the currently authenticated user.
///
/// @return Authenticatable|null
Authenticatable? user();
/// Get the ID for the currently authenticated user.
///
/// @return int|string|null
dynamic id();
/// Validate a user's credentials.
///
/// @param Map<String, dynamic> credentials
/// @return bool
bool validate(Map<String, dynamic> credentials);
/// Determine if the guard has a user instance.
///
/// @return bool
bool hasUser();
/// Set the current user.
///
/// @param Authenticatable user
/// @return Guard
Guard setUser(Authenticatable user);
}
//abstract class Authenticatable {
// String getIdentifier();
//}

View file

@ -0,0 +1,21 @@
abstract class MustVerifyEmail {
/// Determine if the user has verified their email address.
///
/// @return bool
bool hasVerifiedEmail();
/// Mark the given user's email as verified.
///
/// @return bool
bool markEmailAsVerified();
/// Send the email verification notification.
///
/// @return void
void sendEmailVerificationNotification();
/// Get the email address that should be used for verification.
///
/// @return string
String getEmailForVerification();
}

View file

@ -0,0 +1,34 @@
import 'dart:async';
typedef Closure = FutureOr<dynamic> Function();
abstract class PasswordBroker {
/// Constant representing a successfully sent reminder.
static const String RESET_LINK_SENT = 'passwords.sent';
/// Constant representing a successfully reset password.
static const String PASSWORD_RESET = 'passwords.reset';
/// Constant representing the user not found response.
static const String INVALID_USER = 'passwords.user';
/// Constant representing an invalid token.
static const String INVALID_TOKEN = 'passwords.token';
/// Constant representing a throttled reset attempt.
static const String RESET_THROTTLED = 'passwords.throttled';
/// Send a password reset link to a user.
///
/// @param Map<String, dynamic> credentials
/// @param Closure? callback
/// @return Future<String>
Future<String> sendResetLink(Map<String, dynamic> credentials, [Closure? callback]);
/// Reset the password for the given token.
///
/// @param Map<String, dynamic> credentials
/// @param Closure callback
/// @return Future<dynamic>
Future<dynamic> reset(Map<String, dynamic> credentials, Closure callback);
}

View file

@ -0,0 +1,9 @@
import 'password_broker.dart';
abstract class PasswordBrokerFactory {
/// Get a password broker instance by name.
///
/// @param String? name
/// @return PasswordBroker
PasswordBroker broker([String? name]);
}

View file

@ -0,0 +1,44 @@
import 'authenticatable.dart';
import 'guard.dart';
abstract class StatefulGuard extends Guard {
/// Attempt to authenticate a user using the given credentials.
///
/// [credentials] are the user's credentials.
/// [remember] indicates if the user should be remembered.
/// Returns true if authentication was successful.
Future<bool> attempt(Map<String, dynamic> credentials, {bool remember = false});
/// Log a user into the application without sessions or cookies.
///
/// [credentials] are the user's credentials.
/// Returns true if authentication was successful.
Future<bool> once(Map<String, dynamic> credentials);
/// Log a user into the application.
///
/// [user] is the user to log in.
/// [remember] indicates if the user should be remembered.
void login(Authenticatable user, {bool remember = false});
/// Log the given user ID into the application.
///
/// [id] is the ID of the user.
/// [remember] indicates if the user should be remembered.
/// Returns the authenticated user or false if authentication failed.
Future<Authenticatable?> loginUsingId(dynamic id, {bool remember = false});
/// Log the given user ID into the application without sessions or cookies.
///
/// [id] is the ID of the user.
/// Returns the authenticated user or false if authentication failed.
Future<Authenticatable?> onceUsingId(dynamic id);
/// Determine if the user was authenticated via "remember me" cookie.
///
/// Returns true if authenticated via "remember me" cookie.
bool viaRemember();
/// Log the user out of the application.
void logout();
}

View file

@ -0,0 +1,17 @@
import 'package:symfony/http_foundation.dart';
abstract class SupportsBasicAuth {
/// Attempt to authenticate using HTTP Basic Auth.
///
/// @param String field
/// @param Map<String, dynamic> extraConditions
/// @return Response|null
Response? basic({String field = 'email', Map<String, dynamic> extraConditions = const {}});
/// Perform a stateless HTTP Basic login attempt.
///
/// @param String field
/// @param Map<String, dynamic> extraConditions
/// @return Response|null
Response? onceBasic({String field = 'email', Map<String, dynamic> extraConditions = const {}});
}

View file

@ -0,0 +1,44 @@
import 'authenticatable.dart';
abstract class UserProvider {
/// Retrieve a user by their unique identifier.
///
/// @param dynamic identifier
/// @return Authenticatable|null
Future<Authenticatable?> retrieveById(dynamic identifier);
/// Retrieve a user by their unique identifier and "remember me" token.
///
/// @param dynamic identifier
/// @param String token
/// @return Authenticatable|null
Future<Authenticatable?> retrieveByToken(dynamic identifier, String token);
/// Update the "remember me" token for the given user in storage.
///
/// @param Authenticatable user
/// @param String token
/// @return void
Future<void> updateRememberToken(Authenticatable user, String token);
/// Retrieve a user by the given credentials.
///
/// @param Map<String, dynamic> credentials
/// @return Authenticatable|null
Future<Authenticatable?> retrieveByCredentials(Map<String, dynamic> credentials);
/// Validate a user against the given credentials.
///
/// @param Authenticatable user
/// @param Map<String, dynamic> credentials
/// @return bool
Future<bool> validateCredentials(Authenticatable user, Map<String, dynamic> credentials);
/// Rehash the user's password if required and supported.
///
/// @param Authenticatable user
/// @param Map<String, dynamic> credentials
/// @param bool force
/// @return void
Future<void> rehashPasswordIfRequired(Authenticatable user, Map<String, dynamic> credentials, {bool force = false});
}

View file

View file

View file

View file

View file

Some files were not shown because too many files have changed in this diff Show more