Skip to content

Commit

Permalink
#95
Browse files Browse the repository at this point in the history
  • Loading branch information
vanessapinto257 committed Apr 25, 2019
1 parent 192ad78 commit b7c248d
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public User createUser(@Valid @RequestBody User user) {

@CrossOrigin
@RequestMapping("/login")
public ResponseEntity<User> login(@RequestParam("username") String username, @RequestParam("password") String password, @RequestParam("social") String social, @RequestParam("firstname") String firstname, @RequestParam("lastname") String lastname, HttpServletRequest request, Model m, HttpSession session){
public ResponseEntity<User> login(@RequestParam("username") String username, @RequestParam("password") String password, @RequestParam("social") String social, @RequestParam("firstname") String firstName, @RequestParam("lastname") String lastName, HttpServletRequest request, Model m, HttpSession session){
if(social == "") {
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
// String hashedPassword = passwordEncoder.encode(password);
Expand All @@ -86,7 +86,28 @@ public ResponseEntity<User> login(@RequestParam("username") String username, @Re
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
}
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
else {
Optional<User> userlist = userRepository.findAllByUserName(username);
if(userlist.isPresent()) {
Optional<User> user = userRepository.findAllByUserName(username);
if(user.get().getUserName().equals(username)) {
return new ResponseEntity<>(user.get(),HttpStatus.OK);
}
}
User user = new User();
user.setFirstName(firstName);
user.setLastName(lastName);
user.setUserName(username);
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String userId = generateUniqueId().toString();
user.setUserId(userId);
String hashedPassword = passwordEncoder.encode(userId);
user.setPassword(hashedPassword);
userRepository.save(user);
Optional<User> user_list = userRepository.findAllByUserName(username);
return new ResponseEntity<>(user_list.get(), HttpStatus.OK);
}
// return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}

@CrossOrigin
Expand Down

0 comments on commit b7c248d

Please sign in to comment.