using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Authentication;
using System.Text;
using System.Threading.Tasks;
using Tango.Core;
using Tango.Integration.Observables;
using Tango.MachineStudio.Common.Authentication;
namespace Tango.MachineStudio.UI.Authentication
{
///
/// Represents the default Machine Studio Authentication provider
///
///
///
public class DefaultAuthenticationProvider : ExtendedObject, IAuthenticationProvider
{
private User _currentUser;
///
/// Gets the current logged-in user.
///
public User CurrentUser
{
get { return _currentUser; }
set
{
_currentUser = value;
CurrentUserChanged?.Invoke(this, _currentUser);
RaisePropertyChangedAuto();
}
}
///
/// Occurs when the current logged-in user has changed.
///
public event EventHandler CurrentUserChanged;
///
/// Performs a user login by the specified email and password.
///
/// The email.
/// The password.
///
/// Login failed for user " + email
public User Login(string email, string password)
{
User user = ObservablesEntitiesAdapter.Instance.Users.SingleOrDefault(x => x.Email.ToLower() == email.ToLower() && x.Password == password);
if (user == null)
{
throw new AuthenticationException("Login failed for user " + email);
}
CurrentUser = user;
return user;
}
///
/// Logs-out the current logged-in user.
///
public void Logout()
{
CurrentUser = null;
}
}
}