|
|
using Estsh.Core.Controllers;
|
|
|
using Estsh.Core.IServices;
|
|
|
using Estsh.Core.Model;
|
|
|
using Estsh.Core.Model.Result;
|
|
|
using Estsh.Core.Models;
|
|
|
using Estsh.Core.Services;
|
|
|
using Estsh.Core.Util;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
using System.Collections;
|
|
|
using System.Text.Json;
|
|
|
|
|
|
/***************************************************************************************************
|
|
|
*
|
|
|
* 更新人:sitong.dong
|
|
|
* 描述:登录控制类
|
|
|
* 修改时间:2022.06.22
|
|
|
* 修改日志:系统迭代升级
|
|
|
*
|
|
|
**************************************************************************************************/
|
|
|
namespace Estsh.Core.Web.Controllers
|
|
|
{
|
|
|
/// <summary>
|
|
|
/// 处理用户登录
|
|
|
/// </summary>
|
|
|
public class AccountController : BaseController
|
|
|
{
|
|
|
private Hashtable result = new Hashtable();
|
|
|
private IAccountService service;
|
|
|
|
|
|
public AccountController(IAccountService _service)
|
|
|
{
|
|
|
this.service = _service;
|
|
|
}
|
|
|
|
|
|
#region 系统登录
|
|
|
/// <summary>
|
|
|
/// 用户登录
|
|
|
/// </summary>
|
|
|
/// <param name="userInfo"></param>
|
|
|
/// <returns></returns>
|
|
|
[HttpPost, ActionName("Login")]
|
|
|
[AllowAnonymous]
|
|
|
public ActionResult Login(SysEmp userInfo)
|
|
|
{
|
|
|
int factoryId = userInfo.FactoryId;
|
|
|
List<SysFactory> factories = service.getSelectFactory(factoryId);
|
|
|
CommonResult loginResult = new CommonResult();
|
|
|
Hashtable result = this.service.login(userInfo);
|
|
|
LoginStatus loginStatus = (LoginStatus)result["status"];
|
|
|
userInfo = (SysEmp)result["userInfo"];
|
|
|
if (factories.Count==0)
|
|
|
{
|
|
|
loginResult.success = false;
|
|
|
loginResult.message = "工厂不存在!";
|
|
|
return Json(loginResult);
|
|
|
}
|
|
|
|
|
|
if (loginStatus == LoginStatus.LOGINSUCESS)
|
|
|
{
|
|
|
userInfo.FactoryId = factories[0].FactoryId;
|
|
|
userInfo.FactoryCode = factories[0].FactoryCode;
|
|
|
HttpContext.Session.SetString("loginedUser", JsonSerializer.Serialize(userInfo));
|
|
|
|
|
|
loginResult.message = "登录成功!";
|
|
|
loginResult.success = true;
|
|
|
loginResult.accountType = userInfo.EmpType.ToString();
|
|
|
HttpContext.Session.Remove("isLockScreen");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
loginResult.success = false;
|
|
|
if (loginStatus == LoginStatus.USERNAMENOEXISTED)
|
|
|
{
|
|
|
loginResult.message = "用户名不存在!";
|
|
|
}
|
|
|
if (loginStatus == LoginStatus.PASSWORDERROR)
|
|
|
{
|
|
|
loginResult.message = "密码错误!";
|
|
|
}
|
|
|
}
|
|
|
return Json(loginResult);
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 退出登陆
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
[AllowAnonymous]
|
|
|
public RedirectResult Logout()
|
|
|
{
|
|
|
HttpContext.Session.Remove("loginedUser");
|
|
|
HttpContext.Session.Remove("isLockScreen");
|
|
|
|
|
|
return Redirect("/System/Login");
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
/// 锁定用户
|
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult lockScreen()
|
|
|
{
|
|
|
HttpContext.Session.SetString("isLockScreen", "true");
|
|
|
return Json("");
|
|
|
}
|
|
|
/// <summary>
|
|
|
/// 解除锁定
|
|
|
/// </summary>
|
|
|
/// <param name="userInfo"></param>
|
|
|
/// <returns></returns>
|
|
|
public ActionResult unlockScreen(SysEmp userInfo)
|
|
|
{
|
|
|
bool isPass = false;
|
|
|
String password = "";
|
|
|
if (userInfo != null)
|
|
|
{
|
|
|
password = MD5Encrypt.NewObject.MD5(userInfo.Passwd);
|
|
|
}
|
|
|
password = (password == null) ? "" : password;
|
|
|
|
|
|
var loginedUser = HttpContext.Session.GetString("loginedUser");
|
|
|
|
|
|
|
|
|
if (loginedUser == null)
|
|
|
{
|
|
|
isPass = false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
SysEmp? user = JsonSerializer.Deserialize<SysEmp>(loginedUser);
|
|
|
if (user == null)
|
|
|
{
|
|
|
isPass = false;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
if (password.Equals(user.Passwd))
|
|
|
{
|
|
|
HttpContext.Session.Remove("isLockScreen");
|
|
|
isPass = true;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
isPass = false;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
result.Add("isPass", isPass);
|
|
|
return Json(result);
|
|
|
}
|
|
|
#endregion
|
|
|
|
|
|
#region 修改密码
|
|
|
public RedirectResult EditPage()
|
|
|
{
|
|
|
if (CurrentEmp != null)
|
|
|
{
|
|
|
return Redirect("/System/EditPassword");
|
|
|
}
|
|
|
return Logout();
|
|
|
|
|
|
}
|
|
|
|
|
|
public ActionResult EditUserPassword(string empId, string oldPassword, string newPassword1)
|
|
|
{
|
|
|
Hashtable result = new Hashtable();
|
|
|
bool existUser = false;
|
|
|
if (CurrentEmp != null)
|
|
|
{
|
|
|
result = service.EditUserPassword(empId, oldPassword, newPassword1, CurrentEmp.EmpId.ToString());
|
|
|
existUser = true;
|
|
|
}
|
|
|
if(!existUser)
|
|
|
{
|
|
|
result.Add("status", false);
|
|
|
result.Add("msg", "用户信息不存在!请重新登录……");
|
|
|
}
|
|
|
return Json(result);
|
|
|
}
|
|
|
#endregion
|
|
|
}
|
|
|
} |