Merge pull request #22 from lithnet/issues/18
Add ReloadUserTiles method and update IsAutoLogon property
This commit is contained in:
@@ -169,23 +169,20 @@ namespace Lithnet.CredentialProvider
|
||||
|
||||
this.notifyOnTileCollectionChange = true;
|
||||
|
||||
var autoLogonTile = this.Tiles.FirstOrDefault(t => t.IsAutoLogon);
|
||||
var defaultTile = this.Tiles.FirstOrDefault(t => t.IsDefault);
|
||||
var defaultTile = this.DefaultTile;
|
||||
|
||||
uint defaultIndex = CREDENTIAL_PROVIDER_NO_DEFAULT;
|
||||
if (autoLogonTile != null)
|
||||
if (defaultTile != null)
|
||||
{
|
||||
defaultIndex = (uint)this.tiles.IndexOf(autoLogonTile);
|
||||
var index = this.tiles.IndexOf(defaultTile);
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
pdwDefault = (uint)index;
|
||||
pbAutoLogonWithDefault = this.DefaultTileAutoLogon ? 1 : 0;
|
||||
}
|
||||
else if (defaultTile != null)
|
||||
{
|
||||
defaultIndex = (uint)this.tiles.IndexOf(defaultTile);
|
||||
}
|
||||
|
||||
pdwCount = (uint)this.Tiles.Count;
|
||||
pdwDefault = defaultIndex;
|
||||
pbAutoLogonWithDefault = autoLogonTile == null ? 0 : 1;
|
||||
|
||||
this.logger.LogTrace($"GetCredentialCount returning pdwCount: {pdwCount}, pdwDefault: {pdwDefault}, pbAutoLogonWithDefault: {pbAutoLogonWithDefault}");
|
||||
|
||||
return HRESULT.S_OK;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Lithnet.CredentialProvider.Interop;
|
||||
@@ -115,6 +116,35 @@ namespace Lithnet.CredentialProvider
|
||||
/// </summary>
|
||||
public abstract bool ShouldIncludeGenericTile();
|
||||
|
||||
protected internal CredentialTile DefaultTile { get; set; }
|
||||
|
||||
protected internal bool DefaultTileAutoLogon { get; set; }
|
||||
|
||||
public void SetDefaultTile(CredentialTile tile, bool autoLogon)
|
||||
{
|
||||
if (this.DefaultTile == tile && this.DefaultTileAutoLogon == autoLogon)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.Tiles.Contains(tile))
|
||||
{
|
||||
throw new InvalidOperationException("The default tile must be one of the tiles provided by the credential provider");
|
||||
}
|
||||
|
||||
this.DefaultTile = tile;
|
||||
this.DefaultTileAutoLogon = autoLogon;
|
||||
this.ReloadUserTiles();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notifies LogonUI that one of more of the tile items has been modified, and should be reloaded
|
||||
/// </summary>
|
||||
public void ReloadUserTiles()
|
||||
{
|
||||
this.NotifyHostOfTileCollectionChange();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds additional user tiles to the collection, and notifies LogonUI that new tiles are available
|
||||
/// </summary>
|
||||
|
||||
@@ -66,8 +66,8 @@ namespace Lithnet.CredentialProvider
|
||||
{
|
||||
this.logger.LogTrace("SetSelected");
|
||||
this.IsSelected = true;
|
||||
pbAutoLogon = this.IsAutoLogon ? 1 : 0;
|
||||
this.OnSelected();
|
||||
pbAutoLogon = this.OnSelectedShouldAutoLogon() ? 1 : 0;
|
||||
return HRESULT.S_OK;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace Lithnet.CredentialProvider
|
||||
private protected readonly ICredentialProviderLogger logger;
|
||||
private protected ICredentialProviderCredentialEvents events;
|
||||
private protected ICredentialProviderCredentialEvents2 events2;
|
||||
|
||||
private protected ControlCollection controls;
|
||||
|
||||
protected CredentialTile(CredentialProviderBase credentialProvider)
|
||||
@@ -37,12 +36,18 @@ namespace Lithnet.CredentialProvider
|
||||
/// <summary>
|
||||
/// Gets a value that indicates if the user should be automatically logged on when the tile is selected. The tile must also have IsDefault set to true.
|
||||
/// </summary>
|
||||
public bool IsAutoLogon { get; set; }
|
||||
public bool IsDefaultTileAutoLogon
|
||||
{
|
||||
get => this.CredentialProvider.DefaultTile == this && this.CredentialProvider.DefaultTileAutoLogon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating if this should be the default time
|
||||
/// Gets a value indicating if this should be the default tile
|
||||
/// </summary>
|
||||
public bool IsDefault { get; set; }
|
||||
public bool IsDefaultTile
|
||||
{
|
||||
get => this.CredentialProvider.DefaultTile == this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current usage scenario
|
||||
@@ -87,7 +92,7 @@ namespace Lithnet.CredentialProvider
|
||||
/// Gets the HWND of the parent of the credential provider, and notifies LogonUI or CredUI that we need to create a Window
|
||||
/// </summary>
|
||||
/// <returns>A HWND to the parentobject</returns>
|
||||
/// <exception cref="InvalidOperationException">The method was called before the host has advised that is ready to rpovide events</exception>
|
||||
/// <exception cref="InvalidOperationException">The method was called before the host has advised that is ready to provide events</exception>
|
||||
/// <exception cref="COMException">The request to obtain the parent window HWND failed</exception>
|
||||
public IntPtr CreateParentWindowHwnd()
|
||||
{
|
||||
@@ -156,6 +161,15 @@ namespace Lithnet.CredentialProvider
|
||||
/// </summary>
|
||||
protected virtual void OnSelected() { }
|
||||
|
||||
/// <summary>
|
||||
/// Called after a tiles is selected to determine if the user should be automatically logged on
|
||||
/// </summary>
|
||||
/// <returns>True, if a logon should be immediately attempted</returns>
|
||||
/// <remarks>
|
||||
/// In Windows 10, if a credential provider wants to automatically log the user on in a situation Windows does not think is appropriate, the system will display a sign in button as a speed bump. One example of this is when a user with an empty password locks the computer or signs out. In that scenario, Windows does not directly log the user back in.
|
||||
/// </remarks>
|
||||
protected virtual bool OnSelectedShouldAutoLogon() => false;
|
||||
|
||||
/// <summary>
|
||||
/// Called when a user deselects this tile
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user