Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.yash.yotaapi.dto.PasswordDto;
import com.yash.yotaapi.dto.YotaUserDto;
import com.yash.yotaapi.exceptions.ApplicationException;
import com.yash.yotaapi.security.jwt.JwtAuthRequest;
import com.yash.yotaapi.security.jwt.JwtAuthResponse;
import com.yash.yotaapi.services.IServices.IAuthService;
import com.yash.yotaapi.services.IServices.IYOTAUserService;
import com.yash.yotaapi.util.ValidationUtility;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -28,8 +30,16 @@ public class LoginSignUpController {
@Autowired
private IYOTAUserService userService;

@Autowired
private ValidationUtility validationUtility;

@PostMapping("/login")
public ResponseEntity<JwtAuthResponse> login(@RequestBody JwtAuthRequest authRequest) {

if(!validationUtility.validateEmail(authRequest.getEmail())) {
throw new ApplicationException("Email must contain @ and end with @yash.com.");
}

JwtAuthResponse authResponse = this
.authService
.login(authRequest);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.yash.yotaapi.util;

import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Component
public class ValidationUtility {

private static final String ALPHABETIC_PATTERN = "^[a-zA-Z]+$";
Expand Down Expand Up @@ -31,4 +36,13 @@ public static boolean isEndDateGreater(Date startDate, Date endDate) {
}
return true;
}

public boolean validateEmail(String email) {
if (email == null || email.isEmpty()) {
return false;
}
Pattern regexPattern = Pattern.compile("^[^@\\s]+@yash\\.com$");
Matcher regMatcher = regexPattern.matcher(email);
return regMatcher.matches();
}
}