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

49 lines
1.4 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tanshu.Accounts.Repository;
using System.Threading;
using Tanshu.Accounts.Contracts;
using Tanshu.Common.KeyboardControl;
namespace Tanshu.Accounts.PointOfSale
{
class MsrLogin : 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 (var frm = new MsrLoginForm(false))
{
string userName;
frm.ShowDialog();
bool authenticated = frm.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 = UserBI.GetUserFromName(userName);
}
}
}