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