public async Task<MethodResult> Login(UserLoginDTO userLoginDTO) { var authTypes = HttpContext.Authentication.GetAuthenticationSchemes(); await HttpContext.Authentication.SignInAsync(authTypes.First().AuthenticationScheme, CreatePrincipal(userLoginDTO.UserName)); //var result = await SignInManager.PasswordSignInAsync(userLoginDTO.UserName, userLoginDTO.Password, userLoginDTO.RememberMe.Value, lockoutOnFailure: false); var ret = new MethodResult { State = true }; return ret; //if (result.Succeeded) //{ // ret.State = true; // return ret; //} //ret.State = false; //if (result.IsLockedOut) //{ // ret.Data = "账号已锁定!"; // return ret; //} //else //{ // ret.Data = "用户名或密码错误!"; // return ret; //} }
/// <summary> /// 注册账号 /// </summary> /// <param name="userDto">账号注册信息</param> /// <returns></returns> public MethodResult RegisterAccount(RegisterDTO userDto) { var userStore = new UserStore<IdentityUser<int>, IdentityRole<int>, CrossContext, int>(_db); var user = new IdentityUser<int>(); user.UserName = userDto.UserName; user.PasswordHash = userDto.Password; var result = new MethodResult(); try { result.State = userStore.CreateAsync(user).Result.Succeeded; } catch (Exception ex) { result.State = false; result.Data = ex; } return result; }