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.
|
|
package com.volunteersregistration.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;import org.springframework.http.ResponseEntity;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestParam;import org.springframework.web.bind.annotation.RestController;import org.springframework.web.client.RestTemplate;import org.springframework.web.multipart.MultipartFile;
import com.volunteersregistration.config.AppConfigur;import com.volunteersregistration.config.UserSession;import com.volunteersregistration.entity.LoginDetail;
import com.volunteersregistration.repository.LoginDetailRepo;import com.volunteersregistration.repository.VolunteerRegistrationRepo;
import jakarta.servlet.http.HttpServletRequest;import jakarta.servlet.http.HttpSession;
import java.io.IOException;import java.nio.file.Files;import java.nio.file.Path;import java.nio.file.Paths;import java.time.LocalDateTime;import java.time.format.DateTimeFormatter;import java.util.ArrayList;import java.util.Collections;import java.util.HashMap;import java.util.List;import java.util.Map;import java.util.Random;
@RestController("volunteerapicontroller")@RequestMapping("/volunteer/api/registration")public class ApiController {
@Autowired private HttpSession session; @Autowired private Environment environment; @Autowired private LoginDetailRepo logindetailrepo; @Autowired private UserSession usersession; @Autowired private AppConfigur appConfig;
@Autowired private VolunteerRegistrationRepo volunteerRegistrationRepo; //for login
@GetMapping(value = "/login") public String login(HttpServletRequest request, @RequestParam String uname, @RequestParam String upass) { LoginDetail ld = logindetailrepo.checkUser(Long.parseLong(uname), upass); if (ld != null) { session.setAttribute("userId", ld.getId()); // Store user in session
session.setAttribute("mobNo", ld.getMobileno()); session.setAttribute("userType", ld.getUsertype());
return ld.getUsertype(); // Return user type to redirect appropriately
} else { return "Error"; // Return error if login fails
} } @GetMapping(value = "/sendOTP") public String sendOtp(HttpServletRequest request, @RequestParam String mobile,@RequestParam String purpose) { String MobileNo=mobile; System.out.print("\n MobileNo---:"+mobile); Random rand = new Random(); int otp = rand.nextInt(90000) + 10000; System.out.print("\n otp---:"+otp); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd-MMM-yyyy%20HH:mm"); LocalDateTime now = LocalDateTime.now(); System.out.println(dtf.format(now));
String generatedToken = "Welcome to GCC "+otp+" is your OTP for gcc QR System";// String key="qxg4mklD";
String key="pfTEYN6H"; String urlString= appConfig.getGetOtpUrl()+"from=GCCCRP&key="+key+"&sender=GCCCRP&to="+MobileNo+"&body="+generatedToken+"&entityid=1401572690000011081&templateid=1407168250479102852";// String urlString=appConfig.getGetOtpUrl()+"user=GCCtrans&authkey=92kOC1RBGBIws&sender=GCCCRP&mobile="+MobileNo+"&text="+generatedToken+"&rpt=1&summary=1&output=json&entityid=1401572690000011081&templateid=1407168250479102852";
System.out.print("\n urlString---: "+urlString); String bodyMessage = ""; try { RestTemplate restTemplate = new RestTemplate(); String Response = restTemplate.getForObject(urlString, String.class); bodyMessage=Response; System.out.println("\n bodyMessage"+bodyMessage); System.out.println("OTP sent successfully!");
} catch (Exception e) { System.out.print("ERROR---: "+e); bodyMessage = "Error"; } HttpSession session = request.getSession(); session.setAttribute("otp", otp); return bodyMessage;
}
@GetMapping(value = "/verifyOTP") public String verifyOtp(HttpServletRequest request, @RequestParam String otp) { HttpSession session = request.getSession(); try { Integer session_otp = (Integer) session.getAttribute("otp"); System.out.println("session_otp---:" + session_otp); Integer entered_otp = Integer.parseInt(otp);
if (session_otp != null && session_otp.equals(entered_otp)) { System.out.println("Entered OTP Correct"); session.setAttribute("verifiedotp", "success"); return "Success"; } else { System.out.println("Incorrect OTP. Please enter correct OTPs."); session.setAttribute("verifiedotp", "error"); return "Error"; } } catch (NumberFormatException e) { System.out.println("Invalid OTP format: " + otp); return "Error"; } catch (Exception e) { System.out.println("Error verifying OTP: " + e.getMessage()); return "Error"; } } @GetMapping(value = "/getAllCategory") public List<Map<String, Object>> getAllCategory() { return volunteerRegistrationRepo.getAllCategory(); } @GetMapping(value = "/getSubCategoryById") public List<Map<String, Object>> getSubCategoryById(@RequestParam int category_id) { return volunteerRegistrationRepo.getSubCategoryById(category_id); }
}
|