Skip to content

Commit

Permalink
Student/Teacher/Officer | Password Operations APIs | SIS-115 (#63)
Browse files Browse the repository at this point in the history
* Department Status Enum Class Has Been Added to DepartmentSqlScripts Class

* TeacherLessonMapping Class Has Been Refactored

* TeacherLesson GET Endpoint Has Been Updated

* Get All By Status Methods Have Been Updated

* STUDENT_PASSWORD_OPERATION_API_TAG Has Been Added to SisSwaggerConfiguration Class

* feUrl Field Has Been Added to SisOperationInfoRequest Class

* STUDENT_PASSWORD_OPERATION Endpoint Has Been Added to SisControllerEndpoint Class

* unauthorizedResponse Method Has Been Added to SisResponseUtil Class

* ForgotPasswordResponse Class Has Been Deleted

* PasswordOutService Classes Have Been Created

* StudentLoginMapping Class Has Been Moved to common Package

* StudentLoginInfoEntity Class Has Been Moved to common Package

* StudentLoginRequest Class Has Been Moved to common Package

* StudentLogin Repository Classes Have Been Moved to common Package

* StudentLogin Service Classes Have Been Moved to common Package and forgotPassword Method Has Been Deleted Because Method Has Been Moved to PasswordOperationService

* StudentLoginController Class Has Been Moved to common Package

* StudentLogin Out Service Classes Have Been Created

* StudentPasswordOperationMapping Class Has Been Created

* StudentPasswordChangeEntity Class Has Been Created

* StudentPasswordOperationEntity Class Has Been Created

* StudentPasswordChangeRequest Class Has Been Created

* StudentPasswordForgotRequest Class Has Been Moved to password Package

* Student Password Operation Response Classes Have Been Created

* StudentPasswordOperationInfoConverter Class Has Been Created

* Student Password Operation Repository Classes Have Been Created

* Student Password Operation Service Classes Have Been Created

* Student Password Operation Controller Classes Have Been Created

* Student Password Operation Out Service Classes Have Been Created

* getStudentInfoDetailResponse Method Has Been Added to StudentOutService

* ChangePassword URL Has Been Added to Student Mails && Service Codes Has Been Refactored and Updated

* Password Operations Have Been Added to Student Saving Processes

* Teacher Login Operation Classes Have Been Moved to common Package

* TEACHER_PASSWORD_OPERATION_API_TAG Has Been Added to SisSwaggerConfiguration Class

* TEACHER_PASSWORD_OPERATION Endpoint Have Been Added to SisControllerEndpoint Class

* final Key Has Been Added to studentId Parameter in isPasswordExist Method

* final Key Has Been Added to studentId Parameter in getStudentInfoDetailResponse Method

* Teacher Login Repository Classes Have Been Updated

* Teacher/forgotPassword Method Has Been Deleted Because Method Has Been Added to password Package

* final Key Has Been Added to academicInfoResponse and personalInfoResponse Parameters in convert Method

* throws SisNotExistException Has Been Added to saveTeacher Method

* teacherForgotPassword Method Has Been Deleted Because Method Has Been Added to password Package

* Teacher Login Out Service Classes Have Been Created

* getTeacherInfoDetailResponse and ifTeacherIsNotExistThrowNotExistException Methods Have Been Added to Teacher Out Service

* throws SisNotExistException Has Been Added to saveTeacher Method

* TeacherPasswordOperationMapping Class Has Been Created

* TeacherPasswordOperation Request Classes Have Been Created

* TeacherPasswordOperation Entity Classes Have Been Created

* TeacherPasswordOperationInfoConverter Class Has Been Created

* TeacherPasswordOperation Repository Classes Have Been Created

* TeacherPasswordOperation Response Classes Have Been Created

* TeacherPasswordOperation Service Classes Have Been Created

* TeacherPasswordOperation Controller Classes Have Been Created

* TeacherPasswordOperation Out Service Classes Have Been Created

* ChangePassword URL Has Been Added to Teacher Mails && Service Codes Has Been Refactored and Updated

* Password Operations Have Been Added to Teacher Saving Processes

* Officer Login Operation Classes Have Been Moved to common Package

* TeacherLogin Service Classes Have Been Updated

* PasswordService Bean Has Been Deleted in TeacherLoginRepository Because It's Unused

* officerForgotPassword Method Has Been Deleted Because It's Unused

* OFFICER_PASSWORD_OPERATION Endpoint Has Been Added to SisControllerEndpoint Class

* OFFICER_PASSWORD_OPERATION_API_TAG Has Been Added to SisSwaggerConfiguration Class

* throws SisNotExistException Has Been Added to saveOfficer Method

* throws SisNotExistException Has Been Deleted Because It's Unused

* OfficerPasswordOperationMapping Class Has Been Created

* OfficerPasswordChangeEntity and OfficerPasswordOperationEntity Classes Have Been Created

* OfficerPasswordChangeRequest and OfficerPasswordForgotRequest Classes Have Been Created

* OfficerPasswordChangeResponse, OfficerPasswordForgotResponse and OfficerPasswordOperationResponse Classes Have Been Created

* OfficerPasswordOperationInfoConverter Class Has Been Created

* OfficerPasswordOperation Repository Classes Have Been Created

* OfficerPasswordOperation Service Classes Have Been Created

* OfficerPasswordOperation Controller Classes Have Been Created

* OfficerPasswordOperation Out Service Classes Have Been Created

* OfficerLogin Repository Classes Have Been Updated and isPasswordExist Method Has Been Added to OfficerLogin Repository Classes

* OfficerLogin Out Service Classes Have Been Created

* Officer Out Service Classes Have Been Created

* ChangePassword URL Has Been Added to Officer Mails && Service Codes Has Been Refactored and Updated

* Password Operations Have Been Added to Officer Saving Processes
  • Loading branch information
agitrubard authored Mar 1, 2022
1 parent be7dcd9 commit 9c3c610
Show file tree
Hide file tree
Showing 119 changed files with 2,602 additions and 436 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class SisSwaggerConfiguration {
public static final String TEACHER_LESSON_API_TAG = "Teacher Lesson Controller";
public static final String OFFICER_API_TAG = "Officer Controller";
public static final String LOGIN_API_TAG = "Login Controller";
public static final String STUDENT_PASSWORD_OPERATION_API_TAG = "Student Password Operation Controller";
public static final String TEACHER_PASSWORD_OPERATION_API_TAG = "Teacher Password Operation Controller";
public static final String OFFICER_PASSWORD_OPERATION_API_TAG = "Officer Password Operation Controller";

@Bean
public Docket api() {
Expand All @@ -51,7 +54,10 @@ public Docket api() {
new Tag(TEACHER_API_TAG, "TEACHER_ACADEMIC_INFO & TEACHER_PERSONAL_INFO"),
new Tag(TEACHER_LESSON_API_TAG, "TEACHER_LESSON"),
new Tag(OFFICER_API_TAG, "OFFICER_ACADEMIC_INFO & OFFICER_PERSONAL_INFO"),
new Tag(LOGIN_API_TAG, "AUTH_STUDENT_LOGIN & AUTH_TEACHER_LOGIN & AUTH_OFFICER_LOGIN")
new Tag(LOGIN_API_TAG, "AUTH_STUDENT_LOGIN & AUTH_TEACHER_LOGIN & AUTH_OFFICER_LOGIN"),
new Tag(STUDENT_PASSWORD_OPERATION_API_TAG, "AUTH_STUDENT_PASSWORD_OPERATION"),
new Tag(TEACHER_PASSWORD_OPERATION_API_TAG, "AUTH_TEACHER_PASSWORD_OPERATION"),
new Tag(OFFICER_PASSWORD_OPERATION_API_TAG, "AUTH_OFFICER_PASSWORD_OPERATION")
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ public class SisOperationInfoRequest implements Serializable {
@NotNull
@OperationUserID
private Long userId;

private String feUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ private Path() {
}

private static final String REGISTRATION = "/registration";
private static final String PASSWORD_OPERATION = "/password-operation";

public static final String FACULTY = "/faculty";
public static final String DEPARTMENT = "/department";
Expand All @@ -23,5 +24,8 @@ private Path() {
public static final String TEACHER_LESSON = TEACHER + LESSON;
public static final String OFFICER = "/officer";
public static final String LOGIN = "/login";
public static final String STUDENT_PASSWORD_OPERATION = STUDENT + PASSWORD_OPERATION;
public static final String TEACHER_PASSWORD_OPERATION = TEACHER + PASSWORD_OPERATION;
public static final String OFFICER_PASSWORD_OPERATION = OFFICER + PASSWORD_OPERATION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ public static ResponseEntity<SisApiResponse> successResponse() {
.isSuccess(true).build(), HttpStatus.OK);
}

public static ResponseEntity<SisApiResponse> unauthorizedResponse() {
return new ResponseEntity<>(
SisApiResponse.builder()
.requestTime(LocalDateTime.now())
.httpStatus(HttpStatus.UNAUTHORIZED)
.isSuccess(false).build(), HttpStatus.UNAUTHORIZED);
}

public static <T> ResponseEntity<SisBaseApiResponse<T>> successResponse(final T response) {
return new ResponseEntity<>(
SisBaseApiResponse.<T>builder()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.graduationproject.studentinformationsystem.login.common.service;

public interface PasswordOutService {

String getEncodedPassword(String newPassword);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.graduationproject.studentinformationsystem.login.common.service.impl;

import com.graduationproject.studentinformationsystem.login.common.service.PasswordOutService;
import com.graduationproject.studentinformationsystem.login.common.service.PasswordService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class PasswordOutServiceImpl implements PasswordOutService {

private final PasswordService passwordService;

@Override
public String getEncodedPassword(String newPassword) {
return passwordService.encodePassword(newPassword);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.graduationproject.studentinformationsystem.login.officer.controller;
package com.graduationproject.studentinformationsystem.login.officer.common.controller;

import com.graduationproject.studentinformationsystem.common.util.controller.response.SisBaseApiResponse;
import com.graduationproject.studentinformationsystem.common.util.exception.SisNotExistException;
import com.graduationproject.studentinformationsystem.login.common.controller.enpoint.LoginControllerEndpoint;
import com.graduationproject.studentinformationsystem.login.common.model.response.ForgotPasswordResponse;
import com.graduationproject.studentinformationsystem.login.common.model.response.LoginResponse;
import com.graduationproject.studentinformationsystem.login.officer.model.dto.request.OfficerForgotPasswordRequest;
import com.graduationproject.studentinformationsystem.login.officer.model.dto.request.OfficerLoginRequest;
import com.graduationproject.studentinformationsystem.login.officer.service.OfficerLoginService;
import com.graduationproject.studentinformationsystem.login.officer.common.model.dto.request.OfficerLoginRequest;
import com.graduationproject.studentinformationsystem.login.officer.common.service.OfficerLoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -39,14 +36,4 @@ public ResponseEntity<SisBaseApiResponse<LoginResponse>> officerLogin(
final LoginResponse loginResponse = loginService.login(loginRequest);
return successResponse(loginResponse);
}

@PostMapping(LoginControllerEndpoint.OFFICER_FORGOT_PASSWORD)
@ApiOperation(value = "Officer Forgot Password")
public ResponseEntity<SisBaseApiResponse<ForgotPasswordResponse>> officerForgotPassword(
@RequestBody @Valid final OfficerForgotPasswordRequest forgotPasswordRequest)
throws SisNotExistException {

final ForgotPasswordResponse forgotPasswordResponse = loginService.forgotPassword(forgotPasswordRequest);
return successResponse(forgotPasswordResponse);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graduationproject.studentinformationsystem.login.officer.model.dto.request;
package com.graduationproject.studentinformationsystem.login.officer.common.model.dto.request;

import com.graduationproject.studentinformationsystem.common.util.validation.id.OfficerID;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graduationproject.studentinformationsystem.login.officer.model.dto.request;
package com.graduationproject.studentinformationsystem.login.officer.common.model.dto.request;

import com.graduationproject.studentinformationsystem.common.util.validation.id.OfficerID;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graduationproject.studentinformationsystem.login.officer.model.entity;
package com.graduationproject.studentinformationsystem.login.officer.common.model.entity;

import com.graduationproject.studentinformationsystem.common.model.entity.SisBaseLoginInfoEntity;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graduationproject.studentinformationsystem.login.officer.model.mapping;
package com.graduationproject.studentinformationsystem.login.officer.common.model.mapping;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package com.graduationproject.studentinformationsystem.login.officer.repository;
package com.graduationproject.studentinformationsystem.login.officer.common.repository;

import com.graduationproject.studentinformationsystem.login.officer.model.entity.OfficerLoginInfoEntity;
import com.graduationproject.studentinformationsystem.login.officer.common.model.entity.OfficerLoginInfoEntity;

public interface OfficerLoginRepository {

Integer getFailCounter(Long officerId);

String getPassword(Long officerId);

void saveFirstPassword(Long officerId, String password);
void savePassword(Long officerId, String encodedPassword);

void updatePassword(Long officerId, String password);
void updatePassword(Long officerId, String encodedPassword);

void updateLoginInfo(OfficerLoginInfoEntity loginInfoEntity);

void updateFailCounter(Long officerId);

boolean isPasswordExist(Long officerId);
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
package com.graduationproject.studentinformationsystem.login.officer.repository.impl;
package com.graduationproject.studentinformationsystem.login.officer.common.repository.impl;

import com.graduationproject.studentinformationsystem.common.util.exception.SisDatabaseException;
import com.graduationproject.studentinformationsystem.login.common.service.PasswordService;
import com.graduationproject.studentinformationsystem.login.officer.model.entity.OfficerLoginInfoEntity;
import com.graduationproject.studentinformationsystem.login.officer.repository.OfficerLoginRepository;
import com.graduationproject.studentinformationsystem.login.officer.common.model.entity.OfficerLoginInfoEntity;
import com.graduationproject.studentinformationsystem.login.officer.common.repository.OfficerLoginRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import org.sql2o.Connection;
import org.sql2o.Query;
import org.sql2o.Sql2o;

import static com.graduationproject.studentinformationsystem.login.officer.model.mapping.OfficerLoginMapping.*;
import static com.graduationproject.studentinformationsystem.login.officer.repository.impl.scripts.OfficerLoginSqlScripts.*;
import static com.graduationproject.studentinformationsystem.login.officer.common.model.mapping.OfficerLoginMapping.*;
import static com.graduationproject.studentinformationsystem.login.officer.common.repository.impl.scripts.OfficerLoginSqlScripts.*;

@Repository
@RequiredArgsConstructor
public class OfficerLoginRepositoryImpl implements OfficerLoginRepository {

private final PasswordService passwordService;

private final Sql2o sql2o;

@Override
Expand Down Expand Up @@ -52,11 +49,11 @@ public String getPassword(final Long officerId) {
}

@Override
public void saveFirstPassword(final Long officerId, final String password) {
public void savePassword(final Long officerId, final String encodedPassword) {
try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(SAVE_OFFICER_FIRST_PASSWORD)) {

query.addParameter(OFFICER_ID.getModelName(), officerId)
.addParameter(PASSWORD.getModelName(), passwordService.encodePassword(password))
.addParameter(PASSWORD.getModelName(), encodedPassword)
.addParameter(FAIL_COUNTER.getModelName(), 0)
.executeUpdate();

Expand All @@ -68,11 +65,12 @@ public void saveFirstPassword(final Long officerId, final String password) {
}

@Override
public void updatePassword(final Long officerId, final String password) {
public void updatePassword(final Long officerId, final String encodedPassword) {
try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_OFFICER_PASSWORD)) {

query.addParameter(OFFICER_ID.getModelName(), officerId)
.addParameter(PASSWORD.getModelName(), passwordService.encodePassword(password))
.addParameter(PASSWORD.getModelName(), encodedPassword)
.addParameter(FAIL_COUNTER.getModelName(), 0)
.executeUpdate();

// TODO: Specific Info Log Must be Added
Expand Down Expand Up @@ -113,21 +111,17 @@ public void updateFailCounter(final Long officerId) {
}
}

// TODO: Change or Update Password
// @Override
// public void updatePassword(final OfficerLoginInfoEntity loginInfoEntity) {
// try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(UPDATE_OFFICER_PASSWORD)) {
//
// query.addParameter(OFFICER_ID.getModelName(), loginInfoEntity.getOfficerId())
// .addParameter(PASSWORD.getModelName(), loginInfoEntity.getPassword())
// .addParameter(FAIL_COUNTER.getModelName(), loginInfoEntity.getFailCounter())
// .addParameter(LAST_LOGIN_DATE.getModelName(), loginInfoEntity.getLastLoginDate())
// .executeUpdate();
//
@Override
public boolean isPasswordExist(final Long officerId) {
try (final Connection connection = sql2o.open(); final Query query = connection.createQuery(IS_OFFICER_PASSWORD_EXIST)) {

return query.addParameter(OFFICER_ID.getModelName(), officerId)
.executeScalar(Boolean.class);

// TODO: Specific Info Log Must be Added
// } catch (Exception exception) {
} catch (Exception exception) {
// TODO: Specific Error Log Must be Added
// throw new SisDatabaseException(exception);
// }
// }
throw new SisDatabaseException(exception);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.graduationproject.studentinformationsystem.login.officer.repository.impl.scripts;
package com.graduationproject.studentinformationsystem.login.officer.common.repository.impl.scripts;

public class OfficerLoginSqlScripts {

Expand Down Expand Up @@ -30,11 +30,12 @@ private OfficerLoginSqlScripts() {
" FAIL_COUNTER=:failCounter").toString();

/**
* UPDATE AUTH_OFFICER_LOGIN SET PASSWORD=:password WHERE OFFICER_ID=:officerId;
* UPDATE AUTH_OFFICER_LOGIN SET PASSWORD=:password, FAIL_COUNTER=:failCounter WHERE OFFICER_ID=:officerId;
*/
public static final String UPDATE_OFFICER_PASSWORD =
sqlBuilder.delete(0, sqlBuilder.length())
.append("UPDATE AUTH_OFFICER_LOGIN SET PASSWORD=:password WHERE OFFICER_ID=:officerId").toString();
.append("UPDATE AUTH_OFFICER_LOGIN SET PASSWORD=:password, FAIL_COUNTER=:failCounter " +
"WHERE OFFICER_ID=:officerId").toString();

/**
* UPDATE AUTH_OFFICER_LOGIN SET FAIL_COUNTER=:failCounter, LAST_LOGIN_DATE=:lastLoginDate
Expand All @@ -52,4 +53,14 @@ private OfficerLoginSqlScripts() {
sqlBuilder.delete(0, sqlBuilder.length())
.append("UPDATE AUTH_OFFICER_LOGIN SET FAIL_COUNTER=:failCounter " +
"WHERE OFFICER_ID=:officerId").toString();

/**
* SELECT CASE WHEN MAX(OFFICER_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST
* FROM AUTH_OFFICER_LOGIN WHERE OFFICER_ID=:officerId;
*/
public static final String IS_OFFICER_PASSWORD_EXIST =
sqlBuilder.delete(0, sqlBuilder.length())
.append("SELECT CASE WHEN MAX(OFFICER_ID) IS NULL THEN 'false' ELSE 'true' END IS_EXIST " +
"FROM AUTH_OFFICER_LOGIN WHERE OFFICER_ID=:officerId").toString();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.graduationproject.studentinformationsystem.login.officer.common.service;

public interface OfficerLoginOutService {

void saveOrUpdatePassword(Long officerId, String encodedPassword);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.graduationproject.studentinformationsystem.login.officer.common.service;

import com.graduationproject.studentinformationsystem.login.common.model.response.LoginResponse;
import com.graduationproject.studentinformationsystem.login.officer.common.model.dto.request.OfficerLoginRequest;

public interface OfficerLoginService {

LoginResponse login(OfficerLoginRequest loginRequest);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.graduationproject.studentinformationsystem.login.officer.common.service.impl;

import com.graduationproject.studentinformationsystem.login.officer.common.repository.OfficerLoginRepository;
import com.graduationproject.studentinformationsystem.login.officer.common.service.OfficerLoginOutService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class OfficerLoginOutServiceImpl implements OfficerLoginOutService {

private final OfficerLoginRepository officerLoginRepository;

@Override
public void saveOrUpdatePassword(final Long officerId, final String encodedPassword) {

boolean isPasswordExist = officerLoginRepository.isPasswordExist(officerId);

if (!isPasswordExist) {
officerLoginRepository.savePassword(officerId, encodedPassword);
} else {
officerLoginRepository.updatePassword(officerId, encodedPassword);
}
}
}
Loading

0 comments on commit 9c3c610

Please sign in to comment.