Class LocalLoginServiceImpl
- Namespace
- adas_core.LocalLogin
- Assembly
- adas-core.LocalLogin.dll
Service implementation for local login functionality. This service handles user authentication using a local repository and authority service to manage user credentials and permissions.
public class LocalLoginServiceImpl : ILoginService
- Inheritance
-
LocalLoginServiceImpl
- Implements
- Inherited Members
- Extension Methods
Constructors
LocalLoginServiceImpl(ILocalLoginRepository, IAuthorityService)
Service implementation for local login functionality. This service handles user authentication using a local repository and authority service to manage user credentials and permissions.
public LocalLoginServiceImpl(ILocalLoginRepository localLoginRepository, IAuthorityService authorityService)
Parameters
localLoginRepositoryILocalLoginRepositoryThe repository used to access local user data.
authorityServiceIAuthorityServiceThe service used to manage user authorities and permissions.
Properties
AllowPassword
Indicates whether password-based login is allowed for this service. For local login, this is always true.
public bool AllowPassword { get; }
Property Value
Method
Indicates the login method used by this service, which is local login in this case.
public UserEnum.LoginMethod Method { get; }
Property Value
Methods
Authenticate(string, string)
Authenticates a user based on the provided username and password. This method is similar to the Login method but does not throw exceptions for invalid credentials. Instead, it returns an empty User object if authentication fails. This can be useful in scenarios where you want to check credentials without throwing exceptions.
public Task<User> Authenticate(string username, string password)
Parameters
usernamestringThe username of the user to authenticate.
passwordstringThe password of the user to authenticate.
Returns
GetAllUsers()
Retrieves a list of all users from the local repository. This method queries the repository for all user records and returns them as a list. If there are no users in the repository, it returns an empty list.
public Task<List<User>> GetAllUsers()
Returns
GetByEmail(string)
Retrieves a user by their email address. This method queries the local repository for a user with the specified email and returns the user object if found. If no user is found with the given email, it returns null.
public Task<User?> GetByEmail(string email)
Parameters
emailstringThe email address of the user to retrieve.
Returns
GetById(ObjectId)
Retrieves a user by their unique identifier (ObjectId). This method queries the local repository for a user with the specified ID and returns the user object if found. If no user is found with the given ID, it returns null.
public Task<User?> GetById(ObjectId id)
Parameters
idObjectIdThe unique identifier of the user to retrieve.
Returns
GetByUsername(string)
Retrieves a user by their username. This method queries the local repository for a user with the specified username and returns the user object if found. If no user is found with the given username, it returns null.
public Task<User?> GetByUsername(string username)
Parameters
usernamestring
Returns
Login(HttpContext)
Authenticates a user based on the provided HTTP context. This method is not implemented for local login and will throw a LoginServicesException if called.
public Task<User> Login(HttpContext context)
Parameters
contextHttpContextThe HTTP context used for authentication.
Returns
Exceptions
- LoginServicesException
Thrown when this method is called, as it is not implemented for local login.
Login(string, string)
Authenticates a user based on the provided username and password. It retrieves the user from the local repository, verifies the password, and if successful, retrieves the user's authorities before returning the user object. If authentication fails, it throws an UnauthorizedException with an appropriate error message.
public Task<User> Login(string username, string password)
Parameters
usernamestringThe username of the user to authenticate.
passwordstringThe password of the user to authenticate.
Returns
Exceptions
- UnauthorizedException
Thrown when the username or password is invalid.