narsil/Tanshu.Accounts.PointOfSale/Authentication/KeyboardLogin.cs

47 lines
1.3 KiB
C#
Raw Normal View History

2011-01-06 07:17:00 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanshu.Accounts.BI;
using System.Threading;
namespace Tanshu.Accounts.PointOfSale
{
class KeyboardLogin : ILogin
{
private static readonly Tanshu.Logging.SqlLogger log = new Tanshu.Logging.SqlLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public bool LoginUser()
{
return LoginUser(true);
}
bool LoginUser(bool setThreadPrincipal)
{
using (LoginForm login = new LoginForm())
{
string userName;
login.ShowDialog();
bool authenticated = login.UserName(out userName);
if (authenticated && setThreadPrincipal)
SetThreadPrincipal(userName);
return authenticated;
}
}
public bool LogoutUser()
{
Session.User = null;
return true;
}
static void SetThreadPrincipal(string userName)
{
log.Warn(string.Format("User Login: '{0}'", userName));
if (userName.Contains(":"))
userName = userName.Substring(userName.IndexOf(":") + 1);
Session.User = new MembershipBI().GetUserFromName(userName);
}
}
}