using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
namespace bigtree.Controllers
{
using bigtree.Models;
using bigtree.Model;
using bigtree.lib;
using System.Net.Mail;
using System.Text.RegularExpressions;
public class LoginController : Controller
{
public ActionResult Index()
{
return View();
}
/// <summary>
/// 检查登陆
/// </summary>
/// <param></param>
/// <returns></returns>
[HttpPost]
public ActionResult CheckLoginInfo(FormCollection f)
{
try
{
//post: user , pwd ,remembered
string user = f["user"].Trim();
string pwd = f["pwd"].Trim();
string remembered = f["remembered"].Trim();
JsonResult res = new JsonResult();
if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(pwd))
{
res.Data = new { status = 0 };
}
//MD5加密后的密码
pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "md5").ToLower();
//从数据库读取
Common.WebUser account = MemberInfoService.GetMemberIdForCheck(user, pwd);
if (account == null)
{
res.Data = new { status = 0 };
}
else
{
//{status: 1(success)/0(fail),}
res.Data = new { status = 1 };
//todo:登陆成功,记录登陆用户信息保存登陆状态
FunSession.SetSession(account);
//是否记住登录
if (remembered == "on")
{
HttpCookie cookie = new HttpCookie("LoginInfo", account.Id.ToString());
//3天有效
cookie.Expires.AddDays(3);
Response.Cookies.Add(cookie);
}
else
{
HttpCookie cookie = new HttpCookie(account.Id.ToString(), account.Id.ToString());
//使失效
cookie.Expires.AddYears(-1);
Response.Cookies.Add(cookie);
}
}
return res;
}
catch (Exception ex)
{
throw ex.InnerException;
}
}
}
}
.NET的Ajax请求数据提交实例(2)
内容版权声明:除非注明,否则皆为本站原创文章。