using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Forks.JsonRpc.Client;
using Update.LoginService;
using Update.WCF_;
using Utils.Security;
using WeighBusiness;
using WeighBusiness.BL;
using System.Configuration;
namespace Update.Utils
{
public class LoginUtil
{
private static bool IsInitRpc = false;
private static string urlPath;
public static void InitRpc()
{
var path = ConfigurationManager.AppSettings["UrlPath"];
if (!IsInitRpc) {
RpcFacade.Init(path, "CutupClient");
IsInitRpc = true;
urlPath = path;
} else {
if (urlPath != path) {
RpcFacade.ReInit(path);
}
}
urlPath = path;
}
///
/// 验证远程登陆。如果没有登陆远程系统,则重新登陆
///
public static void CheckLogin()//验证远程登陆。如果没有登陆远程系统,则重新登陆
{
CheckLogin(UserBL.CurrentUser.ERP_User_Name, () => SecurityUtil.ChangeBack(UserBL.CurrentUser.ERP_User_Password, UserBL.a));
}
///
/// 验证远程登陆。如果没有登陆远程系统,则重新登陆
///
public static void CheckLogin(string name, Func GetPassword)//验证远程登陆。如果没有登陆远程系统,则重新登陆
{
if (string.IsNullOrEmpty(Config.Ticket) || !new LoginClient().KeepLogin(Config.Ticket)) {
//var login = LoginSystem(name, GetPassword);
var login = LoginSystem(name, GetPassword);
if (!login.Success)
throw new LoginError("登陆系统失败!");
Config.Ticket = login.Message;
new LoginClient().KeepLogin(Config.Ticket);
}
}
public static bool Login(string name, string password, out string error)
{
error = string.Empty;
//if (UserBL.CurrentUser == null) {
try {
RpcFacade.Login(name, password);
} catch (Exception e) {
error = e.Message;
return false;
}
//}
return true;
}
public static bool CheckSystemPassword(string name, string secretPassword)
{
var originalPassword = SecurityUtil.ChangeBack(secretPassword, UserBL.a);
var login = new LoginClient().Login(name, originalPassword);
return login.Success;
}
private static WcfLoginResponseMessage LoginSystem(string name, Func GetPassword)
{
var password = GetPassword();
return new LoginClient().Login(name, password);
}
}
}