更新登录对接
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:EasyDartModule/EasyDartModule.dart';
|
||||
import 'package:ef/ef.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutterflow_ui/flutterflow_ui.dart';
|
||||
import 'package:get_storage/get_storage.dart';
|
||||
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
import 'package:vbvs_app/common/color/ServiceConstant.dart';
|
||||
import 'package:vbvs_app/common/color/app_uri_status.dart';
|
||||
import 'package:vbvs_app/common/util/MyUtils.dart';
|
||||
import 'package:vbvs_app/controller/user_info_controller.dart';
|
||||
import 'package:vbvs_app/model/api_response.dart';
|
||||
part 'login_controller.g.dart';
|
||||
|
||||
@JsonSerializable()
|
||||
@@ -13,7 +21,7 @@ class LoginModel {
|
||||
String? account = '17649984946'; //账户
|
||||
String? password = 'wyf123,.'; //密码
|
||||
|
||||
String? phone; //手机号
|
||||
String? phone; //手机号/邮箱
|
||||
String? code; //验证码
|
||||
|
||||
String? register_code;
|
||||
@@ -47,88 +55,87 @@ class LoginController extends GetControllerEx<LoginModel> {
|
||||
}
|
||||
|
||||
//登录
|
||||
Future<String> login(BuildContext context) async {
|
||||
// return '';
|
||||
String message = '';
|
||||
String account = '';
|
||||
String password = '';
|
||||
// if (model.loginStyle == 1) {
|
||||
// //账号登录
|
||||
// if (model.account == null || model.account!.isEmpty) {
|
||||
// message = '账户不能为空';
|
||||
// showToast(message);
|
||||
// return message;
|
||||
// }
|
||||
// if (model.password == null || model.password!.isEmpty) {
|
||||
// message = '密码不能为空';
|
||||
// showToast(message);
|
||||
// return message;
|
||||
// }
|
||||
// account = model.account!;
|
||||
// password = model.password!;
|
||||
// }
|
||||
// if (model.loginStyle == 2) {
|
||||
// //账号登录
|
||||
// if (model.phone == null || model.phone!.isEmpty) {
|
||||
// message = '手机号不能为空';
|
||||
|
||||
// showToast(message);
|
||||
// return message;
|
||||
// }
|
||||
// if (!MyUtils.isValidPhoneNumber(model.phone!)) {
|
||||
// message = '请输入正确的手机号';
|
||||
|
||||
// showToast(message);
|
||||
// return message;
|
||||
// }
|
||||
// if (model.code == null || model.code!.isEmpty) {
|
||||
// message = '验证码不能为空';
|
||||
|
||||
// showToast(message);
|
||||
// return message;
|
||||
// }
|
||||
// account = model.phone!;
|
||||
// password = model.code!;
|
||||
// }
|
||||
// RegisterController registerController = Get.find();
|
||||
// if (registerController.model.register_agree == null ||
|
||||
// registerController.model.register_agree != true) {
|
||||
// message = "需要同意协议";
|
||||
// showToast(message);
|
||||
// return message;
|
||||
// }
|
||||
// message = await repository.login(
|
||||
// model.loginStyle!, account, password, model.forceLogin);
|
||||
// model.forceLogin = 0;
|
||||
|
||||
return message;
|
||||
Future<ApiResponse> login(BuildContext context) async {
|
||||
ApiResponse apiResponse = ApiResponse(code: -1, msg: "其他手机登录页.登录失败".tr);
|
||||
if (model.phone == null || model.phone!.isEmpty) {
|
||||
apiResponse.msg = "其他手机登录页.请输入手机号".tr;
|
||||
return apiResponse;
|
||||
}
|
||||
if (model.code == null || model.code!.isEmpty) {
|
||||
apiResponse.msg = "其他手机登录页.请输入验证码".tr;
|
||||
return apiResponse;
|
||||
}
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.login;
|
||||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
|
||||
var data = {
|
||||
"type": 1,
|
||||
"userName": model.phone,
|
||||
"password": model.code,
|
||||
};
|
||||
var response =
|
||||
await EasyDartModule.dio.post(queryUrl, data: jsonEncode(data));
|
||||
if (response != null) {
|
||||
var responseData =
|
||||
response.data is String ? jsonDecode(response.data) : response.data;
|
||||
ApiResponse res = ApiResponse.fromJson(responseData, (object) => object);
|
||||
MyUtils.formatResponse(apiResponse, "其他手机登录页.登陆成功".tr, "其他手机登录页.登陆失败".tr);
|
||||
if (res.code == HttpStatusCodes.ok) {
|
||||
UserInfoController userInfoController = Get.find();
|
||||
userInfoController.model.login = 1;
|
||||
String token = response.headers['token']!.first;
|
||||
EasyDartModule.dio.token = token;
|
||||
final box = GetStorage();
|
||||
box.write('token', userInfoController.model.token); // 存储 token
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
return ApiResponse(code: -1, msg: "服务器.失败".tr);
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> getCode(BuildContext context) async {
|
||||
String message = "";
|
||||
Future<ApiResponse> getCode(BuildContext context) async {
|
||||
ApiResponse apiResponse = ApiResponse(code: -1, msg: "其他手机登录页.发送失败".tr);
|
||||
if (model.register_agree == null || model.register_agree != true) {
|
||||
// message = "需要同意协议";
|
||||
// showToast(message);
|
||||
return message;
|
||||
apiResponse.msg = "登录页.未同意协议".tr;
|
||||
return apiResponse;
|
||||
}
|
||||
if (model.phone == null || model.phone!.isEmpty) {
|
||||
message = "请输入手机号";
|
||||
// showToast(message);
|
||||
return message;
|
||||
apiResponse.msg = "其他手机登录页.请输入手机号".tr;
|
||||
return apiResponse;
|
||||
}
|
||||
if (!MyUtils.isValidPhoneNumber(model.phone!)) {
|
||||
message = '请输入正确的手机号';
|
||||
showToast(message);
|
||||
return message;
|
||||
if (!MyUtils.isValidPhoneNumber(model.phone!) &&
|
||||
!MyUtils.isValidEmail(model.phone!)) {
|
||||
apiResponse.msg = '其他手机登录页.不正确手机号'.tr;
|
||||
return apiResponse;
|
||||
}
|
||||
// message = await repository.sendRegisterCode(model.phone!);
|
||||
if (message.isNotEmpty) {
|
||||
showToast(message ?? "发送失败,请稍后再试!");
|
||||
return "发送失败,请稍后再试!";
|
||||
String serviceAddress = ServiceConstant.service_address;
|
||||
String serviceName = ServiceConstant.server_service;
|
||||
String serviceApi = ServiceConstant.send_code;
|
||||
String queryUrl = "${serviceAddress}${serviceName}${serviceApi}";
|
||||
var data = {
|
||||
"userName": model.phone,
|
||||
};
|
||||
var response =
|
||||
await EasyDartModule.dio.post(queryUrl, data: jsonEncode(data));
|
||||
if (response != null) {
|
||||
var responseData =
|
||||
response.data is String ? jsonDecode(response.data) : response.data;
|
||||
ApiResponse res = ApiResponse.fromJson(responseData, (object) => object);
|
||||
if (res.code != HttpStatusCodes.ok) {
|
||||
if (res.msg == null || res.msg!.isEmpty) {
|
||||
res.msg = apiResponse.msg;
|
||||
}
|
||||
} else {
|
||||
if (res.msg == null || res.msg!.isEmpty) {
|
||||
res.msg = "其他手机登录页.发送成功".tr;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
} else {
|
||||
showToast("发送验证码成功!", color: color_success);
|
||||
return ApiResponse(code: -1, msg: "服务器.失败".tr);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
|
||||
//微信登录
|
||||
|
||||
Reference in New Issue
Block a user