/// <summary> /// 用户登录 /// </summary> /// <param name="model">登录模型信息</param> /// <returns>业务操作结果</returns> public OperationResult Login(LoginModel model) { PublicHelper.CheckArgument(model, "model"); LoginInfo loginInfo = new LoginInfo { Account = model.Account, Password = model.Password, IpAddress = HttpContext.Current.Request.UserHostAddress }; OperationResult result = base.Login(loginInfo); if (result.ResultType == OperationResultType.Success) { Member member = (Member)result.AppendData; DateTime expiration = model.IsRememberLogin ? DateTime.Now.AddDays(7) : DateTime.Now.Add(FormsAuthentication.Timeout); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, member.UserName, DateTime.Now, expiration, true, member.NickName, FormsAuthentication.FormsCookiePath); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(ticket)); if (model.IsRememberLogin) { cookie.Expires = DateTime.Now.AddDays(7); } HttpContext.Current.Response.Cookies.Set(cookie); result.AppendData = null; } return result; }
/// <summary> /// 用户登录 /// </summary> /// <param name="loginInfo">登录信息</param> /// <returns>业务操作结果</returns> public virtual OperationResult Login(LoginInfo loginInfo) { PublicHelper.CheckArgument(loginInfo, "loginInfo"); Member member = MemberRepository.Entities.SingleOrDefault(m => m.UserName == loginInfo.Account || m.Email == loginInfo.Account); if (member == null) { return new OperationResult(OperationResultType.QueryNull, "指定账号的用户不存在。"); } if (member.Password != loginInfo.Password) { return new OperationResult(OperationResultType.Warning, "登录密码不正确。"); } LoginLog loginLog = new LoginLog { IpAddress = loginInfo.IpAddress, Member = member }; LoginLogRepository.Insert(loginLog); return new OperationResult(OperationResultType.Success, "登录成功。", member); }