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("id"); string token = Query("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(token); Write("token:" + token + ";User:" + emp.Ac_AccName); } } else Write("token未缓存"); //Context.Response.Write(id); } [HttpPost] public void Login() { string id = Query("id"); string token = Guid.NewGuid().ToString(); DistributedCache cache = DistributedCache.Instance; string acc = Query("acc"); //账号 string pw = Query("pw"); //密码 bool sign = Query("sign"); //是否免登录 #region Ext 扩展代码,同步平台用户数据 //LoginService loginService = new LoginService(); //loginService.LoginBefore_SyncData(acc); //return; #endregion //通过验证,进入登录状态 Song.Entities.Accounts emp = Business.Do().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().PointAdd4Login(emp, "手机网页", "账号密码登录", ""); //增加登录积分 Business.Do().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(emp.Ac_AccName)); } cache.Set(emp.Ac_AccName, token, 600); Write(JsonConvert.SerializeObject(obj)); } else { //登录失败 Write("{\"success\":\"-1\"}"); } //Write(id); //Context.Response.Write(id); } } }