You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
232 lines
7.4 KiB
232 lines
7.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
using System.Web.UI;
|
|
using System.Web.UI.WebControls;
|
|
|
|
|
|
using System.Data;
|
|
|
|
using System.Web.Security;
|
|
using FineUI;
|
|
using System.Text;
|
|
|
|
using CK.SCP.Models.AppBoxEntity;
|
|
|
|
using CK.SCP.Models.ScpEntity;
|
|
using CK.SCP.Controller;
|
|
using System.Text.RegularExpressions;
|
|
using CK.SCP.Models;
|
|
using CK.SCP.Utils;
|
|
using CK.SCP.Common;
|
|
using System.Configuration;
|
|
using SCP.Code;
|
|
|
|
|
|
|
|
namespace SCP
|
|
{
|
|
public partial class Default1 : PageBase
|
|
{
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
GetFactoryName();
|
|
var _username = Request.QueryString["t"];
|
|
var _email = Request.QueryString["u"];
|
|
if (string.IsNullOrEmpty(_username) && string.IsNullOrEmpty(_email))
|
|
{
|
|
LoadData();
|
|
}
|
|
else
|
|
{
|
|
if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_email))
|
|
{
|
|
var _name = Encryption64.Decrypt(_username, DateTime.Now.ToString("yyyyMMdd"));
|
|
var _mail = Encryption64.Decrypt(_email, DateTime.Now.ToString("yyyyMMdd"));
|
|
if (string.IsNullOrEmpty(_name) || string.IsNullOrEmpty(_mail))
|
|
{
|
|
LoadData();
|
|
}
|
|
else
|
|
{
|
|
User user = DB.Users.Where(u => u.Name == _name && u.Email == _mail).FirstOrDefault();
|
|
user.UsedDomain = factoryValue.Value;
|
|
if (user != null)
|
|
{
|
|
if (!user.Enabled)
|
|
{
|
|
Alert.Show(GetResourceKey("用户未启用,请联系管理员!"));
|
|
}
|
|
else
|
|
{
|
|
LoginSuccess(user);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
private void LoadData()
|
|
{
|
|
// 如果用户已经登录,则重定向到管理首页
|
|
if (User.Identity.IsAuthenticated)
|
|
{
|
|
Response.Redirect(FormsAuthentication.DefaultUrl);
|
|
}
|
|
}
|
|
protected string GetFactoryName()
|
|
{
|
|
|
|
|
|
var _list = SCPDB.TB_FACTORY.ToList();
|
|
//dp_List.DataTextField = "FactoryName";
|
|
//dp_List.DataValueField= "ErpDomain";
|
|
//dp_List.DataSource =_list;
|
|
//dp_List.DataBind();
|
|
|
|
|
|
factory.DataTextField = "FactoryName";
|
|
factory.DataValueField = "ErpDomain";
|
|
factory.DataSource = _list;
|
|
factory.DataBind();
|
|
|
|
string _content = "闻荫科技有限公司";
|
|
TA_CONFIG _cf = SCPDB.TA_CONFIG.FirstOrDefault(p => p.ParamName == ("工厂名称"));
|
|
if (_cf != null)
|
|
{
|
|
_content = _cf.ParamValue;
|
|
}
|
|
return _content;
|
|
}
|
|
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
|
|
{
|
|
//用户登录
|
|
try
|
|
{
|
|
|
|
string userName = txtUserName.Text.Trim();
|
|
string password = txtPassword.Text.Trim();
|
|
LoadResouce();
|
|
Login(userName, password);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Alert.Show(ex.Message);
|
|
}
|
|
}
|
|
private void Login(string p_userName, string p_password)
|
|
{
|
|
if (string.IsNullOrEmpty(txtUserName.Text) || string.IsNullOrEmpty(txtPassword.Text))
|
|
{
|
|
lb.Text = (GetResourceKey("用户名或密码不能为空!"));
|
|
return;
|
|
}
|
|
User user = DB.Users.Where(u => u.Name == p_userName).FirstOrDefault();
|
|
|
|
if (user != null)
|
|
{
|
|
if (PasswordUtil.ComparePasswords(user.Password, p_password))
|
|
{
|
|
|
|
if (!user.Enabled)
|
|
{
|
|
lb.Text=(GetResourceKey("用户未启用,请联系管理员!"));
|
|
}
|
|
else
|
|
{
|
|
|
|
var _factoryList = DB.Users.Where(itm => itm.Name == user.Name).FirstOrDefault().TA_FACTORY.Select(p => p.FactoryId).ToList();
|
|
user.UsedDomain = factoryValue.Value;
|
|
if (_factoryList.Contains(factoryValue.Value))
|
|
{
|
|
// 登录成功
|
|
LoginSuccess(user);
|
|
}
|
|
else
|
|
{
|
|
lb.Text = ("不选定工厂下供应商");
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lb.Text = (GetResourceKey("用户名或密码错误!"));
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
lb.Text = (GetResourceKey("用户名或密码错误!"));
|
|
return;
|
|
}
|
|
}
|
|
//获取登录的用户信息
|
|
public static UserLoginInfo UserInfo
|
|
{
|
|
get
|
|
{
|
|
if (HttpContext.Current.Session["user"] != null)
|
|
{
|
|
return (UserLoginInfo)HttpContext.Current.Session["user"];
|
|
}
|
|
return null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
private void LoginSuccess(User user)
|
|
{
|
|
|
|
RegisterOnlineUser(user);
|
|
// 用户所属的角色字符串,以逗号分隔
|
|
string roleIDs = String.Empty;
|
|
if (user.Roles != null)
|
|
{
|
|
roleIDs = String.Join(",", user.Roles.Select(r => r.ID).ToArray());
|
|
}
|
|
bool isPersistent = true;
|
|
DateTime expiration = DateTime.Now.AddMinutes(double.Parse(ConfigurationManager.AppSettings["SCP_TIME_OUT"]));
|
|
CreateFormsAuthenticationTicket(user.Name, roleIDs, isPersistent, expiration, user.UsedDomain);
|
|
|
|
var first = DB.Users.Where(p => p.Name == user.Name).FirstOrDefault();
|
|
if (first != null)
|
|
{
|
|
first.Remark = user.UsedDomain;
|
|
DB.SaveChanges();
|
|
}
|
|
|
|
// 重定向到登陆后首页
|
|
Response.Redirect(FormsAuthentication.DefaultUrl);
|
|
}
|
|
private void LoadResouce()
|
|
{
|
|
List<V_TA_LANGUAGE> _list = new List<V_TA_LANGUAGE>();
|
|
Application["LanguageList"] = ScpCache.LangauageList;
|
|
}
|
|
|
|
|
|
public class UserLoginInfo
|
|
{
|
|
public int UserID;
|
|
public string UserType;
|
|
public string UserName;
|
|
public string SupplierCode;
|
|
public string SupplierName;
|
|
public string FactoryCode;
|
|
public string FactoryName;
|
|
public string Authority;
|
|
public DataTable AuthorityData = null;
|
|
public bool LookPrice;
|
|
}
|
|
}
|
|
}
|