Both Volunteers and C and D Waste included in this project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
5.7 KiB

2 years ago
​
​
2 years ago
​
2 years ago
​
​
​
2 years ago
2 years ago
​
​
​
2 years ago
2 years ago
​
2 years ago
​
​
​
​
2 years ago
​
​
2 years ago
​
​
​
​
2 years ago
​
​
2 years ago
2 years ago
2 years ago
​
2 years ago
2 years ago
2 years ago
​
2 years ago
​
2 years ago
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
2 years ago
2 years ago
2 years ago
2 years ago
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
​
​
2 years ago
2 years ago
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
2 years ago
2 years ago
  1. package com.volunteersregistration.controller;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.core.env.Environment;
  4. import org.springframework.http.HttpStatus;
  5. import org.springframework.http.ResponseEntity;
  6. import org.springframework.web.bind.annotation.GetMapping;
  7. import org.springframework.web.bind.annotation.PostMapping;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RequestParam;
  10. import org.springframework.web.bind.annotation.RestController;
  11. import org.springframework.web.client.RestTemplate;
  12. import org.springframework.web.multipart.MultipartFile;
  13. import com.volunteersregistration.config.AppConfigur;
  14. import com.volunteersregistration.config.UserSession;
  15. import com.volunteersregistration.entity.LoginDetail;
  16. import com.volunteersregistration.repository.LoginDetailRepo;
  17. import com.volunteersregistration.repository.VolunteerRegistrationRepo;
  18. import jakarta.servlet.http.HttpServletRequest;
  19. import jakarta.servlet.http.HttpSession;
  20. import java.io.IOException;
  21. import java.nio.file.Files;
  22. import java.nio.file.Path;
  23. import java.nio.file.Paths;
  24. import java.time.LocalDateTime;
  25. import java.time.format.DateTimeFormatter;
  26. import java.util.ArrayList;
  27. import java.util.Collections;
  28. import java.util.HashMap;
  29. import java.util.List;
  30. import java.util.Map;
  31. import java.util.Random;
  32. @RestController("volunteerapicontroller")
  33. @RequestMapping("/volunteer/api/registration")
  34. public class ApiController {
  35. @Autowired
  36. private HttpSession session;
  37. @Autowired
  38. private Environment environment;
  39. @Autowired
  40. private LoginDetailRepo logindetailrepo;
  41. @Autowired
  42. private UserSession usersession;
  43. @Autowired
  44. private AppConfigur appConfig;
  45. @Autowired
  46. private VolunteerRegistrationRepo volunteerRegistrationRepo;
  47. //for login
  48. @GetMapping(value = "/login")
  49. public String login(HttpServletRequest request, @RequestParam String uname, @RequestParam String upass) {
  50. LoginDetail ld = logindetailrepo.checkUser(Long.parseLong(uname), upass);
  51. if (ld != null) {
  52. session.setAttribute("userId", ld.getId()); // Store user in session
  53. session.setAttribute("mobNo", ld.getMobileno());
  54. session.setAttribute("userType", ld.getUsertype());
  55. return ld.getUsertype(); // Return user type to redirect appropriately
  56. } else {
  57. return "Error"; // Return error if login fails
  58. }
  59. }
  60. @GetMapping(value = "/sendOTP")
  61. public String sendOtp(HttpServletRequest request, @RequestParam String mobile,@RequestParam String purpose) {
  62. String MobileNo=mobile;
  63. System.out.print("\n MobileNo---:"+mobile);
  64. Random rand = new Random();
  65. int otp = rand.nextInt(90000) + 10000;
  66. System.out.print("\n otp---:"+otp);
  67. DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm");
  68. LocalDateTime now = LocalDateTime.now();
  69. System.out.println(dtf.format(now));
  70. String generatedToken = "Welcome to GCC "+otp+" is your OTP for gcc QR System";
  71. // String key="qxg4mklD";
  72. String key="pfTEYN6H";
  73. String urlString= appConfig.getGetOtpUrl()+"from=GCCCRP&key="+key+"&sender=GCCCRP&to="+MobileNo+"&body="+generatedToken+"&entityid=1401572690000011081&templateid=1407168250479102852";
  74. // String urlString=appConfig.getGetOtpUrl()+"user=GCCtrans&authkey=92kOC1RBGBIws&sender=GCCCRP&mobile="+MobileNo+"&text="+generatedToken+"&rpt=1&summary=1&output=json&entityid=1401572690000011081&templateid=1407168250479102852";
  75. System.out.print("\n urlString---: "+urlString);
  76. String bodyMessage = "";
  77. try {
  78. RestTemplate restTemplate = new RestTemplate();
  79. String Response = restTemplate.getForObject(urlString, String.class);
  80. bodyMessage=Response;
  81. System.out.println("\n bodyMessage"+bodyMessage);
  82. System.out.println("OTP sent successfully!");
  83. } catch (Exception e) {
  84. System.out.print("ERROR---: "+e);
  85. bodyMessage = "Error";
  86. }
  87. HttpSession session = request.getSession();
  88. session.setAttribute("otp", otp);
  89. return bodyMessage;
  90. }
  91. @GetMapping(value = "/verifyOTP")
  92. public String verifyOtp(HttpServletRequest request, @RequestParam String otp) {
  93. HttpSession session = request.getSession();
  94. try {
  95. Integer session_otp = (Integer) session.getAttribute("otp");
  96. System.out.println("session_otp---:" + session_otp);
  97. Integer entered_otp = Integer.parseInt(otp);
  98. if (session_otp != null && session_otp.equals(entered_otp)) {
  99. System.out.println("Entered OTP Correct");
  100. session.setAttribute("verifiedotp", "success");
  101. return "Success";
  102. } else {
  103. System.out.println("Incorrect OTP. Please enter correct OTPs.");
  104. session.setAttribute("verifiedotp", "error");
  105. return "Error";
  106. }
  107. } catch (NumberFormatException e) {
  108. System.out.println("Invalid OTP format: " + otp);
  109. return "Error";
  110. } catch (Exception e) {
  111. System.out.println("Error verifying OTP: " + e.getMessage());
  112. return "Error";
  113. }
  114. }
  115. @GetMapping(value = "/getAllCategory")
  116. public List<Map<String, Object>> getAllCategory() {
  117. return volunteerRegistrationRepo.getAllCategory();
  118. }
  119. @GetMapping(value = "/getSubCategoryById")
  120. public List<Map<String, Object>> getSubCategoryById(@RequestParam int category_id) {
  121. return volunteerRegistrationRepo.getSubCategoryById(category_id);
  122. }
  123. }