Skip to content
Snippets Groups Projects
Commit c12c7f4d authored by Sarthak Shrivastava's avatar Sarthak Shrivastava
Browse files

added changepassword

parent 9c97d89e
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,9 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
import java.util.Optional;
@Controller // This means that this class is a Controller
@RequestMapping(path="/user") // This means URL's start with /demo (after Application path)
public class MainController {
......@@ -35,12 +38,17 @@ public class MainController {
@ResponseBody
public User updateUser(@RequestBody Map<String, String> json)
{
if (json.get("email"))
if (json.get("email") != null)
{
User user = userRepository.findById(json.get("email"));
user.setPassword(json.get("password"));
userRepository.save(user);
return user;
Optional<User> user = userRepository.findById(json.get("email"));
if (user.isPresent())
{
User usr = user.get();
usr.setPassword(json.get("password"));
userRepository.save(usr);
return usr;
}
return null;
}
return null;
}
......
......@@ -8,6 +8,6 @@ import com.example.accessingdatamysql.User;
// This will be AUTO IMPLEMENTED by Spring into a Bean called userRepository
// CRUD refers Create, Read, Update, Delete
public interface UserRepository extends CrudRepository<User, Integer> {
public interface UserRepository extends CrudRepository<User, String> {
}
\ No newline at end of file
......@@ -2,6 +2,6 @@
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/inventory
spring.datasource.username=root
spring.datasource.password=
spring.datasource.password=czarthak
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
#spring.jpa.show-sql: true
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment