Ejemplo n.º 1
0
        public async Task <IActionResult> Login([FromBody] LoginViewModel viewModel)
        {
            if (viewModel == null)
            {
                return(StatusCode(400));
            }
            if (string.IsNullOrEmpty(viewModel.PassWord) || string.IsNullOrEmpty(viewModel.UserName))
            {
                return(StatusCode(400));
            }

            if (!string.IsNullOrEmpty(viewModel.returnUri))
            {
                AuthorizationRequest authorizationRequest = await _IdentityInteractionServce.GetAuthorizationContextAsync(viewModel.returnUri);

                if (authorizationRequest == null)
                {
                    return(Json(new { state = "401", Message = "参数错误" }));
                }
                if (await _ClientStore.FindClientByIdAsync(authorizationRequest.ClientId) == null)
                {
                    return(Json(new { state = "401", Message = "参数错误" }));
                }
                forum.DAL.Entity.User user = null;
                //try
                //{
                user = _user.GetAccount(viewModel.UserName, MD5Helper.GetMD5(viewModel.PassWord));
                //}
                //catch(ArgumentException )
                //{
                //    return Json(new { state = "401", Message = "账号或密码为空" });
                //}
                //catch(Exception ex)
                //{
                //    return Json(new { state = "500", Message = "出现错误,请重新刷新页面" });
                //}

                if (user != null)
                {
                    Claim[] claims = new Claim[]
                    {
                        new Claim(ClaimTypes.Name, user.Nickname),
                        new Claim(ClaimTypes.OtherPhone, user.Phone),
                        new Claim(ClaimTypes.PrimarySid, user.ID)
                    };

                    await HttpContext.SignInAsync(viewModel.UserName, claims);

                    return(Json(new { state = "302", location = viewModel.returnUri }));
                }
                return(Json(new { state = "401", Message = "账号或密码错误" }));
            }
            return(View());
        }
Ejemplo n.º 2
0
 public async Task <IActionResult> GetAccount([FromRoute] int id)
 {
     return(Ok(await accountServices.GetAccount(id)));
 }
Ejemplo n.º 3
0
        public AccountModel GetAccount(int accountId)
        {
            var account = _accountServices.GetAccount(accountId);

            return(account.AccountToModel());
        }