/// <summary> /// 執行登入 /// </summary> /// <param name="parameter"></param> /// <returns></returns> public BaseResultModel <MemberModel> DoLogin(LoginParameter parameter) { var result = new BaseResultModel <MemberModel>() { Result = false }; var memeber = _MemberRepository.CheckLogin(parameter.Email, parameter.Password); if (memeber != null) { var now = DateTime.Now; var ticket = new FormsAuthenticationTicket( version: 1, name: memeber.Name, issueDate: DateTime.Now, expiration: now.AddHours(1), isPersistent: false, userData: memeber.Account, cookiePath: FormsAuthentication.FormsCookiePath); var encryptTicket = FormsAuthentication.Encrypt(ticket); HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptTicket); cookie.Expires = ticket.Expiration; HttpContext.Current.Response.Cookies.Add(cookie); HttpContext.Current.Session.Add(ApplicationConst.LoginSessionKey, memeber); result.Result = true; result.Data = memeber; } else { result.Message = "帳號或密碼錯誤"; result.Description = "錯誤"; } return(result); }
public ResultViewModel CheckLogin(MemberViewModel memberVM) { var r = _repos.CheckLogin(memberVM); var rvm = new ResultViewModel(); if (r == null) { rvm.isSuccess = false; rvm.Exception = "no such guy!!"; } else { rvm.isSuccess = true; rvm.Data = r.ID; } return(rvm); }
/// <summary> /// 判断用户登录 /// </summary> /// <param name="loginInfo">用户登录信息</param> /// <returns>操作结果</returns> public OperationResult Login(LoginInfo loginInfo) { var member = MemberRepository.CheckLogin( m => m.Email == loginInfo.Access || m.UserName == loginInfo.Access); if (member == null) { return(new OperationResult(OperationResultType.QueryNull, "指定账号的用户不存在。")); } if (!PublicHelper.MD5(loginInfo.Password + member.Salt).EndsWith(member.PassWord, true, null)) { return(new OperationResult(OperationResultType.Error, "密码错误")); } var loginLog = new LoginLog { IpAddress = loginInfo.IpAddress, Member = member }; LoginLogRepository.Insert(loginLog); return(new OperationResult(OperationResultType.Success, "登录成功", member)); }