对接登陆注册接口

hmxc
小赖 4 years ago
parent b7df47116f
commit de1d559a88

@ -3,6 +3,7 @@ class API {
static String get resource => '$host/static';
static const int networkTimeOut = 10000;
static _Login login = _Login();
static _User user = _User();
}
class _Login {
@ -17,4 +18,12 @@ class _Login {
///ID
String get unitInfo => '/login/findEstateIANByBuilding';
/// app
String get signUp => '/login/register';
}
class _User {
///
String get userProfile => '/user/personalData/findPersonalData';
}

@ -1,28 +1,4 @@
class UserInfoModel {
Data data;
String message;
bool status;
UserInfoModel({this.data, this.message, this.status});
UserInfoModel.fromJson(Map<String, dynamic> json) {
data = json['data'] != null ? new Data.fromJson(json['data']) : null;
message = json['message'];
status = json['status'];
}
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = new Map<String, dynamic>();
if (this.data != null) {
data['data'] = this.data.toJson();
}
data['message'] = this.message;
data['status'] = this.status;
return data;
}
}
class Data {
int id;
List<String> imgUrls;
String name;
@ -31,7 +7,7 @@ class Data {
int sex;
String birthday;
Data(
UserInfoModel(
{this.id,
this.imgUrls,
this.name,
@ -40,7 +16,7 @@ class Data {
this.sex,
this.birthday});
Data.fromJson(Map<String, dynamic> json) {
UserInfoModel.fromJson(Map<String, dynamic> json) {
id = json['id'];
imgUrls = json['imgUrls'].cast<String>();
name = json['name'];

@ -4,7 +4,6 @@ import 'package:flutter/cupertino.dart';
import 'package:akuCommunity/base/assets_image.dart';
import 'package:akuCommunity/utils/headers.dart';
import 'package:akuCommunity/widget/common_input.dart';
import 'package:akuCommunity/widget/common_app_bar.dart';
import 'package:akuCommunity/widget/single_image_up.dart';
class CertificationPage extends StatefulWidget {

@ -136,13 +136,13 @@ class _PersonalIndexState extends State<PersonalIndex>
),
InkWell(
onTap: () {
if (!userProvider.isSigned) SignInPage().to();
if (!userProvider.isLogin) SignInPage().to();
},
child: Container(
margin: EdgeInsets.only(left: 16.w),
child: userProvider.isLogin
? Text(
'Cheailune',
userProvider.userInfoModel.nickName,
style: TextStyle(
fontSize: 32.sp,
color: Color(0xffad8940),

@ -1,8 +1,14 @@
import 'package:akuCommunity/constants/api.dart';
import 'package:akuCommunity/model/user/pick_building_model.dart';
import 'package:akuCommunity/model/user/user_info_model.dart';
import 'package:akuCommunity/provider/sign_up_provider.dart';
import 'package:akuCommunity/provider/user_provider.dart';
import 'package:akuCommunity/utils/network/base_model.dart';
import 'package:akuCommunity/utils/network/net_util.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:dio/dio.dart';
import 'package:get/get.dart' hide Response;
import 'package:provider/provider.dart';
class SignFunc {
static Future sendMessageCode(String phone) async {
@ -38,4 +44,26 @@ class SignFunc {
.map((e) => PickBuildingModel.fromJson(e))
.toList();
}
///
static Future<bool> signUp() async {
final signUpProvider =
Provider.of<SignUpProvider>(Get.context, listen: false);
final userProvider = Provider.of<UserProvider>(Get.context, listen: false);
Response response = await NetUtil().dio.post(
API.login.signUp,
data: signUpProvider.toMap,
);
BotToast.showText(text: response.data['message']);
if (response.data['status']) {
userProvider.setLogin(response.data['token']);
return true;
} else
return false;
}
static Future<UserInfoModel> getUserInfo() async {
BaseModel baseModel = await NetUtil().get(API.user.userProfile);
return UserInfoModel.fromJson(baseModel.data);
}
}

@ -35,7 +35,6 @@ class SignInPage extends StatefulWidget {
class _SignInPageState extends State<SignInPage> {
TextEditingController _phone = new TextEditingController();
TextEditingController _code = new TextEditingController();
AppBar get _appBar => AppBar(elevation: 0, backgroundColor: Colors.white);
Timer _timer;
bool get validPhone => RegexUtil.isMobileSimple(_phone.text);
@ -90,8 +89,7 @@ class _SignInPageState extends State<SignInPage> {
if (response.data['status']) {
if (response.data['choose'] == 1) {
userProvider.setLogin(response.data['token'] as String);
userProvider.setLogin(response.data['token']);
Get.offAll(TabNavigator());
} else {
cancel();
@ -195,7 +193,6 @@ class _SignInPageState extends State<SignInPage> {
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: _appBar,
body: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {

@ -28,8 +28,6 @@ class _SignUpPickRolePageState extends State<SignUpPickRolePage> {
@override
Widget build(BuildContext context) {
final signUpProvider = Provider.of<SignUpProvider>(context);
return Scaffold(
body: ListView(
padding: EdgeInsets.symmetric(horizontal: 32.w),

@ -1,7 +1,12 @@
import 'package:akuCommunity/base/base_style.dart';
import 'package:akuCommunity/pages/sign/sign_up/sign_up_common_widget.dart';
import 'package:akuCommunity/pages/sign/sign_up/sign_up_verify_page.dart';
import 'package:akuCommunity/provider/sign_up_provider.dart';
import 'package:akuCommunity/utils/headers.dart';
import 'package:flustars/flustars.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:velocity_x/velocity_x.dart';
class SignUpSetNicknamePage extends StatefulWidget {
@ -12,6 +17,14 @@ class SignUpSetNicknamePage extends StatefulWidget {
}
class _SignUpSetNicknamePageState extends State<SignUpSetNicknamePage> {
GlobalKey<FormState> _globalKey = GlobalKey<FormState>();
TextEditingController _textEditingController = TextEditingController();
@override
void dispose() {
_textEditingController?.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -22,7 +35,16 @@ class _SignUpSetNicknamePageState extends State<SignUpSetNicknamePage> {
signUpTitle('设置昵称'),
190.hb,
'请输入您的昵称'.text.size(32.sp).color(ktextPrimary).make(),
TextField(
Form(
key: _globalKey,
child: TextFormField(
controller: _textEditingController,
validator: (value) {
if (TextUtil.isEmpty(value))
return '昵称不能为空';
else
return null;
},
decoration: InputDecoration(
border: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFFD8D8D8)),
@ -30,6 +52,7 @@ class _SignUpSetNicknamePageState extends State<SignUpSetNicknamePage> {
hintText: '为保护个人隐私,在与邻居交流时将显示昵称',
),
),
),
],
),
bottomNavigationBar: Column(
@ -42,7 +65,14 @@ class _SignUpSetNicknamePageState extends State<SignUpSetNicknamePage> {
height: 89.w,
child: '保存'.text.make(),
shape: StadiumBorder(),
onPressed: () {},
onPressed: () {
if (_globalKey.currentState.validate()) {
final signUpProvider =
Provider.of<SignUpProvider>(context, listen: false);
signUpProvider.setNickName(_textEditingController.text);
Get.to(SignUpVerifyPage());
}
},
),
MaterialButton(
elevation: 0,

@ -0,0 +1,94 @@
import 'package:akuCommunity/base/base_style.dart';
import 'package:akuCommunity/pages/sign/sign_func.dart';
import 'package:akuCommunity/pages/sign/sign_up/sign_up_common_widget.dart';
import 'package:akuCommunity/pages/tab_navigator.dart';
import 'package:akuCommunity/provider/sign_up_provider.dart';
import 'package:akuCommunity/utils/headers.dart';
import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:velocity_x/velocity_x.dart';
class SignUpVerifyPage extends StatefulWidget {
SignUpVerifyPage({Key key}) : super(key: key);
@override
_SignUpVerifyPageState createState() => _SignUpVerifyPageState();
}
class _SignUpVerifyPageState extends State<SignUpVerifyPage> {
TextEditingController _nameController = TextEditingController();
TextEditingController _idNumberController = TextEditingController();
GlobalKey<FormState> _formKey = GlobalKey<FormState>();
@override
Widget build(BuildContext context) {
return Scaffold(
body: Form(
key: _formKey,
child: ListView(
padding: EdgeInsets.symmetric(horizontal: 32.w),
children: [
148.hb,
signUpTitle('设置昵称'),
190.hb,
'请输入您的姓名'.text.size(32.sp).color(ktextPrimary).make(),
TextFormField(
controller: _nameController,
validator: (value) {
if (TextUtil.isEmpty(value))
return '姓名不能为空';
else
return null;
},
decoration: InputDecoration(
border: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFFD8D8D8)),
),
// hintText: '',
),
),
40.hb,
'请输入您的身份证号'.text.size(32.sp).color(ktextPrimary).make(),
TextFormField(
controller: _idNumberController,
validator: (value) {
if (TextUtil.isEmpty(value)) return '身份证号不能为空';
if (!RegexUtil.isIDCard(value))
return '身份证格式错误';
else
return null;
},
decoration: InputDecoration(
border: UnderlineInputBorder(
borderSide: BorderSide(color: Color(0xFFD8D8D8)),
),
// hintText: '',
),
),
],
),
),
bottomNavigationBar: MaterialButton(
height: 89.w,
color: kPrimaryColor,
shape: StadiumBorder(),
disabledColor: kPrimaryColor.withOpacity(0.3),
child: '登录'.text.bold.make(),
onPressed: () async {
final signUpProvider =
Provider.of<SignUpProvider>(context, listen: false);
if (_formKey.currentState.validate()) {
signUpProvider.setName(_nameController.text);
signUpProvider.setIdNumber(_idNumberController.text);
bool result = await SignFunc.signUp();
if (result) Get.offAll(TabNavigator());
}
},
elevation: 0,
).pLTRB(82.w, 0, 82.w, 155.w),
);
}
}

@ -11,11 +11,36 @@ class SignUpProvider extends ChangeNotifier {
String get name => _name;
String _tel;
String get tel => _tel;
int _idType;
///default is 1
///
///
///1.
///2.
///3.
int _idType = 1;
///default is 1
///
///
///1.
///2.
///3.
int get idType => _idType;
String _idNumber;
String get idNumber => _idNumber;
Map<String, dynamic> get toMap => {
'estateId': _estateId,
'type': _type,
'nickName': _nickName,
'name': _name,
'tel': _tel,
'idType': _idType,
'idNumber': _idNumber,
};
setEstateId(int id) {
_estateId = id;
notifyListeners();
@ -26,6 +51,11 @@ class SignUpProvider extends ChangeNotifier {
notifyListeners();
}
setNickName(String name) {
_nickName = name;
notifyListeners();
}
setName(String name) {
_name = name;
notifyListeners();
@ -36,7 +66,7 @@ class SignUpProvider extends ChangeNotifier {
notifyListeners();
}
setidType(int idType) {
setIdType(int idType) {
_idType = idType;
notifyListeners();
}

@ -1,3 +1,5 @@
import 'package:akuCommunity/model/user/user_info_model.dart';
import 'package:akuCommunity/pages/sign/sign_func.dart';
import 'package:akuCommunity/utils/hive_store.dart';
import 'package:akuCommunity/utils/network/net_util.dart';
import 'package:flutter/material.dart';
@ -13,25 +15,31 @@ class UserProvider extends ChangeNotifier {
bool _isLogin = false;
bool get isLogin => _isLogin;
setLogin(String token) {
Future setLogin(int token) async {
_isLogin = true;
NetUtil().dio.options.headers.putIfAbsent('App-Admin-Token', () => token);
HiveStore.appBox.put('token', token);
await updateProfile();
notifyListeners();
}
logout() {
_isLogin = false;
_token = null;
_userInfoModel = null;
NetUtil().dio.options.headers.remove('App-Admin-Token');
HiveStore.appBox.delete('token');
notifyListeners();
}
updateProfile() async {
// await
Future updateProfile() async {
_userInfoModel = await SignFunc.getUserInfo();
notifyListeners();
}
String _token;
String get token => _token ?? '';
UserInfoModel _userInfoModel;
UserInfoModel get userInfoModel => _userInfoModel;
}

@ -1,4 +1,5 @@
import 'package:akuCommunity/utils/logger/logger_dio_err.dart';
import 'package:akuCommunity/utils/logger/logger_dio_success.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
@ -13,13 +14,7 @@ class LoggerCard extends StatelessWidget {
Widget _buildResponse() {
Response response = data;
return Card(
child: Column(
children: [
Text(response.statusCode.toString()),
],
),
);
return LoggerDioSuccess(response: response);
}
Widget _getLoggerView() {

@ -1,5 +1,4 @@
import 'package:akuCommunity/extensions/num_ext.dart';
import 'package:common_utils/common_utils.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:velocity_x/velocity_x.dart';

@ -0,0 +1,40 @@
import 'package:akuCommunity/extensions/num_ext.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:velocity_x/velocity_x.dart';
class LoggerDioSuccess extends StatelessWidget {
final Response response;
const LoggerDioSuccess({Key key, this.response}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialButton(
elevation: 10,
highlightElevation: 1,
color: Colors.white,
onPressed: () {},
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
children: [
5.wb,
response.request.path.text.bold.make().expand(),
Chip(
backgroundColor: Colors.redAccent,
label: Text(response?.statusCode?.toString() ?? 'UNKNOW'),
),
5.wb,
Chip(
backgroundColor: Colors.greenAccent,
label: Text(response.request.method),
),
],
),
response.headers['date'].first.toString().text.make(),
],
),
);
}
}
Loading…
Cancel
Save