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;
|
this.notifyOnTileCollectionChange = true;
|
||||||
|
|
||||||
var autoLogonTile = this.Tiles.FirstOrDefault(t => t.IsAutoLogon);
|
var defaultTile = this.DefaultTile;
|
||||||
var defaultTile = this.Tiles.FirstOrDefault(t => t.IsDefault);
|
|
||||||
|
|
||||||
uint defaultIndex = CREDENTIAL_PROVIDER_NO_DEFAULT;
|
if (defaultTile != null)
|
||||||
if (autoLogonTile != null)
|
|
||||||
{
|
{
|
||||||
defaultIndex = (uint)this.tiles.IndexOf(autoLogonTile);
|
var index = this.tiles.IndexOf(defaultTile);
|
||||||
}
|
|
||||||
else if (defaultTile != null)
|
if (index >= 0)
|
||||||
{
|
{
|
||||||
defaultIndex = (uint)this.tiles.IndexOf(defaultTile);
|
pdwDefault = (uint)index;
|
||||||
|
pbAutoLogonWithDefault = this.DefaultTileAutoLogon ? 1 : 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pdwCount = (uint)this.Tiles.Count;
|
pdwCount = (uint)this.Tiles.Count;
|
||||||
pdwDefault = defaultIndex;
|
|
||||||
pbAutoLogonWithDefault = autoLogonTile == null ? 0 : 1;
|
|
||||||
|
|
||||||
this.logger.LogTrace($"GetCredentialCount returning pdwCount: {pdwCount}, pdwDefault: {pdwDefault}, pbAutoLogonWithDefault: {pbAutoLogonWithDefault}");
|
this.logger.LogTrace($"GetCredentialCount returning pdwCount: {pdwCount}, pdwDefault: {pdwDefault}, pbAutoLogonWithDefault: {pbAutoLogonWithDefault}");
|
||||||
|
|
||||||
return HRESULT.S_OK;
|
return HRESULT.S_OK;
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using Lithnet.CredentialProvider.Interop;
|
using Lithnet.CredentialProvider.Interop;
|
||||||
@@ -115,6 +116,35 @@ namespace Lithnet.CredentialProvider
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract bool ShouldIncludeGenericTile();
|
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>
|
/// <summary>
|
||||||
/// Adds additional user tiles to the collection, and notifies LogonUI that new tiles are available
|
/// Adds additional user tiles to the collection, and notifies LogonUI that new tiles are available
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ namespace Lithnet.CredentialProvider
|
|||||||
{
|
{
|
||||||
this.logger.LogTrace("SetSelected");
|
this.logger.LogTrace("SetSelected");
|
||||||
this.IsSelected = true;
|
this.IsSelected = true;
|
||||||
pbAutoLogon = this.IsAutoLogon ? 1 : 0;
|
|
||||||
this.OnSelected();
|
this.OnSelected();
|
||||||
|
pbAutoLogon = this.OnSelectedShouldAutoLogon() ? 1 : 0;
|
||||||
return HRESULT.S_OK;
|
return HRESULT.S_OK;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ namespace Lithnet.CredentialProvider
|
|||||||
private protected readonly ICredentialProviderLogger logger;
|
private protected readonly ICredentialProviderLogger logger;
|
||||||
private protected ICredentialProviderCredentialEvents events;
|
private protected ICredentialProviderCredentialEvents events;
|
||||||
private protected ICredentialProviderCredentialEvents2 events2;
|
private protected ICredentialProviderCredentialEvents2 events2;
|
||||||
|
|
||||||
private protected ControlCollection controls;
|
private protected ControlCollection controls;
|
||||||
|
|
||||||
protected CredentialTile(CredentialProviderBase credentialProvider)
|
protected CredentialTile(CredentialProviderBase credentialProvider)
|
||||||
@@ -37,12 +36,18 @@ namespace Lithnet.CredentialProvider
|
|||||||
/// <summary>
|
/// <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.
|
/// 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>
|
/// </summary>
|
||||||
public bool IsAutoLogon { get; set; }
|
public bool IsDefaultTileAutoLogon
|
||||||
|
{
|
||||||
|
get => this.CredentialProvider.DefaultTile == this && this.CredentialProvider.DefaultTileAutoLogon;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating if this should be the default time
|
/// Gets a value indicating if this should be the default tile
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDefault { get; set; }
|
public bool IsDefaultTile
|
||||||
|
{
|
||||||
|
get => this.CredentialProvider.DefaultTile == this;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the current usage scenario
|
/// 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
|
/// Gets the HWND of the parent of the credential provider, and notifies LogonUI or CredUI that we need to create a Window
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>A HWND to the parentobject</returns>
|
/// <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>
|
/// <exception cref="COMException">The request to obtain the parent window HWND failed</exception>
|
||||||
public IntPtr CreateParentWindowHwnd()
|
public IntPtr CreateParentWindowHwnd()
|
||||||
{
|
{
|
||||||
@@ -156,6 +161,15 @@ namespace Lithnet.CredentialProvider
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void OnSelected() { }
|
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>
|
/// <summary>
|
||||||
/// Called when a user deselects this tile
|
/// Called when a user deselects this tile
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user