This repository has been archived by the owner on May 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
185 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'package:pocket_cinema/controller/firestore_database.dart'; | ||
|
||
class Validate { | ||
static bool isEmail(String email){ | ||
return RegExp(r"^[a-zA-Z0-9.a-zA-Z0-9.!#$%&'*+-/=?^_`{|}~]+@[a-zA-Z0-9]+\.[a-zA-Z]+") | ||
.hasMatch(email); | ||
} | ||
|
||
static Future<String> login(String userId, String password) async{ | ||
if (userId.isEmpty) { | ||
return Future.error("Please enter your email or username"); | ||
} | ||
if (password.isEmpty) { | ||
return Future.error("Please enter your password"); | ||
} | ||
if(!isEmail(userId)){ | ||
if(!await FirestoreDatabase.usernameExists(userId)){ | ||
return Future.error("The username does not exist"); | ||
} | ||
}else{ | ||
if(!await FirestoreDatabase.emailExists(userId)){ | ||
return Future.error("The email does not exist"); | ||
} | ||
} | ||
return ""; | ||
} | ||
|
||
static Future<String> register(String username, String email, String password, String confirmPassword) async{ | ||
if(username.isEmpty || email.isEmpty || password.isEmpty || confirmPassword.isEmpty) { | ||
return Future.error("There are empty fields"); | ||
} | ||
if(!isEmail(email)) { | ||
return Future.error("Please enter a valid email"); | ||
} | ||
if(password.length < 6) { | ||
return Future.error("Password must be at least 6 characters"); | ||
} | ||
if(password != confirmPassword) { | ||
return Future.error("Passwords do not match"); | ||
} | ||
if(await FirestoreDatabase.emailExists(email)){ | ||
return Future.error("The email already exists"); | ||
} | ||
if(await FirestoreDatabase.usernameExists(username)){ | ||
return Future.error("The username already exists"); | ||
} | ||
|
||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import 'package:firebase_auth/firebase_auth.dart'; | ||
import 'package:pocket_cinema/model/my_user.dart'; | ||
|
||
class ValidateLR { | ||
static String? validateLogin(String? userId, String? password) { | ||
if (userId == null || userId.isEmpty) { | ||
return 'Please enter your email or username'; | ||
} | ||
if (password == null || password.isEmpty) { | ||
return 'Please enter your password'; | ||
} | ||
return null; | ||
} | ||
|
||
static String? validateRegister(String? username, String? email, String? password, String? confirmPassword) { | ||
if (email != null && email.isNotEmpty) { | ||
final RegExp emailRegex = RegExp(r'^.+@[a-zA-Z]+\.{1}[a-zA-Z]+(\.{0,1}[a-zA-Z]+)$'); | ||
if (!emailRegex.hasMatch(email)) { | ||
return 'Please enter a valid email'; | ||
} | ||
} | ||
if (email == null || email.isEmpty) { | ||
return 'Please enter your email'; | ||
} | ||
if (username == null || username.isEmpty) { | ||
return 'Please enter your username'; | ||
} | ||
if (password == null || password.isEmpty) { | ||
return 'Please enter your password'; | ||
} | ||
if (confirmPassword == null || confirmPassword.isEmpty) { | ||
return 'Please confirm your password'; | ||
} | ||
if (password != confirmPassword) { | ||
return 'Passwords do not match'; | ||
} | ||
if (password.length < 6) { | ||
return 'Password must be at least 6 characters'; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters