Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Team 14 - IDATT1002
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eirik Steira
Team 14 - IDATT1002
Commits
6f1baa94
Commit
6f1baa94
authored
5 years ago
by
Lars Brodin Østby
Committed by
Mads Lundegaard
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Signup with valid input
parent
d8439bea
No related branches found
No related tags found
1 merge request
!165
Weekly merge to Master
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/NTNU/IDATT1002/controllers/SignUp.java
+90
-34
90 additions, 34 deletions
src/main/java/NTNU/IDATT1002/controllers/SignUp.java
src/main/java/NTNU/IDATT1002/service/UserService.java
+5
-0
5 additions, 0 deletions
src/main/java/NTNU/IDATT1002/service/UserService.java
with
95 additions
and
34 deletions
src/main/java/NTNU/IDATT1002/controllers/SignUp.java
+
90
−
34
View file @
6f1baa94
...
...
@@ -6,24 +6,17 @@ import java.time.LocalDate;
import
java.time.ZoneId
;
import
java.util.ArrayList
;
import
java.util.Date
;
import
java.util.Optional
;
import
NTNU.IDATT1002.App
;
import
NTNU.IDATT1002.service.UserService
;
import
java.util.regex.Pattern
;
import
javafx.event.ActionEvent
;
import
javafx.scene.control.Button
;
import
javafx.scene.control.DatePicker
;
import
javafx.scene.control.PasswordField
;
import
javafx.scene.control.TextField
;
import
javafx.scene.layout.GridPane
;
import
javafx.scene.text.Text
;
import
javax.persistence.EntityManager
;
import
java.io.IOException
;
import
java.time.Instant
;
import
java.time.LocalDate
;
import
java.time.ZoneId
;
import
java.util.Date
;
/**
* Controls the buttons and changeable elements on signup.fxml,
...
...
@@ -42,10 +35,9 @@ public class SignUp {
public
TextField
signup_phoneNr
;
public
DatePicker
signup_birthDate
;
public
Text
signup_error
;
public
UserService
userService
;
public
Button
signup_btn
;
private
boolean
check
;
public
SignUp
()
{
EntityManager
entityManager
=
App
.
ex
.
getEntityManager
();
...
...
@@ -74,34 +66,98 @@ public class SignUp {
signupFields
.
add
(
signup_password
);
signupFields
.
add
(
signup_phoneCode
);
signupFields
.
add
(
signup_phoneNr
);
boolean
blank
=
false
;
for
(
TextField
signupField
:
signupFields
)
{
if
(
signupField
.
getText
().
trim
().
isEmpty
()){
signupField
.
setPromptText
(
"*"
);
signupField
.
setStyle
(
"-fx-prompt-text-fill: red"
);
blank
=
true
;
}
}
LocalDate
birthLocalDate
=
signup_birthDate
.
getValue
()
;
if
(
validateInfo
(
username
,
firstName
,
lastName
,
email
,
password
,
phoneCode
,
phoneNr
,
birthLocalDate
))
{
{
Instant
instant
=
Instant
.
from
(
birthLocalDate
.
atStartOfDay
(
ZoneId
.
systemDefault
()));
Date
birthDate
=
Date
.
from
(
instant
);
if
(
signup_birthDate
.
getValue
()
==
null
){
signup_birthDate
.
setPromptText
(
"*"
);
signup_error
.
setText
(
"* fields required to sign up"
);
if
(
userService
.
createUser
(
email
,
username
,
firstName
,
lastName
,
phoneCode
,
phoneNr
,
birthDate
,
password
).
isPresent
())
{
//TODO: Return message to user to confirm that user has been succsessfully registered
App
.
setRoot
(
"login"
);
}
}}
}
else
if
(
blank
)
{
signup_error
.
setText
(
"* fields required to sign up"
);
public
void
cancel
(
ActionEvent
event
)
throws
IOException
{
App
.
setRoot
(
"login"
);
}
else
{
LocalDate
birthLocalDate
=
signup_birthDate
.
getValue
();
Instant
instant
=
Instant
.
from
(
birthLocalDate
.
atStartOfDay
(
ZoneId
.
systemDefault
()));
Date
birthDate
=
Date
.
from
(
instant
);
if
(
userService
.
createUser
(
email
,
username
,
firstName
,
lastName
,
phoneCode
,
phoneNr
,
birthDate
,
password
).
isPresent
())
{
//TODO: Return message to user to confirm that user has been succsessfully registered
App
.
setRoot
(
"login"
);
/**
* Checks both that the user put info in the necessary textfields and that the username and/or email isnt in use.
*
* @param username
* @param firstName
* @param lastName
* @param email
* @param password
* @param phoneCode
* @param phoneNR
* @param birthdate
*
*/
private
boolean
validateInfo
(
String
username
,
String
firstName
,
String
lastName
,
String
email
,
String
password
,
String
phoneCode
,
String
phoneNR
,
LocalDate
birthdate
){
check
=
true
;
userService
.
getUsers
().
stream
().
forEach
(
x
->
{
if
(
x
.
getUsername
().
equals
(
username
))
{
signup_username
.
clear
();
signup_username
.
setStyle
(
"-fx-prompt-text-fill: red"
);
signup_username
.
setPromptText
(
"Username already taken"
);
check
=
false
;
}
});
userService
.
getUsers
().
stream
().
forEach
(
x
->
{
if
(
x
.
getEmail
().
equals
(
email
))
{
signup_username
.
clear
();
signup_username
.
setStyle
(
"-fx-prompt-text-fill: red"
);
signup_username
.
setPromptText
(
"Email is already in use"
);
check
=
false
;
}
});
if
(
username
.
isEmpty
()){
signup_username
.
setStyle
(
"-fx-prompt-text-fill: red"
);
signup_username
.
setPromptText
(
"Please enter a username"
);
check
=
false
;
}
if
(
firstName
.
isEmpty
()){
signup_firstName
.
setStyle
(
"-fx-prompt-text-fill: red"
);
signup_firstName
.
setPromptText
(
"Please enter your firstname"
);
check
=
false
;
}
if
(
lastName
.
isEmpty
()){
signup_lastName
.
setStyle
(
"-fx-prompt-text-fill: red"
);
signup_lastName
.
setPromptText
(
"Please enter your surname"
);
check
=
false
;
}
if
(
email
.
isEmpty
()){
signup_email
.
setStyle
(
"-fx-prompt-text-fill: red"
);
signup_email
.
setPromptText
(
"Please enter your email"
);
check
=
false
;
}
if
(
password
.
isEmpty
()){
signup_password
.
setStyle
(
"-fx-prompt-text-fill: red"
);
signup_password
.
setPromptText
(
"Please enter a password"
);
check
=
false
;
}
if
(
phoneCode
.
isEmpty
()
||
!(
Pattern
.
matches
(
"[0-9]+"
,
phoneCode
))){
signup_phoneCode
.
clear
();
signup_phoneCode
.
setStyle
(
"-fx-prompt-text-fill: red"
);
signup_phoneCode
.
setPromptText
(
"Please enter phnoe code"
);
check
=
false
;
}
if
(
phoneNR
.
isEmpty
()
||
!(
Pattern
.
matches
(
"[0-9]+"
,
phoneNR
))){
signup_phoneNr
.
clear
();
signup_phoneNr
.
setStyle
(
"-fx-prompt-text-fill: red"
);
signup_phoneNr
.
setPromptText
(
"Please enter your phone number"
);
check
=
false
;
}
if
(
birthdate
==
null
){
signup_birthDate
.
setStyle
(
"-fx-prompt-text-fill: red"
);
signup_birthDate
.
setPromptText
(
"Please enter your birthdate"
);
check
=
false
;
}
return
check
;
}
}
public
void
cancel
(
ActionEvent
event
)
throws
IOException
{
App
.
setRoot
(
"login"
);
}
}
This diff is collapsed.
Click to expand it.
src/main/java/NTNU/IDATT1002/service/UserService.java
+
5
−
0
View file @
6f1baa94
...
...
@@ -7,6 +7,7 @@ import NTNU.IDATT1002.repository.LoginRepository;
import
NTNU.IDATT1002.repository.UserRepository
;
import
NTNU.IDATT1002.utils.Authentication
;
import
java.util.List
;
import
javax.persistence.EntityManager
;
import
java.util.ArrayList
;
import
java.util.Date
;
...
...
@@ -126,4 +127,8 @@ public class UserService {
}
return
false
;
}
public
List
<
User
>
getUsers
(){
return
userRepository
.
findAll
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment