ZhiYeJianKang_PeiXun/PeiXun.Controllers/BasicInfo/AccountsAPIController.cs
2025-02-20 15:41:53 +08:00

128 lines
4.1 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using CYQ.Data.Cache;
using CYQ.Data.Tool;
using Newtonsoft.Json;
using Song.Extend;
using Song.ServiceInterfaces;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Web;
using Taurus.Core;
using Taurus.Mvc;
using Taurus.Mvc.Attr;
using WeiSha.Common;
namespace PeiXun.Controllers.BasicInfo
{
public class AccountsAPIController : Controller
{
//public override bool BeforeInvoke(string methodName)
//{
// CancelLoadHtml = true;
// return true;
//}
[HttpGet]
[Token]
public void AA()
{
string id = Query<string>("id");
string token = Query<string>("token");
DistributedCache cache = DistributedCache.Instance;
if (!string.IsNullOrEmpty(token))
{
token = token.ToLower().TrimStart("xyl:".ToCharArray());
if (cache.Get(token) != null)
{
Song.Entities.Accounts emp = cache.Get<Song.Entities.Accounts>(token);
Write("token" + token + "User" + emp.Ac_AccName);
}
}
else
Write("token未缓存");
//Context.Response.Write(id);
}
[HttpPost]
public void Login()
{
string id = Query<string>("id");
string token = Guid.NewGuid().ToString();
DistributedCache cache = DistributedCache.Instance;
string acc = Query<string>("acc"); //账号
string pw = Query<string>("pw"); //密码
bool sign = Query<bool>("sign"); //是否免登录
#region Ext
//LoginService loginService = new LoginService();
//loginService.LoginBefore_SyncData(acc);
//return;
#endregion
//通过验证,进入登录状态
Song.Entities.Accounts emp = Business.Do<IAccounts>().AccountsLogin(acc, pw, true);
if (emp != null)
{
//对于worker如果企业已有负责人或管理员缴费则直接授权登录否则提示没有权限
if (!emp.Ac_IsTeacher && emp.Ac_Type == "worker" && emp.Ac_Pay != 1)
{
Write("{\"success\":\"-4\"}");
return;
}
// 如果没有缴费
if (!emp.Ac_IsTeacher && emp.Ac_Pay != 1)
{
Write("{\"success\":\"-3\"}");
return;
}
//如果没有设置免登录,则按系统设置的时效
if (!sign)
LoginState.Accounts.Write(emp);
else
LoginState.Accounts.Write(emp, 999);
//登录成功
Business.Do<IAccounts>().PointAdd4Login(emp, "手机网页", "账号密码登录", ""); //增加登录积分
Business.Do<IStudent>().LogForLoginAdd(emp);
string json = "{\"success\":\"1\",\"name\":\"" + emp.Ac_Name + "\",\"acid\":\"" + emp.Ac_ID + "\",\"sign\":\"" + (sign ? "1" : "") + "\",\"pw\":\"" + emp.Ac_Pw + "\"}";
//Write(json);
dynamic obj = new ExpandoObject();
obj.token = token;
obj.code = 1;
obj.msg = "success";
obj.data = emp;
//Write(JsonHelper.ToJson(obj));
cache.Set(token, emp, 600);//600分钟
if (cache.Get(emp.Ac_AccName) != null)
{
cache.Remove(cache.Get<string>(emp.Ac_AccName));
}
cache.Set(emp.Ac_AccName, token, 600);
Write(JsonConvert.SerializeObject(obj));
}
else
{
//登录失败
Write("{\"success\":\"-1\"}");
}
//Write(id);
//Context.Response.Write(id);
}
}
}