Issue 44 - Error message not displaying when customer/admin login fails (Bug fixed)
Issue 45 - No validation for duplicate username during registration (Validation added)
basedata.sql script updated to have UNIQUEusername field
Issue 44 code changes:
In userLogin.jsp, adminlogin.jsp, changed {message} to {msg} since the attribute name defined in UserController.javauserlogin function and AdminController.javaadminlogin function is "msg"
In AdminController.java, added check for user.getRole() != null since without it, the program would throw before entering the if statement (therefore we would be unable to trigger the error message display)
In UserController.java, changed the check from if(u.getUsername().equals(username)) to if(username.equals(u.getUsername())) since the program would throw whenever u.getUsername() is null (therefore we would be unable to enter the if statement and trigger the error message display)
Issue 44 Testing:
Issue 45 code changes:
Changed the basedata.sql script to have a UNIQUE constraint on the username column of the customers table
In models/User, defined a unique constraint on the username field with @Column(unique = true)
In userDao,java, created new function userExists(String username) which returns a boolean
In userService.java, created new function checkUserExists(String username) which calls userExists and returns a boolean
In UserController.javanewUseRegister function, added validation for duplicate usernames. Did this by calling
checkUserExists. Also changed the return type of the function and added code to trigger error messages to display (referenced how to do this from existing code)
In register.jsp, added html for the error message display (referenced how to do this from existing code)
Closes #44, Closes #45
Summary
basedata.sql
script updated to haveUNIQUE
username
fieldIssue 44 code changes:
In
userLogin.jsp
,adminlogin.jsp
, changed{message}
to{msg}
since the attribute name defined inUserController.java
userlogin
function andAdminController.java
adminlogin
function is"msg"
In
AdminController.java
, added check foruser.getRole() != null
since without it, the program would throw before entering the if statement (therefore we would be unable to trigger the error message display)In
UserController.java
, changed the check fromif(u.getUsername().equals(username))
toif(username.equals(u.getUsername()))
since the program would throw wheneveru.getUsername()
is null (therefore we would be unable to enter the if statement and trigger the error message display)Issue 44 Testing:
Issue 45 code changes:
Changed the
basedata.sql
script to have aUNIQUE
constraint on the username column of the customers tableIn
models/User
, defined a unique constraint on the username field with@Column(unique = true)
In
userDao,java
, created new functionuserExists(String username)
which returns a booleanIn
userService.java
, created new functioncheckUserExists(String username)
which callsuserExists
and returns a booleanIn
UserController.java
newUseRegister
function, added validation for duplicate usernames. Did this by callingcheckUserExists
. Also changed the return type of the function and added code to trigger error messages to display (referenced how to do this from existing code)In
register.jsp
, added html for the error message display (referenced how to do this from existing code)Issue 45 Testing: