ログイン機能

This commit is contained in:
s-sakiyama
2026-10-22 15:55:31 +09:00
parent 85d1d3715b
commit 5a5bfd9112
2 changed files with 20 additions and 1 deletions

View File

@@ -1,5 +1,7 @@
package com.example.demo.repository;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
@@ -8,5 +10,7 @@ import com.example.demo.entity.EmployeeEntity;
@Repository
public interface EmployeeRepository extends JpaRepository<EmployeeEntity, Integer> {
//メールアドレスとパスワードに合致するレコード
Optional<EmployeeEntity> findByMailAddressAndPassword(String mailAddress, String password);
}

View File

@@ -11,6 +11,7 @@ import org.springframework.stereotype.Service;
import com.example.demo.entity.Book_collectionEntity;
import com.example.demo.entity.Borrow_booksEntity;
import com.example.demo.form.LendingForm;
import com.example.demo.form.LoginInfoForm;
import com.example.demo.form.ReturnForm;
import com.example.demo.form.SearchConditionBookForm;
import com.example.demo.model.LeadingListModel;
@@ -176,4 +177,18 @@ public class ReturnService {
}
//メアドとパスワードが合っていればtureで返す
public boolean canlogin(String mail, String pass) {
if (mail == null || mail.isEmpty() || pass == null || pass.isEmpty()) {
return false;
}
return employeeRepository.findByMailAddressAndPassword(mail, pass).isPresent();
}
//LoginInfoFormの情報からidEmployeeを返す
public int getUserID(LoginInfoForm form) {
return employeeRepository.findByMailAddressAndPassword(form.getMailAddress(), form.getPassword()).get()
.getIdEmployee();
}
}