Răsfoiți Sursa

登录修改

panhui 6 ani în urmă
părinte
comite
9c467b4259

BIN
images/2x/list_icon_yanzhengma.png


BIN
images/3x/list_icon_yanzhengma.png


BIN
images/list_icon_yanzhengma.png


+ 2 - 1
lib/main.dart

@@ -57,7 +57,8 @@ class MobileCyberGamesApp extends StatelessWidget {
               splashColor: Color(0xFF8E3B36),
               shape: RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(0))),
             )),
-        home: store.state.userInfo != null ? HomePage() : LoginFirst(),
+        // home: store.state.userInfo != null ? HomePage() : LoginFirst(),
+        home: LoginFirst(),
         routes: {'/home': (BuildContext context) => HomePage()},
         color: Color(0xFF2E3049),
       ),

+ 43 - 32
lib/pages/LoginFirst.dart

@@ -6,6 +6,8 @@ import '../styles/totast.dart';
 import 'LoginSecond.dart';
 import '../utils/Utils.dart';
 import '../widget/LinearButton.dart';
+import '../net/HttpManager.dart';
+import '../net/Result.dart';
 
 class LoginFirst extends StatefulWidget {
   @override
@@ -47,7 +49,7 @@ class LoginFirstState extends State<LoginFirst> {
                       Image.asset('images/icon_logo.png'),
                       Container(
                         margin: EdgeInsets.only(top: 30),
-                        child: Text('手机快捷登录', style: TextStyle(color: Colors.white, fontSize: 28, fontWeight: FontWeight.w500)),
+                        child: Text('手机账号登录', style: TextStyle(color: Colors.white, fontSize: 28, fontWeight: FontWeight.w500)),
                       ),
                       Container(
                           margin: EdgeInsets.only(top: 20),
@@ -82,45 +84,54 @@ class LoginFirstState extends State<LoginFirst> {
                               onChanged: (value) {
                                 inputVal = value;
                               })),
-                      Text('未注册的手机号验证后自动创建账户', style: TextStyle(color: Color(0xFF727785), fontSize: 13)),
-                      Container(height: 20,),
+                      // Text('未注册的手机号验证后自动创建账户', style: TextStyle(color: Color(0xFF727785), fontSize: 13)),
+                      Container(
+                        height: 52,
+                      ),
                       LinearButton(
-                        btntext: '下一步',
-                        onTapHomeMenu: ()  {
-                          
-                           if (!checkPhone(inputVal)) {
-                                Toast.show(context, '手机号格式错误', 1500, 'info');
+                          btntext: '下一步',
+                          onTapHomeMenu: () async {
+                            if (!checkPhone(inputVal)) {
+                              Toast.show(context, '手机号格式错误', 1500, 'info');
+                            } else {
+                              final Result res = await HttpManager.get('userInfo/getOne', data: {'phone': inputVal});
+
+                              if (res.data != null && res.data['id'] != null) {
+                                Navigator.push(
+                                  context,
+                                  CupertinoPageRoute(
+                                    builder: (context) => LoginSecond(phone: inputVal, userId: res.data['id']),
+                                  ),
+                                );
                               } else {
                                 Navigator.push(
                                   context,
                                   CupertinoPageRoute(
-                                    builder: (context) =>
-                                        LoginSecond(phone: inputVal),
+                                    builder: (context) => LoginSecond(phone: inputVal, userId: 0),
                                   ),
                                 );
                               }
-                        }
-                      ),
-                     
-                        //  FlatButton(
-                        //   textColor: Colors.white,
-                        //   color: PRIMARY_COLOR,
-                        //   highlightColor: Color(0xFF763434),
-                        //   child: Text('下一步'),
-                        //   onPressed: () {
-                        //     if (!checkPhone(inputVal)) {
-                        //       Toast.show(context, '手机号格式错误', 1500, 'info');
-                        //     } else {
-                        //       Navigator.push(
-                        //         context,
-                        //         CupertinoPageRoute(
-                        //           builder: (context) => LoginSecond(phone: inputVal),
-                        //         ),
-                        //       );
-                        //     }
-                        //   },
-                        // ),
-                      
+                            }
+                          }),
+
+                      //  FlatButton(
+                      //   textColor: Colors.white,
+                      //   color: PRIMARY_COLOR,
+                      //   highlightColor: Color(0xFF763434),
+                      //   child: Text('下一步'),
+                      //   onPressed: () {
+                      //     if (!checkPhone(inputVal)) {
+                      //       Toast.show(context, '手机号格式错误', 1500, 'info');
+                      //     } else {
+                      //       Navigator.push(
+                      //         context,
+                      //         CupertinoPageRoute(
+                      //           builder: (context) => LoginSecond(phone: inputVal),
+                      //         ),
+                      //       );
+                      //     }
+                      //   },
+                      // ),
                     ],
                   ),
                 ),

+ 93 - 90
lib/pages/LoginSecond.dart

@@ -1,7 +1,7 @@
 import 'dart:async';
+import 'package:flutter/cupertino.dart';
 import 'package:flutter/material.dart';
 import 'package:shared_preferences/shared_preferences.dart';
-import 'package:flutter/cupertino.dart';
 import '../styles/colors.dart';
 import 'dart:ui';
 import '../styles/totast.dart';
@@ -14,10 +14,12 @@ import '../redux/AppState.dart';
 import '../redux/UserRedux.dart';
 import '../model/UserInfo.dart';
 import '../widget/LinearButton.dart';
+import '../widget/Dialog.dart';
 
 class LoginSecond extends StatefulWidget {
-  LoginSecond({Key key, this.phone}) : super(key: key);
+  LoginSecond({Key key, this.phone, this.userId = 0}) : super(key: key);
   final String phone; // 用来储存传递过来的值
+  final int userId;
   @override
   LoginSecondState createState() => LoginSecondState();
 }
@@ -26,7 +28,8 @@ class LoginSecondState extends State<LoginSecond> {
   String _sessionID;
   bool isSend = false; //是否发送
   int sendTime = 0;
-  String inputCode;
+  String password;
+  String surePass;
   String useToken;
   Timer timer;
 
@@ -34,7 +37,7 @@ class LoginSecondState extends State<LoginSecond> {
   void initState() {
     super.initState();
     Future.delayed(Duration.zero, () {
-      sendMsg();
+      // sendMsg();
     });
   }
 
@@ -56,52 +59,28 @@ class LoginSecondState extends State<LoginSecond> {
                     SliverToBoxAdapter(
                       child: Container(
                         color: BG_SUB_COLOR,
-                        padding:
-                            EdgeInsets.symmetric(vertical: 30, horizontal: 15),
+                        padding: EdgeInsets.symmetric(vertical: 30, horizontal: 15),
                         child: Column(
                           crossAxisAlignment: CrossAxisAlignment.start,
                           children: <Widget>[
                             Text(
-                              '验证码已发送至',
-                              style: TextStyle(
-                                  color: Colors.white,
-                                  fontSize: 28,
-                                  fontWeight: FontWeight.w600),
+                              '请输入密码',
+                              style: TextStyle(color: Colors.white, fontSize: 28, fontWeight: FontWeight.w600),
                             ),
                             Container(
-                              margin: EdgeInsets.only(top: 45),
-                              child: Row(
-                                mainAxisAlignment:
-                                    MainAxisAlignment.spaceBetween,
-                                children: <Widget>[
-                                  Text(widget.phone,
-                                      style: TextStyle(
-                                          color: Theme.of(context).primaryColor,
-                                          fontSize: 20,
-                                          fontWeight: FontWeight.w500)),
-                                  FlatButton(
-                                    highlightColor: BG_SUB_COLOR,
-                                    textColor: PRIMARY_COLOR,
-                                    child:
-                                        Text(isSend ? '($sendTime)秒' : '重新发送'),
-                                    disabledTextColor: Color(0xFF8D8E9C),
-                                    onPressed: isSend
-                                        ? null
-                                        : () {
-                                            if (timer != null) {
-                                              timer.cancel();
-                                            }
-                                            sendMsg();
-                                          },
-                                  )
-                                ],
-                              ),
+                              height: widget.userId == 0 ? 5 : 20,
                             ),
+                            widget.userId == 0
+                                ? Text(
+                                    '您当前为首次登录,请设置您的密码',
+                                    style: TextStyle(color: Colors.white, fontSize: 14),
+                                  )
+                                : Container(),
                             Container(
                               margin: EdgeInsets.only(top: 10),
                               child: ITextField(
                                 maxLength: 6,
-                                keyboardType: ITextInputType.number,
+                                keyboardType: ITextInputType.password,
                                 prefixIcon: Container(
                                   padding: EdgeInsets.all(10),
                                   // color: PRIMARY_COLOR,
@@ -110,7 +89,7 @@ class LoginSecondState extends State<LoginSecond> {
                                     width: 20,
                                   ),
                                 ),
-                                hintText: '输入短信验证码',
+                                hintText: widget.userId==0?'请设置您的密码':'请输入您的密码',
                                 hintStyle: TextStyle(
                                   fontSize: 16,
                                   color: Color(0xFF727785),
@@ -118,62 +97,87 @@ class LoginSecondState extends State<LoginSecond> {
                                 textStyle: TextStyle(color: Colors.white),
                                 fieldCallBack: (content) {
                                   setState(() {
-                                    inputCode = content;
+                                    password = content;
                                   });
                                 },
-                                counterStyle:
-                                    TextStyle(color: BG_SUB_COLOR, fontSize: 0),
+                                counterStyle: TextStyle(color: BG_SUB_COLOR, fontSize: 0),
                               ),
                             ),
-                            Container(height: 20,),
+                            widget.userId == 0
+                                ? Container(
+                                    margin: EdgeInsets.only(top: 10),
+                                    child: ITextField(
+                                      maxLength: 6,
+                                      keyboardType: ITextInputType.password,
+                                      prefixIcon: Container(
+                                        padding: EdgeInsets.all(10),
+                                        // color: PRIMARY_COLOR,
+                                        child: Image.asset(
+                                          'images/list_icon_yanzhengma.png',
+                                          width: 20,
+                                        ),
+                                      ),
+                                      hintText: '请确认您的密码',
+                                      hintStyle: TextStyle(
+                                        fontSize: 16,
+                                        color: Color(0xFF727785),
+                                      ),
+                                      textStyle: TextStyle(color: Colors.white),
+                                      fieldCallBack: (content) {
+                                        setState(() {
+                                          surePass = content;
+                                        });
+                                      },
+                                      counterStyle: TextStyle(color: BG_SUB_COLOR, fontSize: 0),
+                                    ),
+                                  )
+                                : InkWell(
+                                    child: Text('忘记密码?',
+                                        style: TextStyle(
+                                          color: Theme.of(context).primaryColor,
+                                        )),
+                                    onTap: () {
+                                      MyDialog.showDialog(context, '找回密码请联系客服',
+                                          textList: [
+                                            {'value': 'QQ:561133222', 'isImportant': false}
+                                          ],
+                                          title: '找回密码');
+                                    },
+                                  ),
+                            Container(
+                              height: 52,
+                            ),
                             LinearButton(
-                              btntext:'注册/登录',
+                              btntext: widget.userId == 0 ? '注册' : '登录',
                               onTapHomeMenu: () async {
-                                    if (_sessionID == null) {
-                                      Toast.show(
-                                          context, '请发送验证码', 1500, 'info');
-                                    } else if (inputCode.length != 6) {
-                                      Toast.show(
-                                          context, '请输入验证码', 1500, 'info');
-                                    } else {
-                                      Toast.show(context, '加载中', -1, 'loading');
-                                      final Result res = await HttpManager.post(
-                                          'auth/loginSms',
-                                          data: {
-                                            'phone': widget.phone,
-                                            'code': inputCode,
-                                            'sessionId': _sessionID,
-                                            'requireToken': true
-                                          });
-                                      Toast.hide();
-                                      if (res.success) {
-                                        if (timer != null) {
-                                          timer.cancel();
-                                        }
-                                        final prefs = await SharedPreferences
-                                            .getInstance();
-                                        await prefs.setString(
-                                            'token', res.token);
-                                        HttpManager.token = res.token;
-                                        StoreProvider.of<AppState>(context)
-                                            .dispatch(UpdateUserAction(
-                                                UserInfo.fromJson(res.data)));
+                                if (password == '') {
+                                  Toast.show(context, '请输入密码', 1500, 'info');
+                                } else if (password != surePass && widget.userId == 0) {
+                                  Toast.show(context, '两次密码输入不一致', 1500, 'info');
+                                } else {
+                                  print(password);
+                                  print(widget.phone);
+                                  Toast.show(context, '加载中', -1, 'loading');
+                                  final Result res =
+                                      await HttpManager.post('auth/login', data: {'username': widget.phone, 'password': password, 'requireToken': true});
+                                  Toast.hide();
+                                  if (res.success) {
+                                    final prefs = await SharedPreferences.getInstance();
+                                    await prefs.setString('token', res.token);
+                                    HttpManager.token = res.token;
+                                    StoreProvider.of<AppState>(context).dispatch(UpdateUserAction(UserInfo.fromJson(res.data)));
 
-                                        Toast.show(
-                                            context, '登录成功', 1500, 'success');
-                                        Navigator.pushReplacement(
-                                          context,
-                                          CupertinoPageRoute(
-                                              builder: (context) => HomePage()),
-                                        );
-                                      } else {
-                                        Toast.show(
-                                            context, res.error, 1500, 'info');
-                                      }
-                                    }
-                                  },
+                                    Toast.show(context, '登录成功', 1500, 'success');
+                                    Navigator.pushReplacement(
+                                      context,
+                                      CupertinoPageRoute(builder: (context) => HomePage()),
+                                    );
+                                  } else {
+                                    Toast.show(context, res.error, 1500, 'info');
+                                  }
+                                }
+                              },
                             ),
-                            
                           ],
                         ),
                       ),
@@ -191,8 +195,7 @@ class LoginSecondState extends State<LoginSecond> {
 
   Future<void> sendMsg() async {
     Toast.show(context, '加载中', -1, 'loading');
-    final Result res =
-        await HttpManager.get('rong/sendCode', data: {'phone': widget.phone});
+    final Result res = await HttpManager.get('rong/sendCode', data: {'phone': widget.phone});
     Toast.hide();
     if (res.success) {
       Toast.show(context, '发送成功', 1500, 'success');

+ 220 - 0
lib/pages/LoginSecond_old.dart

@@ -0,0 +1,220 @@
+import 'dart:async';
+import 'package:flutter/material.dart';
+import 'package:shared_preferences/shared_preferences.dart';
+import 'package:flutter/cupertino.dart';
+import '../styles/colors.dart';
+import 'dart:ui';
+import '../styles/totast.dart';
+import '../widget/ITextInput.dart';
+import 'package:flutter_redux/flutter_redux.dart';
+import '../net/HttpManager.dart';
+import '../net/Result.dart';
+import 'HomePage.dart';
+import '../redux/AppState.dart';
+import '../redux/UserRedux.dart';
+import '../model/UserInfo.dart';
+import '../widget/LinearButton.dart';
+
+class LoginSecond extends StatefulWidget {
+  LoginSecond({Key key, this.phone,this.userId=0}) : super(key: key);
+  final String phone; // 用来储存传递过来的值
+  final int userId;
+  @override
+  LoginSecondState createState() => LoginSecondState();
+}
+
+class LoginSecondState extends State<LoginSecond> {
+  String _sessionID;
+  bool isSend = false; //是否发送
+  int sendTime = 0;
+  String inputCode;
+  String useToken;
+  Timer timer;
+
+  @override
+  void initState() {
+    super.initState();
+    Future.delayed(Duration.zero, () {
+      // sendMsg();
+    });
+  }
+
+  @override
+  Widget build(BuildContext context) {
+    return WillPopScope(
+        child: Container(
+          color: BG_SUB_COLOR,
+          child: Scaffold(
+              appBar: AppBar(
+                // backgroundColor: BG_SUB_COLOR,
+                centerTitle: true,
+                elevation: 0,
+              ),
+              body: Container(
+                color: BG_SUB_COLOR,
+                child: CustomScrollView(
+                  slivers: <Widget>[
+                    SliverToBoxAdapter(
+                      child: Container(
+                        color: BG_SUB_COLOR,
+                        padding:
+                            EdgeInsets.symmetric(vertical: 30, horizontal: 15),
+                        child: Column(
+                          crossAxisAlignment: CrossAxisAlignment.start,
+                          children: <Widget>[
+                            Text(
+                              '验证码已发送至',
+                              style: TextStyle(
+                                  color: Colors.white,
+                                  fontSize: 28,
+                                  fontWeight: FontWeight.w600),
+                            ),
+                            Container(
+                              margin: EdgeInsets.only(top: 45),
+                              child: Row(
+                                mainAxisAlignment:
+                                    MainAxisAlignment.spaceBetween,
+                                children: <Widget>[
+                                  Text(widget.phone,
+                                      style: TextStyle(
+                                          color: Theme.of(context).primaryColor,
+                                          fontSize: 20,
+                                          fontWeight: FontWeight.w500)),
+                                  FlatButton(
+                                    highlightColor: BG_SUB_COLOR,
+                                    textColor: PRIMARY_COLOR,
+                                    child:
+                                        Text(isSend ? '($sendTime)秒' : '重新发送'),
+                                    disabledTextColor: Color(0xFF8D8E9C),
+                                    onPressed: isSend
+                                        ? null
+                                        : () {
+                                            if (timer != null) {
+                                              timer.cancel();
+                                            }
+                                            sendMsg();
+                                          },
+                                  )
+                                ],
+                              ),
+                            ),
+                            Container(
+                              margin: EdgeInsets.only(top: 10),
+                              child: ITextField(
+                                maxLength: 6,
+                                keyboardType: ITextInputType.number,
+                                prefixIcon: Container(
+                                  padding: EdgeInsets.all(10),
+                                  // color: PRIMARY_COLOR,
+                                  child: Image.asset(
+                                    'images/list_icon_yanzhengma.png',
+                                    width: 20,
+                                  ),
+                                ),
+                                hintText: '输入短信验证码',
+                                hintStyle: TextStyle(
+                                  fontSize: 16,
+                                  color: Color(0xFF727785),
+                                ),
+                                textStyle: TextStyle(color: Colors.white),
+                                fieldCallBack: (content) {
+                                  setState(() {
+                                    inputCode = content;
+                                  });
+                                },
+                                counterStyle:
+                                    TextStyle(color: BG_SUB_COLOR, fontSize: 0),
+                              ),
+                            ),
+                            Container(height: 20,),
+                            LinearButton(
+                              btntext:'注册/登录',
+                              onTapHomeMenu: () async {
+                                    if (_sessionID == null) {
+                                      Toast.show(
+                                          context, '请发送验证码', 1500, 'info');
+                                    } else if (inputCode.length != 6) {
+                                      Toast.show(
+                                          context, '请输入验证码', 1500, 'info');
+                                    } else {
+                                      Toast.show(context, '加载中', -1, 'loading');
+                                      final Result res = await HttpManager.post(
+                                          'auth/loginSms',
+                                          data: {
+                                            'phone': widget.phone,
+                                            'code': inputCode,
+                                            'sessionId': _sessionID,
+                                            'requireToken': true
+                                          });
+                                      Toast.hide();
+                                      if (res.success) {
+                                        if (timer != null) {
+                                          timer.cancel();
+                                        }
+                                        final prefs = await SharedPreferences
+                                            .getInstance();
+                                        await prefs.setString(
+                                            'token', res.token);
+                                        HttpManager.token = res.token;
+                                        StoreProvider.of<AppState>(context)
+                                            .dispatch(UpdateUserAction(
+                                                UserInfo.fromJson(res.data)));
+
+                                        Toast.show(
+                                            context, '登录成功', 1500, 'success');
+                                        Navigator.pushReplacement(
+                                          context,
+                                          CupertinoPageRoute(
+                                              builder: (context) => HomePage()),
+                                        );
+                                      } else {
+                                        Toast.show(
+                                            context, res.error, 1500, 'info');
+                                      }
+                                    }
+                                  },
+                            ),
+                            
+                          ],
+                        ),
+                      ),
+                    )
+                  ],
+                ),
+              )),
+        ),
+        onWillPop: () {
+          Toast.hide();
+          Navigator.pop(context);
+          return Future.value(false);
+        });
+  }
+
+  Future<void> sendMsg() async {
+    Toast.show(context, '加载中', -1, 'loading');
+    final Result res =
+        await HttpManager.get('rong/sendCode', data: {'phone': widget.phone});
+    Toast.hide();
+    if (res.success) {
+      Toast.show(context, '发送成功', 1500, 'success');
+      _sessionID = res.data;
+      setState(() {
+        isSend = true;
+      });
+      sendTime = 60;
+      timer = Timer.periodic(Duration(seconds: 1), (timer) {
+        if (sendTime == 0) {
+          setState(() {
+            isSend = false;
+          });
+        } else {
+          setState(() {
+            sendTime = sendTime - 1;
+          });
+        }
+      });
+    } else {
+      Toast.show(context, res.error, 1500, 'info');
+    }
+  }
+}