Unverified Commit 4c236125 authored by sarojsingh2021's avatar sarojsingh2021 Committed by GitHub
Browse files

Merge pull request #9 from UPHRH-platform/delete-user-fix

fix requestOTP
No related merge requests found
Showing with 47 additions and 23 deletions
+47 -23
......@@ -564,33 +564,44 @@ public class UserController {
@RequestMapping(value = PathRoutes.UserRoutes.REQUEST_OTP, method = RequestMethod.POST)
public String requestOTP(@RequestBody LoginUser loginUser) throws JsonProcessingException {
if (StringUtils.isNotBlank(loginUser.getUsername())) {
if (userService.checkUserNameExists(loginUser.getUsername(), null) != 0L) {
Boolean authorized = Boolean.FALSE;
// Mobile login validation
if (loginUser.getIsMobile() != null && loginUser.getIsMobile()) {
// Allow only inspector role
List<Role> userRoles = userService.findAllRolesByUser(null, null, loginUser.getUsername());
if (userRoles != null && userRoles.size() > 0) {
for (Role role : userRoles) {
if (role.getName().equalsIgnoreCase(Constants.UserRoles.INSPECTOR.name())) {
authorized = Boolean.TRUE;
break;
User user = userService.getUserByEmailId(loginUser.getUsername());
if(user != null) {
if(!user.getIsDeleted()) {
Boolean authorized = Boolean.FALSE;
// Mobile login validation
if (loginUser.getIsMobile() != null && loginUser.getIsMobile()) {
// Allow only inspector role
List<Role> userRoles = userService.findAllRolesByUser(null, null, loginUser.getUsername());
if (userRoles != null && userRoles.size() > 0) {
for (Role role : userRoles) {
if (role.getName().equalsIgnoreCase(Constants.UserRoles.INSPECTOR.name())) {
authorized = Boolean.TRUE;
break;
}
}
}
} else {
authorized = Boolean.TRUE;
}
} else {
authorized = Boolean.TRUE;
}
// send otp
if (authorized) {
if (userService.requestOTP(loginUser.getUsername())) {
return ResponseGenerator.successResponse("OTP sent successfully!");
// send otp
if (authorized) {
if (userService.requestOTP(loginUser.getUsername())) {
return ResponseGenerator.successResponse("OTP sent successfully!");
}
return ResponseGenerator.failureResponse("Failed to send OTP.");
}
return ResponseGenerator.failureResponse("Failed to send OTP.");
}else {
return ResponseGenerator.failureResponse(Constants.DELETED_USER);
}
}else {
return ResponseGenerator.failureResponse(Constants.UNAUTHORIZED_USER);
}
return ResponseGenerator.failureResponse(Constants.UNAUTHORIZED_USER);
} else {
return ResponseGenerator.failureResponse("Email id missing");
......
......@@ -443,6 +443,7 @@ public class UserDaoImpl implements UserDao {
try {
userId = jdbcTemplate.queryForObject(UserQueries.GET_USER_ID, new Object[] { emailId, emailId, phoneNo },
Long.class);
} catch (Exception e) {
LOGGER.error("Encountered an Exception while finding the UserName Availability : " + e);
}
......
......@@ -28,7 +28,8 @@ public class User {
private String timeZone;
private String avatarUrl;
public String getAvatarUrl() {
return avatarUrl;
}
......
......@@ -67,6 +67,8 @@ public class SqlDataMapper {
user.setUsername(rs.getString("username"));
user.setEmailId(rs.getString("email_id"));
user.setPhoneNo(rs.getString("phone_no"));
user.setIsActive(rs.getBoolean("is_active"));
user.setIsDeleted(rs.getBoolean("is_deleted"));
return user;
}
}
......
......@@ -254,4 +254,6 @@ public interface UserService {
List<InstituteCourses> findAllInstituteCourses(Long userId);
User getUserByEmailId(String emailId);
}
\ No newline at end of file
......@@ -270,6 +270,12 @@ public class UserServiceImpl implements UserDetailsService, UserService {
public Long checkUserNameExists(String emailId, String phoneNo) {
return userDao.checkUserNameExists(emailId, phoneNo);
}
@Override
public User getUserByEmailId(String emailId) {
return userDao.findOnlyUser(emailId);
}
@Override
public Boolean uploadFile(MultipartFile file, long userId) {
......
......@@ -63,6 +63,7 @@ public class Constants {
public static String UNAUTHORIZED = "Invalid credentials. Please try again.";
public static String PROCESS_FAIL = "Process failed, Please try again.";
public static String UNAUTHORIZED_USER = "Unauthorized user";
public static String DELETED_USER = "User Deleted. Please contact Admin to active";
public static final String EXCEPTION_METHOD = "Exception in %s method : %s";
/**
......
......@@ -71,7 +71,7 @@ public interface Sql {
final String SELECT_USER_BY_TOKEN = "SELECT COUNT(*) FROM user_authentication WHERE auth_token = ? ";
final String SELECT_USER_ON_USERNAME = "SELECT * FROM user usr inner join country_user cu on usr.id =cu.user_id inner join country c on cu.country_id = c.id where username=? or phone_no = ?";
final String SELECT_ONLY_USER = "SELECT id, username, password, email_id, phone_no FROM user where username = ? or phone_no = ? ";
final String SELECT_ONLY_USER = "SELECT id, username, password, email_id, phone_no, is_active, is_deleted FROM user where username = ? or phone_no = ? ";
final String MAP_USER_TO_ROLE_WITH_ORG = "INSERT INTO user_role (user_id, role_id, org_id) VALUES (?, ?, ?)";
final String MAP_USER_TO_ROLE = "INSERT INTO user_role (user_id, role_id) VALUES (?, ?)";
......@@ -178,7 +178,7 @@ public interface Sql {
+ " LEFT JOIN role_org ro ON ro.role_id = r.id " + " LEFT JOIN role_actions ra ON r.id = ra.role_id "
+ " LEFT JOIN actions act ON ra.action_id = act.id " + " WHERE usr.username = ? ";
final String GET_USER_ID = "SELECT id FROM user WHERE username = ? OR email_id = ? OR phone_no = ?";
final String GET_USER_ID = "SELECT id FROM user WHERE (username = ? OR email_id = ? OR phone_no = ?) and is_deleted = 0";
final String GET_USER_PROFILE = "SELECT user.id, user.username, user.email_id as emailId, user.phone_no as phoneNo, user.avatar_url as avatarUrl, user_profile.first_name, user_profile.last_name, user_profile.dob FROM user LEFT JOIN user_profile on user_profile.user_id = user.id WHERE (user.username = ? or user.email_id = ? ) and is_active is TRUE";
final String GET_NUMBER_USER_ROLES = "SELECT count(*) as 'numberOfUsers', r.role_name as 'roleName' from user usr LEFT JOIN user_role ur ON usr.id = ur.user_id LEFT JOIN role r ON ur.role_id = r.id where r.id > 2090 group by r.role_name ";
final String SET_USER_PIN = "UPDATE user SET pin=? WHERE id= ?";
......
Supports Markdown
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