|
namespace Encrypt_Decrypt_SBA.LoginUI
{
using System.ComponentModel;
using System.Globalization;
using System.ServiceModel.DomainServices.Client.ApplicationServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
/// <summary>
/// Clase <see cref="UserControl"/> que muestra el estado actual de inicio de sesión y permite iniciar y cerrar sesión.
/// </summary>
public partial class LoginStatus : UserControl
{
/// <summary>
/// Crea una nueva instancia de <see cref="LoginStatus"/>.
/// </summary>
public LoginStatus()
{
this.InitializeComponent();
if (DesignerProperties.IsInDesignTool)
{
VisualStateManager.GoToState(this, "loggedOut", false);
}
else
{
this.DataContext = WebContext.Current;
WebContext.Current.Authentication.LoggedIn += this.Authentication_LoggedIn;
WebContext.Current.Authentication.LoggedOut += this.Authentication_LoggedOut;
this.UpdateLoginState();
}
}
private void LoginButton_Click(object sender, RoutedEventArgs e)
{
LoginRegistrationWindow loginWindow = new LoginRegistrationWindow();
loginWindow.Show();
}
private void LogoutButton_Click(object sender, RoutedEventArgs e)
{
WebContext.Current.Authentication.Logout(logoutOperation =>
{
if (logoutOperation.HasError)
{
ErrorWindow.CreateNew(logoutOperation.Error);
logoutOperation.MarkErrorAsHandled();
}
}, /* userState */ null);
}
private void Authentication_LoggedIn(object sender, AuthenticationEventArgs e)
{
this.UpdateLoginState();
}
private void Authentication_LoggedOut(object sender, AuthenticationEventArgs e)
{
this.UpdateLoginState();
}
private void UpdateLoginState()
{
if (WebContext.Current.User.IsAuthenticated)
{
this.welcomeText.Text = string.Format(
CultureInfo.CurrentUICulture,
ApplicationStrings.WelcomeMessage,
WebContext.Current.User.DisplayName);
}
else
{
this.welcomeText.Text = ApplicationStrings.AuthenticatingMessage;
}
if (WebContext.Current.Authentication is WindowsAuthentication)
{
VisualStateManager.GoToState(this, "windowsAuth", true);
}
else
{
VisualStateManager.GoToState(this, (WebContext.Current.User.IsAuthenticated) ? "loggedIn" : "loggedOut", true);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
hristian Amado is a professional software engineer, professional developer and trainer with over 18 years of experience building applications for Windows Desktop and the Web. Located in Asuncion, Paraguay, He's well involved in many Microsoft's technologies including XAML, C#, X++, WCF, ADO.NET and ASP.NET.
He holds a several Microsoft certifications including Microsoft Certified Professional Developer (MCPD), Microsoft Certified IT Professional, Microsoft Certified Technology Specialist and Microsoft Office Specialist.