Commit b121299f authored by Deep Dey's avatar Deep Dey

add user login api

parent 696f5a43
...@@ -14,6 +14,12 @@ public class Settings { ...@@ -14,6 +14,12 @@ public class Settings {
@Value("${lamartin.static.server.path}") @Value("${lamartin.static.server.path}")
private String staticServerPath; private String staticServerPath;
@Value("${lamartin.username}")
private String username;
@Value("${lamartin.password}")
private String password;
public String getImageStoragePath() { public String getImageStoragePath() {
return staticResourcesRootPath + "/images/"; return staticResourcesRootPath + "/images/";
} }
......
package com.example.LaMartin.user.controller;
import com.example.LaMartin.admission.model.AdmissionFormData;
import com.example.LaMartin.common.model.GeneralResponse;
import com.example.LaMartin.config.Settings;
import com.example.LaMartin.constants.AppConstants;
import com.example.LaMartin.user.pojo.LoginPayload;
import com.example.LaMartin.user.utills.GenerateKey;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Objects;
@RestController
@AllArgsConstructor(onConstructor = @__(@Autowired))
public class UserController {
private final Settings settings;
@PostMapping(
value = "/user/login",
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
@ApiResponses(value = {
@ApiResponse(code = 200, message = "SUCCESS"),
@ApiResponse(code = 400, message = "FAILED"),
@ApiResponse(code = 500, message = "Exception Occurred")
})
@ApiOperation(value = "")
public Object login(
HttpServletRequest request,
@Valid @RequestBody LoginPayload loginPayload
) throws Exception {
if (Objects.equals(loginPayload.getEmail(), settings.getUsername())
&& Objects.equals(loginPayload.getPassword(), settings.getPassword())) {
return new ResponseEntity<>(
new GeneralResponse(
true,
AppConstants.RESPONSE_SUCCESS_STATUS_CODE,
"Login Successfully",
GenerateKey.randomString(16)
),
HttpStatus.OK);
} else {
return new ResponseEntity<>(
new GeneralResponse(
false,
AppConstants.RESPONSE_FAILURE_STATUS_CODE,
"Failed to Login",
null
),
HttpStatus.OK);
}
}
}
package com.example.LaMartin.user.pojo;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
public class LoginPayload {
private String email;
private String password;
}
package com.example.LaMartin.user.utills;
import java.security.SecureRandom;
public class GenerateKey {
public static String randomString(int len) {
final String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
SecureRandom rnd = new SecureRandom();
StringBuilder sb = new StringBuilder(len);
for (int i = 0; i < len; i++)
sb.append(chars.charAt(rnd.nextInt(chars.length())));
return sb.toString();
}
}
...@@ -13,4 +13,6 @@ spring.mail.port=587 ...@@ -13,4 +13,6 @@ spring.mail.port=587
spring.mail.username=noreply@lamartiniere.co spring.mail.username=noreply@lamartiniere.co
spring.mail.password=xoobqggzxputgvky spring.mail.password=xoobqggzxputgvky
lamartin.static.resources.root.path=D:/WEBSOFTTECHS/webomagic/data lamartin.static.resources.root.path=D:/WEBSOFTTECHS/webomagic/data
lamartin.static.server.path=http://localhost:8084/webomagic-lamartin/ lamartin.static.server.path=http://localhost:8084/webomagic-lamartin/
\ No newline at end of file lamartin.username=admin@lamartiniere.co
lamartin.password=P@$$w0rdLamartin
\ No newline at end of file
logging.level.web=DEBUG
logging.file.name=/opt/Lamartiniere/logs/spring-inside-app.log
logging.level.root=INFO
server.http2.enabled=true
spring.datasource.url=jdbc:postgresql://127.0.0.1:5432/webomagic_lamartin
spring.web.resources.cache.cachecontrol.s-max-age=3600000
spring.datasource.username=magicoweb_user
spring.datasource.password=magicoweb@websoft@2025
spring.redis.host=127.0.0.1
spring.redis.port=6379
spring.mail.host=smtp.gmail.com
spring.mail.port=587
spring.mail.username=noreply@lamartiniere.co
spring.mail.password=xoobqggzxputgvky
lamartin.static.resources.root.path=/opt/Lamartiniere/data
lamartin.static.server.path=https://adm.lamartiniere.co/webomagic-lamartin/
lamartin.username=admin@lamartiniere.co
lamartin.password=P@$$w0rdLamartin
\ No newline at end of file
...@@ -17,5 +17,5 @@ spring.mail.username=noreply@lamartiniere.co ...@@ -17,5 +17,5 @@ spring.mail.username=noreply@lamartiniere.co
spring.mail.password=xoobqggzxputgvky spring.mail.password=xoobqggzxputgvky
lamartin.static.resources.root.path=/home/iitkgpssh/docker/data lamartin.static.resources.root.path=/home/iitkgpssh/docker/data
lamartin.static.server.path=https://adm.lamartiniere.co/webomagic-lamartin/ lamartin.static.server.path=https://adm.lamartiniere.co/webomagic-lamartin/
#lamartin.static.resources.root.path=/home/ubuntu/webomagic_lamartin/data lamartin.username=admin@lamartiniere.co
#lamartin.static.server.path=http://65.0.101.174:8084/webomagic-lamartin/ lamartin.password=P@$$w0rdLamartin
\ No newline at end of file \ No newline at end of file
...@@ -11,4 +11,4 @@ server.servlet.session.timeout=30m ...@@ -11,4 +11,4 @@ server.servlet.session.timeout=30m
server.tomcat.connection-timeout=600000 server.tomcat.connection-timeout=600000
server.tomcat.accept-count=100 server.tomcat.accept-count=100
# application.properties # application.properties
spring.profiles.active=prod spring.profiles.active=hostinger
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment