// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
namespace Microsoft.AspNetCore.Identity
{
///
/// Represents the result of a sign-in operation.
///
public class SignInResult
{
private static readonly SignInResult _success = new SignInResult { Succeeded = true };
private static readonly SignInResult _failed = new SignInResult();
private static readonly SignInResult _lockedOut = new SignInResult { IsLockedOut = true };
private static readonly SignInResult _notAllowed = new SignInResult { IsNotAllowed = true };
private static readonly SignInResult _twoFactorRequired = new SignInResult { RequiresTwoFactor = true };
///
/// Returns a flag indication whether the sign-in was successful.
///
/// True if the sign-in was successful, otherwise false.
public bool Succeeded { get; protected set; }
///
/// Returns a flag indication whether the user attempting to sign-in is locked out.
///
/// True if the user attempting to sign-in is locked out, otherwise false.
public bool IsLockedOut { get; protected set; }
///
/// Returns a flag indication whether the user attempting to sign-in is not allowed to sign-in.
///
/// True if the user attempting to sign-in is not allowed to sign-in, otherwise false.
public bool IsNotAllowed { get; protected set; }
///
/// Returns a flag indication whether the user attempting to sign-in requires two factor authentication.
///
/// True if the user attempting to sign-in requires two factor authentication, otherwise false.
public bool RequiresTwoFactor { get; protected set; }
///
/// Returns a that represents a successful sign-in.
///
/// A that represents a successful sign-in.
public static SignInResult Success => _success;
///
/// Returns a that represents a failed sign-in.
///
/// A that represents a failed sign-in.
public static SignInResult Failed => _failed;
///
/// Returns a that represents a sign-in attempt that failed because
/// the user was logged out.
///
/// A that represents sign-in attempt that failed due to the
/// user being locked out.
public static SignInResult LockedOut => _lockedOut;
///
/// Returns a that represents a sign-in attempt that failed because
/// the user is not allowed to sign-in.
///
/// A that represents sign-in attempt that failed due to the
/// user is not allowed to sign-in.
public static SignInResult NotAllowed => _notAllowed;
///
/// Returns a that represents a sign-in attempt that needs two-factor
/// authentication.
///
/// A that represents sign-in attempt that needs two-factor
/// authentication.
public static SignInResult TwoFactorRequired => _twoFactorRequired;
///
/// Converts the value of the current object to its equivalent string representation.
///
/// A string representation of value of the current object.
public override string ToString()
{
return IsLockedOut ? "Lockedout" :
IsNotAllowed ? "NotAllowed" :
RequiresTwoFactor ? "RequiresTwoFactor" :
Succeeded ? "Succeeded" : "Failed";
}
}
}