@@ -12,8 +12,11 @@
import com.swdn.entity.UserEntity;
import com.swdn.error.SwdnErrors;
import com.swdn.exception.SwdnException;
import com.swdn.model.request.ForgetPasswordRequest;
import com.swdn.model.request.LoginRequest;
import com.swdn.model.response.ForgotPasswordResponse;
import com.swdn.model.response.LoginResponse;
import com.swdn.model.response.LogoutResponse;
import com.swdn.service.UserService;

@Service
@@ -28,20 +31,20 @@ public LoginResponse doLogin(LoginRequest loginRequest) throws SwdnException {
User userDto = userDao.getUserDetails(loginRequest.getUserName());

if (userDto == null) {
throw new SwdnException(SwdnErrors.SWDN_LOGIN_ERROR_01.getErrorMessage(),
SwdnErrors.SWDN_LOGIN_ERROR_01.name(), SwdnErrors.SWDN_LOGIN_ERROR_01.getErrorMessage());
throw new SwdnException(SwdnErrors.SWDN_ERROR_01.name(), SwdnErrors.SWDN_ERROR_01.getErrorMessage(),
SwdnErrors.SWDN_ERROR_01.getErrorMessage());
}

if (!loginRequest.getPassword().equals(userDto.getPassword())) {
throw new SwdnException(SwdnErrors.SWDN_LOGIN_ERROR_02.getErrorMessage(),
SwdnErrors.SWDN_LOGIN_ERROR_02.name(), SwdnErrors.SWDN_LOGIN_ERROR_02.getErrorMessage());
throw new SwdnException(SwdnErrors.SWDN_ERROR_02.name(), SwdnErrors.SWDN_ERROR_02.getErrorMessage(),
SwdnErrors.SWDN_ERROR_02.getErrorMessage());
}

UserEntity userEntity = userDao.getUserDetailedInfo(userDto.getId());

if (userEntity == null) {
throw new SwdnException(SwdnErrors.SWDN_LOGIN_ERROR_01.getErrorMessage(),
SwdnErrors.SWDN_LOGIN_ERROR_01.name(), SwdnErrors.SWDN_LOGIN_ERROR_01.getErrorMessage());
throw new SwdnException(SwdnErrors.SWDN_ERROR_01.name(), SwdnErrors.SWDN_ERROR_01.getErrorMessage(),
SwdnErrors.SWDN_ERROR_01.getErrorMessage());
}

Sept sept = userDao.getSeptDetails(userDto.getId());
@@ -61,8 +64,8 @@ public LoginResponse doLogin(LoginRequest loginRequest) throws SwdnException {
loginResponse.setIsSeptCompleted(true);

else if (sept.getSeptStatus().equalsIgnoreCase(SeptStatus.STARTED.name()))
throw new SwdnException(SwdnErrors.SWDN_LOGIN_ERROR_03.getErrorMessage(),
SwdnErrors.SWDN_LOGIN_ERROR_03.name(), SwdnErrors.SWDN_LOGIN_ERROR_03.getErrorMessage());
throw new SwdnException(SwdnErrors.SWDN_ERROR_03.name(), SwdnErrors.SWDN_ERROR_03.getErrorMessage(),
SwdnErrors.SWDN_ERROR_03.getErrorMessage());
}

String token = generateTempToken();
@@ -72,8 +75,11 @@ else if (sept.getSeptStatus().equalsIgnoreCase(SeptStatus.STARTED.name()))
}

@Override
public LoginResponse doLogout(String userName) throws SwdnException {
return null;
public LogoutResponse doLogout(String userToken) throws SwdnException {
userDao.setUserStatusLogout(userToken);
LogoutResponse logoutResponse = new LogoutResponse();
logoutResponse.setUiMessage("User has been logged out successfully");
return logoutResponse;
}

public String generateTempToken() {
@@ -83,4 +89,16 @@ public String generateTempToken() {
return s;
}

@Override
public ForgotPasswordResponse forgetPassword(ForgetPasswordRequest forgetPassRequest) throws SwdnException {
User user = userDao.getUserDetailsByEmailId(forgetPassRequest.getEmailId());
if (user == null)
throw new SwdnException(SwdnErrors.SWDN_ERROR_01.name(), SwdnErrors.SWDN_ERROR_01.getErrorMessage(),
SwdnErrors.SWDN_ERROR_01.getErrorMessage());

ForgotPasswordResponse forgetPasswordResponse =new ForgotPasswordResponse();
forgetPasswordResponse.setUiMessage("Your password has been sent over to your email id");
return forgetPasswordResponse;
}

}
@@ -0,0 +1,47 @@
package com.swdn.utils;

import org.springframework.stereotype.Service;
import org.springframework.validation.BindingResult;

import com.swdn.error.SwdnError;
import com.swdn.error.SwdnErrors;
import com.swdn.exception.SwdnException;
import com.swdn.model.response.SwdnResponse;

@Service
public class SwdnUtils {


public SwdnResponse handleValidationException(SwdnErrors swdnErrors,BindingResult bindingResult) {
SwdnResponse swdnResponse = new SwdnResponse();

String error = bindingResult.getAllErrors().get(0).getDefaultMessage();

SwdnError swdnError = new SwdnError();
swdnError.setErrorCode(swdnErrors.name());
swdnError.setErrorMessage(error);
swdnError.setErrorUiMessage(error);

swdnResponse.setError(swdnError);
return swdnResponse;
}



public SwdnResponse getResponse(Object object, SwdnException exception) {
SwdnResponse swdnResponse = new SwdnResponse();
if (object != null)
swdnResponse.setData(object);
else {
SwdnError swdnError = new SwdnError();
swdnError.setErrorCode(exception.getErrorCode());
swdnError.setErrorMessage(exception.getErrorMessage());
swdnError.setErrorUiMessage(exception.getUiErrorMessage());
swdnResponse.setError(swdnError);
}

return swdnResponse;
}


}