using CK.SCP.Models; using CK.SCP.Models.AppBoxEntity; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; namespace WebService { /// /// WebService 的摘要说明 /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 // [System.Web.Script.Services.ScriptService] public class WebService : System.Web.Services.WebService { [WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethod(Description = "登录", EnableSession = true)] public string GetTokenByUsername(string username) { string clientIp = Context.Request.UserHostAddress; string token = ""; using (AppBoxContext _appdb = EntitiesFactory.CreateAppBoxInstance()) { var user = _appdb.Users.FirstOrDefault(r => r.Name == username); if (user != null) { var usertoken = _appdb.UserTokens.FirstOrDefault(r => r.UserName == username); token = Guid.NewGuid().ToString(); if (usertoken == null) { UserToken item = new UserToken(); item.Token = token; item.UserName = username; item.CreateTime = DateTime.Now; item.CreateUser = clientIp; _appdb.UserTokens.Add(item); } else { usertoken.Token = token; usertoken.UserName = username; usertoken.UpdateTime = DateTime.Now; usertoken.UpdateUser = clientIp; } EntitiesFactory.SaveDb(_appdb); //Context.Session.Add(username, token); token = Encryption64.Encrypt(token, DateTime.Now.ToString("yyyyMMdd")); } else { token = "此用户名无效!"; } } return token; } //[WebMethod(Description = "获取用户名", EnableSession = true)] //public string LoginByToken(string username, string token) //{ // string clientIp = Context.Request.UserHostAddress; // string mseesge = "失败"; // try // { // if (Context.Session[username].ToString() == token) // { // using (AppBoxContext _appdb = EntitiesFactory.CreateAppBoxInstance()) // { // var user = _appdb.Users.FirstOrDefault(r => r.Name == username); // string domin = "JZ1"; // mseesge = "成功"; // // Context.Response.Redirect(FormsAuthentication.LoginUrl + "?t=" + username+ "&f="+ domin); // Context.Response.Redirect("https://www.baidu.com/", true); // } // } // else // { // mseesge = "令牌不对"; // } // } // catch // { // mseesge = "令牌不对"; // } // return mseesge; //} } }