fix: 因應資料庫欄位修改
1. 使用Username作為primary key 2. Username, Email 皆可作為登入依據
This commit is contained in:
parent
4be851ab86
commit
5cf59af63e
|
|
@ -5,6 +5,8 @@ import 'package:topic/HomePage.dart';
|
||||||
import 'package:mysql_client/mysql_client.dart';
|
import 'package:mysql_client/mysql_client.dart';
|
||||||
import 'package:topic/NoSwipeBackRoute.dart';
|
import 'package:topic/NoSwipeBackRoute.dart';
|
||||||
import 'package:topic/RegisterPage.dart';
|
import 'package:topic/RegisterPage.dart';
|
||||||
|
import 'package:validators/validators.dart' as validator;
|
||||||
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
runApp(MaterialApp(
|
runApp(MaterialApp(
|
||||||
|
|
@ -92,10 +94,20 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
print('输入的密碼: $password');
|
print('输入的密碼: $password');
|
||||||
|
|
||||||
// 查詢數據庫,检查是否有匹配的帳號
|
// 查詢數據庫,检查是否有匹配的帳號
|
||||||
var result = await conn.execute(
|
IResultSet result;
|
||||||
'SELECT * FROM HomeLogin WHERE homeEmail = :email AND homePassword = :password',
|
if (validator.isEmail(email)) {
|
||||||
{'email': email, 'password': password},
|
result = await conn.execute(
|
||||||
);
|
'SELECT * FROM HomeLogin WHERE homeEmail = :email AND homePassword = :password',
|
||||||
|
{'email': email, 'password': password},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
result = await conn.execute(
|
||||||
|
'SELECT * FROM HomeLogin WHERE homeUserName = :email AND homePassword = :password',
|
||||||
|
{'email': email, 'password': password},
|
||||||
|
);
|
||||||
|
email = result.rows.first.colByName("homeEmail").toString();
|
||||||
|
}
|
||||||
|
|
||||||
print('查詢結果行數: ${result.rows.length}');
|
print('查詢結果行數: ${result.rows.length}');
|
||||||
|
|
||||||
|
|
@ -167,7 +179,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
border: OutlineInputBorder(),
|
border: OutlineInputBorder(),
|
||||||
prefixIcon: Icon(Icons.email_outlined),
|
prefixIcon: Icon(Icons.email_outlined),
|
||||||
//https://www.fluttericon.cn/v
|
//https://www.fluttericon.cn/v
|
||||||
labelText: '電子信箱',
|
labelText: '電子信箱/帳號',
|
||||||
),
|
),
|
||||||
), //電子信箱
|
), //電子信箱
|
||||||
SizedBox(height: 20),
|
SizedBox(height: 20),
|
||||||
|
|
@ -220,6 +232,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||||
},
|
},
|
||||||
child: Text('立即註冊'),
|
child: Text('立即註冊'),
|
||||||
style: TextButton.styleFrom(
|
style: TextButton.styleFrom(
|
||||||
|
// TODO: In physical devices, the background color of the button is transparent
|
||||||
backgroundColor: Colors.transparent, // 無背景颜色
|
backgroundColor: Colors.transparent, // 無背景颜色
|
||||||
textStyle: TextStyle(fontSize: 18),
|
textStyle: TextStyle(fontSize: 18),
|
||||||
shadowColor: Colors.transparent, // 去除陰影
|
shadowColor: Colors.transparent, // 去除陰影
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user