1
1
package UI ;
2
2
3
+ import Controllers .UserRegistrationUseCase ;
3
4
import UseCase .UserVerifier ;
4
5
import UseCase .verificationMethodFactory ;
5
6
6
7
import javax .swing .*;
7
8
import java .awt .event .ActionEvent ;
8
9
import java .awt .event .ActionListener ;
9
10
import java .util .Random ;
10
- public class UserVerificationUI implements UserVerifier , ActionListener {
11
+ public class UserRegistrationController implements UserVerifier , ActionListener , UserRegistrationUseCase {
12
+ private final String username ;
13
+ private final String password ;
14
+ private final String email ;
15
+ private UserDatabase database ;
11
16
Random random ;
12
17
private final int code ;
13
18
private JTextField verificationCodeText ;
14
19
private JLabel success ;
15
20
16
- public UserVerificationUI (int code ){
21
+ public UserRegistrationController (int code , String Username , String Password , String email , UserDatabase database ){
17
22
this .code = code ;
23
+ this .username = Username ;
24
+ this .password = Password ;
25
+ this .email = email ;
26
+ this .database = database ;
18
27
}
19
28
20
29
//Asks for the verification code from the user, and matches it with this.code to potentially verify the user
21
30
public void verify (String email ){
22
- //Creating the UI to input the verification code
23
31
JFrame verificationFrame = new JFrame ();
24
32
verificationFrame .setSize (400 , 200 );
25
33
verificationFrame .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
@@ -50,6 +58,14 @@ public void verify(String email){
50
58
mailMan .deliverCode ();
51
59
}
52
60
61
+ public void registerUser () {
62
+ if (database .UserExists (this .username , this .email )){
63
+ System .out .println ("A user with this username or email already exists" );
64
+ }else {
65
+ this .verify (email );
66
+ }
67
+ }
68
+
53
69
//For testing purposes
54
70
/*public static void main(String[] args){
55
71
UI.UserVerificationUI ver = new UI.UserVerificationUI(389);
@@ -59,11 +75,11 @@ public void verify(String email){
59
75
@ Override
60
76
public void actionPerformed (ActionEvent e ) {
61
77
int verCode = Integer .parseInt (verificationCodeText .getText ());
62
- if (code == verCode ){
63
- //TODO: Going to change below to a label, and will link to LoginUI
64
- success . setText ( "verified! " );
78
+ if (verCode == this . code ){
79
+ database . createUser ( this . username , this . password , this . email , "Basic" );
80
+ System . out . println ( "Verification successful " );
65
81
}else {
66
- success . setText ( "Try again" );
82
+ System . out . println ( "Could not verify please try again" );
67
83
}
68
84
}
69
85
}
0 commit comments