Ejemplo n.º 1
0
 public AuthStatus IsCorrectLoginName(string userName)
 {
     var status = new AuthStatus() { IsSuccess = true };
     if (string.IsNullOrWhiteSpace(userName))
     {
         status.IsSuccess = false;
         status.Message = "登录名不能为空!";
     }
     return status;
 }
Ejemplo n.º 2
0
 public AuthStatus IsCorrectPassword(string password)
 {
     var status = new AuthStatus() { IsSuccess = true };
     if (string.IsNullOrWhiteSpace(password))
     {
         status.IsSuccess = false;
         status.Message = "密码不能为空!";
     }
     return status;
 }
Ejemplo n.º 3
0
        //[AllowAnonymous]
        public async Task<IHttpActionResult> Login(LoginViewModel loginViewModel)
        {
            if (!ModelState.IsValid)
                return BadRequest(ModelState);

            #region 设置默认返回JSON
            AuthStatus actionResult = new AuthStatus() { IsSuccess = true, Message = "登录成功!" };
            #endregion
            #region 获取验证策略
            var userStrategy = ApplicationContext.StrategyManager.GetDefaultStrategy<IUserAuthenticationStrategy>();
            if (userStrategy == null)
            {
                actionResult = new AuthStatus() { IsSuccess = true, Message = "无法登录,没有找到登录策略!" };
                return Ok(actionResult);
            }
            #endregion
            actionResult = userStrategy.Login(loginViewModel.LoginName, loginViewModel.Password, loginViewModel.RememberMe);
            return Ok(actionResult);
        }