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.
359 lines
14 KiB
359 lines
14 KiB
using System;
|
|
using System.Data;
|
|
using System.Web;
|
|
using System.Web.Security;
|
|
using FineUI;
|
|
using System.Text;
|
|
using System.Linq;
|
|
using CK.SCP.Models.AppBoxEntity;
|
|
using System.Collections.Generic;
|
|
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;
|
|
using System.Reflection;
|
|
|
|
namespace SCP
|
|
{
|
|
public partial class default_XG : PageBase
|
|
{
|
|
#region Page_Load
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
var _username = Request.QueryString["t"];
|
|
var _email = Request.QueryString["u"];
|
|
var _domain = Request.QueryString["f"];//工厂
|
|
var _token = Request.QueryString["token"];//单点登陆令牌
|
|
|
|
if (string.IsNullOrEmpty(_username) && string.IsNullOrEmpty(_email))
|
|
{
|
|
LoadData();
|
|
}
|
|
else if (!string.IsNullOrEmpty(_username) && !string.IsNullOrEmpty(_domain) && !string.IsNullOrEmpty(_token))//单点登陆代码
|
|
{
|
|
FormsAuthentication.SignOut();
|
|
Session.Abandon();
|
|
string token= Encryption64.Decrypt(_token.Replace(" ", "+"), DateTime.Now.ToString("yyyyMMdd"));
|
|
if (string.IsNullOrEmpty(token))
|
|
{
|
|
Alert.Show(GetResourceKey("登陆令牌错误!"));
|
|
}
|
|
UserToken usertoken = DB.UserTokens.Where(u => u.UserName == _username && u.Token == token).FirstOrDefault();
|
|
User user = DB.Users.Where(u => u.Name == _username).FirstOrDefault();
|
|
user.UsedDomain = _domain;
|
|
if (usertoken != null && user != null)
|
|
{
|
|
if (!user.Enabled)
|
|
{
|
|
Alert.Show(GetResourceKey("用户未启用,请联系管理员!"));
|
|
}
|
|
else
|
|
{
|
|
LoginSuccess(user);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert.Show(GetResourceKey("登陆令牌错误!或用户名错误!"));
|
|
}
|
|
}
|
|
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 == ("工厂名称"));
|
|
// Versiontxt.Value = "版本号:" + Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
|
if (_cf != null)
|
|
{
|
|
_content = _cf.ParamValue;
|
|
}
|
|
return _content;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Events
|
|
|
|
protected void btnSubmit_Click(object sender, EventArgs e)
|
|
{
|
|
//if (string.IsNullOrEmpty(Text1.Value.ToString()))
|
|
//{
|
|
string userName = textUserName.Value.Trim();
|
|
string password = textPassword.Value.Trim();
|
|
LoadResouce();
|
|
Login(userName, password);
|
|
//}
|
|
}
|
|
protected void btnCZ_Click(object sender, EventArgs e)
|
|
{
|
|
textUserName.Value="";
|
|
textPassword.Value="";
|
|
textyzm.Value = "";
|
|
}
|
|
private void Login(string p_userName, string p_password)
|
|
{
|
|
if (string.IsNullOrEmpty(textUserName.Value) || string.IsNullOrEmpty(textPassword.Value))
|
|
{
|
|
Alert.Show(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)
|
|
{
|
|
Alert.Show(GetResourceKey("用户未启用,请联系管理员!"));
|
|
}
|
|
else
|
|
{
|
|
if (p_password == "666666")
|
|
{
|
|
this.div_1.Style.Add("visibility", "visible");
|
|
this.div_2.Style.Add("visibility", "visible");
|
|
this.div_3.Style.Add("display", "block");
|
|
this.div_4.Style.Add("visibility", "visible");
|
|
this.div_5.Style.Add("visibility", "visible");
|
|
//this.div_6.Style.Add("display", "block");
|
|
//lab2.InnerText = "旧密码";
|
|
if (!string.IsNullOrEmpty(this.textPassword1.Value))
|
|
{
|
|
if (string.IsNullOrEmpty(textEmail.Value) || string.IsNullOrEmpty(textName.Value) ||
|
|
string.IsNullOrEmpty(textMobile.Value))
|
|
{
|
|
Alert.Show(GetResourceKey("电子邮件、电话、姓名不能为空!"));
|
|
return;
|
|
}
|
|
if (this.textPassword1.Value.Trim() != textConfim.Value.Trim())
|
|
{
|
|
Alert.Show(GetResourceKey("新密码与确认密码不一致!"));
|
|
return;
|
|
}
|
|
user.ChineseName = this.textName.Value;
|
|
user.Email = this.textEmail.Value;
|
|
user.CellPhone = this.textMobile.Value;
|
|
user.Password = PasswordUtil.CreateDbPassword(this.textPassword1.Value);
|
|
DB.SaveChanges();
|
|
}
|
|
else
|
|
{
|
|
Alert.Show(GetResourceKey("用户名或密码不能为空!"));
|
|
return;
|
|
}
|
|
}
|
|
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
|
|
{
|
|
Alert.Show("不选定工厂下供应商");
|
|
return;
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert.Show(GetResourceKey("用户名或密码错误!"));
|
|
return;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert.Show(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;
|
|
}
|
|
#endregion
|
|
|
|
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;
|
|
}
|
|
protected void btnResetPassWord_Click(object sender, EventArgs e)
|
|
{
|
|
string userName = textUserName.Value.Trim();
|
|
string email = textEmail.Value.Trim();
|
|
if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(email))
|
|
{
|
|
Alert.Show(GetResourceKey("用户名或邮件不能为空!"));
|
|
return;
|
|
}
|
|
User user = DB.Users.Where(u => u.Name == userName).FirstOrDefault();
|
|
if (user != null)
|
|
{
|
|
if (user.Email == email)
|
|
{
|
|
if (!user.Enabled)
|
|
{
|
|
Alert.Show(GetResourceKey("用户未启用,请联系管理员!"));
|
|
}
|
|
else
|
|
{
|
|
string mails = "";
|
|
mails += user.Email + ",";
|
|
if (mails != "")
|
|
{
|
|
mails = mails.Substring(0, mails.Length - 1);
|
|
}
|
|
var _email = Encryption64.Encrypt(user.Email, DateTime.Now.ToString("yyyyMMdd"));
|
|
var _name = Encryption64.Encrypt(user.Name, DateTime.Now.ToString("yyyyMMdd"));
|
|
string mailbody = "";
|
|
mailbody += "尊敬的供应商<br>";
|
|
mailbody += "你好!<br><br>";
|
|
mailbody += string.Format("<a href='http://{0}/default.aspx?t={1}&u={2}'>{3}</a><br/><br/>", ConfigurationManager.AppSettings["ResetPassWord"].ToString(), _name, _email, "点击登录后请在【权限管理】->【用户设置】更改密码,此链接当天有效");
|
|
mailbody += "<br><br><br><br>日期:" + DateTime.Now;
|
|
MyWebSmtpMail webmail = new MyWebSmtpMail();
|
|
webmail.Send(mails, mailbody, "供应商密码找回");
|
|
Alert.Show("登录链接已发送到邮箱,请查收!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
Alert.Show("不是用户注册邮件,不能登录!");
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void btn_ch_Click(object sender, EventArgs e)
|
|
{
|
|
Session["language"] = "CH";
|
|
btn_Login.Text = "登录";
|
|
btn_MailLogin.Text = "邮件登录";
|
|
btn_back.Attributes["value"] = "退回";
|
|
btn_pass.Attributes["value"] = "找回密码";
|
|
}
|
|
|
|
protected void btn_en_Click(object sender, EventArgs e)
|
|
{
|
|
Session["language"] = "EN";
|
|
btn_Login.Text = "Login";
|
|
btn_MailLogin.Text = "Mail Login";
|
|
btn_back.Attributes["value"] = "Back";
|
|
btn_pass.Attributes["value"] = "Forgot Password";
|
|
}
|
|
|
|
|
|
}
|
|
}
|