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 b7c248d commit 02d4459
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
40 changes: 20 additions & 20 deletions html_frontend/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@

function login() {
if(validateLoginForm()){
var api_url = 'http://149.165.171.50:30008/api/login?username='+document.getElementById("username_login").value+'&password='+document.getElementById("password_login").value+"&social=&firstname=&lastname";
var api_url = 'http://149.165.171.50:30008/api/login?username='+document.getElementById("username_login").value+'&password='+document.getElementById("password_login").value+'&social=&firstname=&lastname=';
$.ajax({
type:'get',
dataType:'json',
Expand Down Expand Up @@ -270,25 +270,25 @@
var lastname = profile.getFamilyName();


// var api_url = 'http://149.165.171.50:30008/api/googlelogin?username='+username+'&firstname='+firstname+'&lastname='+lastname;
// $.ajax({
// type:'get',
// dataType:'json',
// url: api_url,
// success: function(user) {
// console.log(user);
// window.sessionStorage.setItem("user",user.userId);
// window.location.href = "dashboard/dashboard.html";
// },
// error: function (textStatus, errorThrown) {
// var login_form_validation = document.getElementById("login_form_validation");
// login_form_validation.innerHTML = "Login Error";
// login_form_validation.style.display = "block";
// login_form_validation.parentNode.style.backgroundColor = "#FFDFDF";
// console.log(textStatus);
// console.log(errorThrown);
// }
// });
var api_url = 'http://149.165.171.50:30008/api/login?username='+username+'&password=&social=yes&firstname='+firstname+'&lastname='+lastname;
$.ajax({
type:'get',
dataType:'json',
url: api_url,
success: function(user) {
console.log(user);
window.sessionStorage.setItem("user",user.userId);
window.location.href = "dashboard/dashboard.html";
},
error: function (textStatus, errorThrown) {
var login_form_validation = document.getElementById("login_form_validation");
login_form_validation.innerHTML = "Login Error";
login_form_validation.style.display = "block";
login_form_validation.parentNode.style.backgroundColor = "#FFDFDF";
console.log(textStatus);
console.log(errorThrown);
}
});
}
</script>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,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){
if(social == "") {
if(!social.matches("yes")) {
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
// String hashedPassword = passwordEncoder.encode(password);
Optional<User> user = userRepository.findAllByUserName(username);
Expand All @@ -94,16 +94,16 @@ public ResponseEntity<User> login(@RequestParam("username") String username, @Re
return new ResponseEntity<>(user.get(),HttpStatus.OK);
}
}
User user = new User();
user.setFirstName(firstName);
user.setLastName(lastName);
user.setUserName(username);
User new_user = new User();
new_user.setFirstName(firstName);
new_user.setLastName(lastName);
new_user.setUserName(username);
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String userId = generateUniqueId().toString();
user.setUserId(userId);
new_user.setUserId(userId);
String hashedPassword = passwordEncoder.encode(userId);
user.setPassword(hashedPassword);
userRepository.save(user);
new_user.setPassword(hashedPassword);
userRepository.save(new_user);
Optional<User> user_list = userRepository.findAllByUserName(username);
return new ResponseEntity<>(user_list.get(), HttpStatus.OK);
}
Expand Down

0 comments on commit 02d4459

Please sign in to comment.