feat: web端密码登录
This commit is contained in:
@ -408,6 +408,8 @@ class Api {
|
|||||||
"${HttpString.passBaseUrl}/x/passport-login/web/login/sms";
|
"${HttpString.passBaseUrl}/x/passport-login/web/login/sms";
|
||||||
|
|
||||||
// web端密码登录
|
// web端密码登录
|
||||||
|
static const String loginInByWebPwd =
|
||||||
|
"${HttpString.passBaseUrl}/x/passport-login/web/login";
|
||||||
|
|
||||||
// app端短信验证码
|
// app端短信验证码
|
||||||
static const String appSmsCode =
|
static const String appSmsCode =
|
||||||
|
@ -214,4 +214,42 @@ class LoginHttp {
|
|||||||
);
|
);
|
||||||
print(res);
|
print(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// web端密码登录
|
||||||
|
static Future loginInByWebPwd({
|
||||||
|
required int username,
|
||||||
|
required String password,
|
||||||
|
required String token,
|
||||||
|
required String challenge,
|
||||||
|
required String validate,
|
||||||
|
required String seccode,
|
||||||
|
}) async {
|
||||||
|
Map data = {
|
||||||
|
'username': username,
|
||||||
|
'password': password,
|
||||||
|
'keep': 0,
|
||||||
|
'token': token,
|
||||||
|
'challenge': challenge,
|
||||||
|
'validate': validate,
|
||||||
|
'seccode': seccode,
|
||||||
|
'source': 'main-fe-header',
|
||||||
|
"go_url": HttpString.baseUrl
|
||||||
|
};
|
||||||
|
FormData formData = FormData.fromMap({...data});
|
||||||
|
var res = await Request().post(
|
||||||
|
Api.loginInByWebPwd,
|
||||||
|
data: formData,
|
||||||
|
options: Options(
|
||||||
|
contentType: Headers.formUrlEncodedContentType,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
if (res.data['code'] == 0) {
|
||||||
|
return {
|
||||||
|
'status': true,
|
||||||
|
'data': res.data['data'],
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {'status': false, 'data': [], 'msg': res.data['message']};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,13 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:developer';
|
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:encrypt/encrypt.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||||
import 'package:get/get.dart';
|
import 'package:get/get.dart';
|
||||||
import 'package:get/get_rx/get_rx.dart';
|
|
||||||
import 'package:pilipala/http/login.dart';
|
import 'package:pilipala/http/login.dart';
|
||||||
import 'package:gt3_flutter_plugin/gt3_flutter_plugin.dart';
|
import 'package:gt3_flutter_plugin/gt3_flutter_plugin.dart';
|
||||||
import 'package:pilipala/models/login/index.dart';
|
import 'package:pilipala/models/login/index.dart';
|
||||||
import 'package:pilipala/pages/webview/index.dart';
|
|
||||||
import 'package:pilipala/utils/login.dart';
|
import 'package:pilipala/utils/login.dart';
|
||||||
|
|
||||||
class LoginPageController extends GetxController {
|
class LoginPageController extends GetxController {
|
||||||
@ -39,7 +37,7 @@ class LoginPageController extends GetxController {
|
|||||||
// 默认密码登录
|
// 默认密码登录
|
||||||
RxInt loginType = 0.obs;
|
RxInt loginType = 0.obs;
|
||||||
|
|
||||||
late String captchaLey;
|
late String captchaKey;
|
||||||
|
|
||||||
late int tel;
|
late int tel;
|
||||||
late int webSmsCode;
|
late int webSmsCode;
|
||||||
@ -102,6 +100,39 @@ class LoginPageController extends GetxController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// web端密码登录
|
||||||
|
void loginInByWebPassword() async {
|
||||||
|
if ((passwordFormKey.currentState as FormState).validate()) {
|
||||||
|
getCaptcha((data) async {
|
||||||
|
CaptchaDataModel captchaData = data;
|
||||||
|
var webKeyRes = await LoginHttp.getWebKey();
|
||||||
|
if (webKeyRes['status']) {
|
||||||
|
String rhash = webKeyRes['data']['hash'];
|
||||||
|
String key = webKeyRes['data']['key'];
|
||||||
|
dynamic publicKey = RSAKeyParser().parse(key);
|
||||||
|
String passwordEncryptyed = Encrypter(RSA(publicKey: publicKey))
|
||||||
|
.encrypt(rhash + passwordTextController.text)
|
||||||
|
.base64;
|
||||||
|
var res = await LoginHttp.loginInByWebPwd(
|
||||||
|
username: tel,
|
||||||
|
password: passwordEncryptyed,
|
||||||
|
token: captchaData.token!,
|
||||||
|
challenge: captchaData.geetest!.challenge!,
|
||||||
|
validate: captchaData.validate!,
|
||||||
|
seccode: captchaData.seccode!,
|
||||||
|
);
|
||||||
|
if (res['status']) {
|
||||||
|
await LoginUtils.confirmLogin('', null);
|
||||||
|
} else {
|
||||||
|
SmartDialog.showToast(res['msg']);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
SmartDialog.showToast(webKeyRes['msg']);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// web端验证码登录
|
// web端验证码登录
|
||||||
void loginInByCode() async {
|
void loginInByCode() async {
|
||||||
if ((msgCodeFormKey.currentState as FormState).validate()) {
|
if ((msgCodeFormKey.currentState as FormState).validate()) {
|
||||||
@ -110,11 +141,10 @@ class LoginPageController extends GetxController {
|
|||||||
cid: 86,
|
cid: 86,
|
||||||
tel: tel,
|
tel: tel,
|
||||||
code: webSmsCode,
|
code: webSmsCode,
|
||||||
captchaKey: captchaLey,
|
captchaKey: captchaKey,
|
||||||
);
|
);
|
||||||
if (res['status']) {
|
if (res['status']) {
|
||||||
log(res.toString());
|
await LoginUtils.confirmLogin('', null);
|
||||||
LoginUtils.confirmLogin('', null);
|
|
||||||
} else {
|
} else {
|
||||||
SmartDialog.showToast(res['msg']);
|
SmartDialog.showToast(res['msg']);
|
||||||
}
|
}
|
||||||
@ -245,7 +275,7 @@ class LoginPageController extends GetxController {
|
|||||||
seccode: captchaData.seccode!,
|
seccode: captchaData.seccode!,
|
||||||
);
|
);
|
||||||
if (res['status']) {
|
if (res['status']) {
|
||||||
captchaLey = res['data']['captcha_key'];
|
captchaKey = res['data']['captcha_key'];
|
||||||
SmartDialog.showToast('验证码已发送');
|
SmartDialog.showToast('验证码已发送');
|
||||||
// 倒计时60s
|
// 倒计时60s
|
||||||
smsCodeSendStatus.value = true;
|
smsCodeSendStatus.value = true;
|
||||||
@ -256,6 +286,7 @@ class LoginPageController extends GetxController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 验证码倒计时
|
||||||
void startTimer() {
|
void startTimer() {
|
||||||
timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
timer = Timer.periodic(const Duration(seconds: 1), (timer) {
|
||||||
if (seconds.value > 0) {
|
if (seconds.value > 0) {
|
||||||
|
@ -234,7 +234,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
.primary, // 设置按钮背景色
|
.primary, // 设置按钮背景色
|
||||||
),
|
),
|
||||||
onPressed: () =>
|
onPressed: () =>
|
||||||
_loginPageCtr.loginInByAppPassword(),
|
_loginPageCtr.loginInByWebPassword(),
|
||||||
child: const Text('确认登录'),
|
child: const Text('确认登录'),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
Reference in New Issue
Block a user