增加client_id登录方式

This commit is contained in:
NewTab
2022-01-19 19:39:25 +08:00
parent 6dbed6cf49
commit e8694643d8
14 changed files with 415 additions and 281 deletions

View File

@@ -18,8 +18,6 @@ class ConfigEditPage extends ConsumerStatefulWidget {
}
class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
String? value;
late TextEditingController _controller;
FocusNode node = FocusNode();
@@ -46,12 +44,10 @@ class _ConfigEditPageState extends ConsumerState<ConfigEditPage> {
actions: [
InkWell(
onTap: () async {
if (value == null) {
"请先点击保存".toast();
return;
}
HttpResponse<NullResponse> response = await Api.saveFile(widget.title, _controller.text);
HttpResponse<NullResponse> response =
await Api.saveFile(widget.title, _controller.text);
if (response.success) {
"提交成功".toast();
ref.read(configProvider).loadContent(widget.title);
Navigator.of(context).pop();
} else {

View File

@@ -8,9 +8,9 @@ import 'package:qinglong_app/module/env/env_viewmodel.dart';
import 'package:qinglong_app/utils/extension.dart';
class AddEnvPage extends ConsumerStatefulWidget {
final EnvBean? taskBean;
final EnvBean? envBean;
const AddEnvPage({Key? key, this.taskBean}) : super(key: key);
const AddEnvPage({Key? key, this.envBean}) : super(key: key);
@override
ConsumerState<AddEnvPage> createState() => _AddEnvPageState();
@@ -27,8 +27,8 @@ class _AddEnvPageState extends ConsumerState<AddEnvPage> {
@override
void initState() {
super.initState();
if (widget.taskBean != null) {
envBean = widget.taskBean!;
if (widget.envBean != null) {
envBean = widget.envBean!;
_nameController.text = envBean.name ?? "";
_valueController.text = envBean.value ?? "";
_remarkController.text = envBean.remarks ?? "";
@@ -88,7 +88,7 @@ class _AddEnvPageState extends ConsumerState<AddEnvPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 10,
height: 15,
),
const Text(
"名称:",
@@ -97,14 +97,10 @@ class _AddEnvPageState extends ConsumerState<AddEnvPage> {
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
TextField(
focusNode: focusNode,
controller: _nameController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入名称",
),
autofocus: false,
@@ -121,7 +117,7 @@ class _AddEnvPageState extends ConsumerState<AddEnvPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 10,
height: 15,
),
const Text(
"值:",
@@ -130,15 +126,11 @@ class _AddEnvPageState extends ConsumerState<AddEnvPage> {
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
TextField(
controller: _valueController,
maxLines: 8,
minLines: 1,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入值",
),
autofocus: false,
@@ -155,7 +147,7 @@ class _AddEnvPageState extends ConsumerState<AddEnvPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 10,
height: 15,
),
const Text(
"备注:",
@@ -164,13 +156,9 @@ class _AddEnvPageState extends ConsumerState<AddEnvPage> {
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
TextField(
controller: _remarkController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入备注",
),
autofocus: false,
@@ -197,10 +185,12 @@ class _AddEnvPageState extends ConsumerState<AddEnvPage> {
envBean.name = _nameController.text;
envBean.value = _valueController.text;
envBean.remarks = _remarkController.text;
HttpResponse<NullResponse> response = await Api.addEnv(_nameController.text, _valueController.text, _remarkController.text, id: envBean.sId);
HttpResponse<NullResponse> response = await Api.addEnv(
_nameController.text, _valueController.text, _remarkController.text,
id: envBean.sId);
if (response.success) {
"操作成功".toast();
(envBean.sId == null) ? "新增成功" : "修改成功".toast();
ref.read(envProvider).updateEnv(envBean);
Navigator.of(context).pop();
} else {

View File

@@ -22,7 +22,8 @@ class LoginPage extends ConsumerStatefulWidget {
}
class _LoginPageState extends ConsumerState<LoginPage> {
final TextEditingController _hostController = TextEditingController(text: getIt<UserInfoViewModel>().host);
final TextEditingController _hostController =
TextEditingController(text: getIt<UserInfoViewModel>().host);
final TextEditingController _userNameController = TextEditingController();
final TextEditingController _passwordController = TextEditingController();
final TextEditingController _cIdController = TextEditingController();
@@ -31,11 +32,15 @@ class _LoginPageState extends ConsumerState<LoginPage> {
bool rememberPassword = false;
bool useSecretLogin = false;
@override
void initState() {
super.initState();
useSecretLogin = getIt<UserInfoViewModel>().useSecretLogined;
if (getIt<UserInfoViewModel>().userName != null && getIt<UserInfoViewModel>().userName!.isNotEmpty) {
if (getIt<UserInfoViewModel>().userName != null &&
getIt<UserInfoViewModel>().userName!.isNotEmpty) {
if (getIt<UserInfoViewModel>().useSecretLogined) {
_cIdController.text = getIt<UserInfoViewModel>().userName!;
} else {
@@ -45,7 +50,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
} else {
rememberPassword = false;
}
if (getIt<UserInfoViewModel>().passWord != null && getIt<UserInfoViewModel>().passWord!.isNotEmpty) {
if (getIt<UserInfoViewModel>().passWord != null &&
getIt<UserInfoViewModel>().passWord!.isNotEmpty) {
if (getIt<UserInfoViewModel>().useSecretLogined) {
_cSecretController.text = getIt<UserInfoViewModel>().passWord!;
} else {
@@ -54,12 +60,8 @@ class _LoginPageState extends ConsumerState<LoginPage> {
}
getIt<UserInfoViewModel>().updateToken("");
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
if (getIt<UserInfoViewModel>().useSecretLogined) {
if (useSecretLogin) {
cardKey.currentState?.toggleCard();
getIt<UserInfoViewModel>().useSecretLogin(!(cardKey.currentState?.isFront ?? true));
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
setState(() {});
});
}
});
}
@@ -151,114 +153,126 @@ class _LoginPageState extends ConsumerState<LoginPage> {
),
FlipCard(
key: cardKey,
fill: Fill.fillBack,
// Fill the back side of the card to make in the same size as the front.
onFlipDone: (back) {
useSecretLogin = back;
setState(() {});
},
direction: FlipDirection.HORIZONTAL,
front: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 15,
),
const Text(
"用户名:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
front: SizedBox(
height: 200,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 15,
),
),
TextField(
onChanged: (_) {
setState(() {});
},
controller: _userNameController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入用户名",
const Text(
"用户名:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
autofocus: false,
),
const SizedBox(
height: 15,
),
const Text(
"密码:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
TextField(
onChanged: (_) {
setState(() {});
},
controller: _userNameController,
decoration: const InputDecoration(
contentPadding:
EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入用户名",
),
autofocus: false,
),
),
TextField(
onChanged: (_) {
setState(() {});
},
controller: _passwordController,
obscureText: true,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入密码",
const SizedBox(
height: 15,
),
autofocus: false,
),
const SizedBox(
height: 10,
),
],
const Text(
"密码:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
TextField(
onChanged: (_) {
setState(() {});
},
controller: _passwordController,
obscureText: true,
decoration: const InputDecoration(
contentPadding:
EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入密码",
),
autofocus: false,
),
const SizedBox(
height: 10,
),
],
),
),
back: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 15,
),
const Text(
"client_id:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
back: SizedBox(
height: 200,
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 15,
),
),
TextField(
onChanged: (_) {
setState(() {});
},
controller: _cIdController,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入client_id",
const Text(
"client_id:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
autofocus: false,
),
const SizedBox(
height: 15,
),
const Text(
"client_secret:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
TextField(
onChanged: (_) {
setState(() {});
},
controller: _cIdController,
decoration: const InputDecoration(
contentPadding:
EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入client_id",
),
autofocus: false,
),
),
TextField(
onChanged: (_) {
setState(() {});
},
controller: _cSecretController,
obscureText: true,
decoration: const InputDecoration(
contentPadding: EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入client_secret",
const SizedBox(
height: 15,
),
autofocus: false,
),
const SizedBox(
height: 10,
),
],
const Text(
"client_secret:",
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
TextField(
onChanged: (_) {
setState(() {});
},
controller: _cSecretController,
obscureText: true,
decoration: const InputDecoration(
contentPadding:
EdgeInsets.fromLTRB(0, 5, 0, 5),
hintText: "请输入client_secret",
),
autofocus: false,
),
const SizedBox(
height: 10,
),
],
),
),
),
Row(
@@ -280,12 +294,13 @@ class _LoginPageState extends ConsumerState<LoginPage> {
GestureDetector(
onTap: () {
cardKey.currentState?.toggleCard();
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) {
WidgetsBinding.instance
?.addPostFrameCallback((timeStamp) {
setState(() {});
});
},
child: Text(
(cardKey.currentState?.isFront ?? true) ? "client_id登录" : "用户名密码登录",
loginByUserName() ? "client_id登录" : "用户名密码登录",
style: const TextStyle(
fontSize: 14,
),
@@ -299,12 +314,19 @@ class _LoginPageState extends ConsumerState<LoginPage> {
SizedBox(
width: MediaQuery.of(context).size.width - 80,
child: IgnorePointer(
ignoring: _hostController.text.isEmpty || _userNameController.text.isEmpty || _passwordController.text.isEmpty || isLoading,
ignoring: !canClickLoginBtn(),
child: CupertinoButton(
padding: const EdgeInsets.symmetric(
vertical: 5,
),
color: canClickLoginBtn() ? ref.watch(themeProvider).themeColor.buttonBgColor() : Theme.of(context).primaryColor.withOpacity(0.4),
color: canClickLoginBtn()
? ref
.watch(themeProvider)
.themeColor
.buttonBgColor()
: Theme.of(context)
.primaryColor
.withOpacity(0.4),
child: isLoading
? const CupertinoActivityIndicator()
: const Text(
@@ -316,11 +338,14 @@ class _LoginPageState extends ConsumerState<LoginPage> {
onPressed: () {
Http.pushedLoginPage = false;
Utils.hideKeyBoard(context);
getIt<UserInfoViewModel>().updateHost(_hostController.text);
if (cardKey.currentState?.isFront ?? true) {
login(_userNameController.text, _passwordController.text);
getIt<UserInfoViewModel>()
.updateHost(_hostController.text);
if (loginByUserName()) {
login(_userNameController.text,
_passwordController.text);
} else {
login(_cIdController.text, _cSecretController.text);
login(_cIdController.text,
_cSecretController.text);
}
},
),
@@ -340,7 +365,7 @@ class _LoginPageState extends ConsumerState<LoginPage> {
bool isLoading = false;
bool loginByUserName() {
return !getIt<UserInfoViewModel>().useSecretLogined;
return !useSecretLogin;
}
Future<void> login(String userName, String password) async {
@@ -365,7 +390,9 @@ class _LoginPageState extends ConsumerState<LoginPage> {
} else {
HttpResponse<UserBean> userResponse = await Api.user();
if (userResponse.success) {
if (userResponse.bean != null && userResponse.bean!.twoFactorActivated != null && userResponse.bean!.twoFactorActivated!) {
if (userResponse.bean != null &&
userResponse.bean!.twoFactorActivated != null &&
userResponse.bean!.twoFactorActivated!) {
("你已开启两步验证,App暂不支持").toast();
isLoading = false;
setState(() {});
@@ -390,9 +417,11 @@ class _LoginPageState extends ConsumerState<LoginPage> {
if (_hostController.text.isEmpty) return false;
if (!loginByUserName()) {
return _cIdController.text.isNotEmpty && _cSecretController.text.isNotEmpty;
return _cIdController.text.isNotEmpty &&
_cSecretController.text.isNotEmpty;
} else {
return _userNameController.text.isNotEmpty && _passwordController.text.isNotEmpty;
return _userNameController.text.isNotEmpty &&
_passwordController.text.isNotEmpty;
}
}
}

View File

@@ -6,16 +6,16 @@ import 'package:qinglong_app/base/ql_app_bar.dart';
import 'package:qinglong_app/module/others/dependencies/dependency_viewmodel.dart';
import 'package:qinglong_app/utils/extension.dart';
class AddDependenyPage extends ConsumerStatefulWidget {
const AddDependenyPage({
class AddDependencyPage extends ConsumerStatefulWidget {
const AddDependencyPage({
Key? key,
}) : super(key: key);
@override
ConsumerState<AddDependenyPage> createState() => _AddDependencyPageState();
ConsumerState<AddDependencyPage> createState() => _AddDependencyPageState();
}
class _AddDependencyPageState extends ConsumerState<AddDependenyPage> {
class _AddDependencyPageState extends ConsumerState<AddDependencyPage> {
final TextEditingController _nameController = TextEditingController();
DepedencyEnum depedencyType = DepedencyEnum.NodeJS;
@@ -83,7 +83,7 @@ class _AddDependencyPageState extends ConsumerState<AddDependenyPage> {
height: 10,
),
DropdownButtonFormField<DepedencyEnum>(
items: [
items: [
DropdownMenuItem(
value: DepedencyEnum.NodeJS,
child: Text(DepedencyEnum.NodeJS.name),
@@ -154,7 +154,7 @@ class _AddDependencyPageState extends ConsumerState<AddDependenyPage> {
);
if (response.success) {
"操作成功".toast();
"新增成功".toast();
ref.read(dependencyProvider).loadData(
depedencyType.name.toLowerCase(),
);

View File

@@ -88,7 +88,7 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 10,
height: 15,
),
const Text(
"名称:",
@@ -97,9 +97,6 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
TextField(
focusNode: focusNode,
controller: _nameController,
@@ -121,7 +118,7 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 10,
height: 15,
),
const Text(
"命令:",
@@ -130,9 +127,6 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
TextField(
controller: _commandController,
maxLines: 4,
@@ -155,7 +149,7 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const SizedBox(
height: 10,
height: 15,
),
const Text(
"定时:",
@@ -164,9 +158,6 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
fontWeight: FontWeight.w600,
),
),
const SizedBox(
height: 10,
),
TextField(
controller: _cronController,
decoration: const InputDecoration(
@@ -213,10 +204,12 @@ class _AddTaskPageState extends ConsumerState<AddTaskPage> {
taskBean.name = _nameController.text;
taskBean.command = _commandController.text;
taskBean.schedule = _cronController.text;
HttpResponse<NullResponse> response = await Api.addTask(_nameController.text, _commandController.text, _cronController.text, id: taskBean.sId);
HttpResponse<NullResponse> response = await Api.addTask(
_nameController.text, _commandController.text, _cronController.text,
id: taskBean.sId);
if (response.success) {
"操作成功".toast();
(widget.taskBean?.sId == null) ? "新增成功" : "修改成功".toast();
ref.read(taskProvider).updateBean(taskBean);
Navigator.of(context).pop();
} else {