# 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
  object
  LocalLoginServiceImpl

Implements
  ILoginService

Inherited Members
  object.Equals(object)
  object.Equals(object, object)
  object.GetHashCode()
  object.GetType()
  object.MemberwiseClone()
  object.ReferenceEquals(object, object)
  object.ToString()

Extension Methods
  NumberUtils.IsNumber(object)
  NumberUtils.ToDouble(object)
  ObjectUtils.ToStr(object?)

## 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

`localLoginRepository` ILocalLoginRepository

  The repository used to access local user data.

`authorityService` IAuthorityService

  The 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

bool

### Method

Indicates the login method used by this service, which is local login in this case.

    public UserEnum.LoginMethod Method { get; }

#### Property Value

UserEnum.LoginMethod

## 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

`username` string

  The username of the user to authenticate.

`password` string

  The password of the user to authenticate.

#### Returns

Task<User>

  The authenticated user object, or an empty User object if authentication fails.

### 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

Task<List<User>>

  A list of all user objects, or an empty list if no users are found.

### 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

`email` string

  The email address of the user to retrieve.

#### Returns

Task<User>

  The user object if found, or null if no user is found with the given email.

### 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

`id` ObjectId

  The unique identifier of the user to retrieve.

#### Returns

Task<User>

  The user object if found, or null if no user is found with the given ID.

### 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

`username` string

#### Returns

Task<User>

### 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

`context` HttpContext

  The HTTP context used for authentication.

#### Returns

Task<User>

  A task representing the asynchronous operation.

#### 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

`username` string

  The username of the user to authenticate.

`password` string

  The password of the user to authenticate.

#### Returns

Task<User>

  The authenticated user object.

#### Exceptions

UnauthorizedException

  Thrown when the username or password is invalid.