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.
324 lines
12 KiB
324 lines
12 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;
|
|
|
|
namespace SCP
|
|
{
|
|
public partial class _default : PageBase
|
|
{
|
|
#region Page_Load
|
|
|
|
protected void Page_Load(object sender, EventArgs e)
|
|
{
|
|
if (!IsPostBack)
|
|
{
|
|
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();
|
|
if (user != null)
|
|
{
|
|
if (!user.Enabled)
|
|
{
|
|
Alert.Show(GetResourceKey("用户未启用,请联系管理员!"));
|
|
}
|
|
else
|
|
{
|
|
LoginSuccess(user);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
private void ImageLoad()
|
|
{
|
|
//IMG_CHECK.ImageUrl = "~/Handlers/MakeVerifyCode.ashx?t=" + DateTime.Now.Ticks;
|
|
|
|
|
|
}
|
|
|
|
private void LoadData()
|
|
{
|
|
// ImageLoad();
|
|
// 如果用户已经登录,则重定向到管理首页
|
|
if (User.Identity.IsAuthenticated)
|
|
{
|
|
Response.Redirect(FormsAuthentication.DefaultUrl);
|
|
}
|
|
}
|
|
protected string GetFactoryName()
|
|
{
|
|
string _content = "闻荫科技有限公司";
|
|
TA_CONFIG _cf = SCPDB.TA_CONFIG.FirstOrDefault(p => p.ParamName == ("工厂名称"));
|
|
if (_cf != null)
|
|
{
|
|
_content = _cf.ParamValue;
|
|
}
|
|
return _content;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Events
|
|
|
|
protected void btnSubmit_Click(object sender, EventArgs e)
|
|
{
|
|
string userName = textUserName.Value.Trim();
|
|
string password = textPassword.Value.Trim();
|
|
|
|
//if (Session["VerifyCode"] != null && !string.IsNullOrEmpty(txt_Verify.Value.Trim()))
|
|
//{
|
|
// var _verifyCode = Session["VerifyCode"].ToString();
|
|
|
|
|
|
// if (txt_Verify.Value.Trim() == _verifyCode)
|
|
// {
|
|
// LoadResouce();
|
|
// Login(userName, password);
|
|
// }
|
|
// else
|
|
// {
|
|
// Alert.Show("验证码不正确,请重新输入!");
|
|
// return;
|
|
// }
|
|
//}
|
|
//else
|
|
//{
|
|
// Alert.Show("请输入验证码!");
|
|
// //ImageLoad();
|
|
// return;
|
|
//}
|
|
|
|
|
|
LoadResouce();
|
|
Login(userName, password);
|
|
|
|
|
|
|
|
}
|
|
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
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
// 登录成功
|
|
LoginSuccess(user);
|
|
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 = false;
|
|
DateTime expiration = DateTime.Now.AddMinutes(120);
|
|
//CreateFormsAuthenticationTicket(user.Name, roleIDs, isPersistent, expiration);
|
|
// 重定向到登陆后首页
|
|
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";
|
|
}
|
|
|
|
|
|
|
|
protected void BTN_CHANGE_Click(object sender, EventArgs e)
|
|
{
|
|
//ImageLoad();
|
|
}
|
|
|
|
protected void btn_Image_Click(object sender, EventArgs e)
|
|
{
|
|
//IMG_CHECK.ImageUrl = "~/Handlers/MakeVerifyCode.ashx?t=" + DateTime.Now.Ticks;
|
|
|
|
}
|
|
}
|
|
}
|
|
|