Ejemplo n.º 1
0
 /// <summary>
 ///     用户登录
 /// </summary>
 /// <param name="model">登录模型信息</param>
 /// <returns>业务操作结果</returns>
 public OperationResult Login(LoginModel model)
 {
     PublicHelper.CheckArgument(model, "model");
     LoginInfo loginInfo = new LoginInfo
     {
         Access = 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;
 }
Ejemplo n.º 2
0
 /// <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.Access || m.Email == loginInfo.Access);
     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);
 }