using Itlead.Architecture.Contract;
using Itlead.Architecture.Contract.DataContract;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
namespace Itlead.Architecture.WebAppUI.tools
{
///
/// PhoneLogin 的摘要说明
///
public class PhoneLogin : IHttpHandler, IRequiresSessionState
{
const string userService = "userService";
const string payHistoryService = "payHistoryService";
public void ProcessRequest(HttpContext context)
{
context.Response.Expires = 0;
context.Response.CacheControl = "no-cache";
context.Response.AddHeader("Pragma", "No-Cache");
context.Response.ContentType = "text/plain";
// context.Response.Write("Hello World");
string UserName = context.Request.Params["UserName"];
string Userpass = context.Request.Params["Userpass"];
string Phone = context.Request.Params["phone"];
string PhoneCode = context.Request.Params["phonecode"];
UserData user = new UserData();
var uerinfo = MyBasicLib.Utilities.ServiceInvoker.Invoke(userService, s => s.GetUserByPhone(Phone));
if (uerinfo != null)
{
if (uerinfo.Islock == true)
{
context.Response.Write("jihuo");
}
else
{
if (uerinfo.UserId != Guid.Empty)
{
ReturnData re = new ReturnData();
if (uerinfo.ConfirmPhone == false)
{
re = new getPhoneCode().checkSMS(context, Phone, PhoneCode, 5);
}
else
{
re = new getPhoneCode().checkSMS(context, uerinfo.telphone, PhoneCode, 5);
}
if (re.flag == false)
{
context.Response.Write(re.data);
return;
}
else
{
if (uerinfo.ConfirmPhone == false)
{
uerinfo.telphone = Phone;
uerinfo.ConfirmPhone = true;
MyBasicLib.Utilities.ServiceInvoker.Invoke(userService, s => s.UpdateUser(uerinfo));
uerinfo = MyBasicLib.Utilities.ServiceInvoker.Invoke(userService, s => s.GetUser(user.UserName));
}
}
MyBasicLib.Utilities.ServiceInvoker.Invoke(userService, b => b.updateSessionID(uerinfo.UserId, context.Session.SessionID.ToString().Trim()));
HttpCookie cookie = new HttpCookie("user");
cookie.Expires = DateTime.Now.AddDays(1);
var model = MyBasicLib.Utilities.ServiceInvoker.Invoke(payHistoryService, p => p.getfirstHistory(uerinfo.UserId));
if (model != null)
{
if (model.Endtime >= System.DateTime.Now)
{
cookie.Values.Add("Isread", "1");
}
else
{
cookie.Values.Add("Isread", "0");
var f = MyBasicLib.Utilities.ServiceInvoker.Invoke(userService, u => u.setSate(uerinfo.UserId, "普通会员"));
}
}
else
{
cookie.Values.Add("Isread", "0");
}
context.Session["confirm_phone"] = uerinfo.ConfirmPhone;
context.Session["phone"] = uerinfo.telphone;
cookie.Values.Add("UserName", HttpUtility.UrlEncode(uerinfo.UserName, System.Text.Encoding.UTF8));
cookie.Values.Add("UserId", uerinfo.UserId.ToString());
context.Response.Cookies.Add(cookie);
context.Response.Write("yes");
}
else
{
context.Response.Write("perror");
}
}
}
else
{
context.Response.Write("uerror");
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}