Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix login error. #213

Merged
merged 2 commits into from
Sep 14, 2023
Merged
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
3 changes: 1 addition & 2 deletions frontend/src/pages/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export const Home = () => {
}
}


return (
<div className="home">
<div className="div">
Expand Down Expand Up @@ -91,7 +90,7 @@ export const Home = () => {
{isLoggedIn ? (
<span style={{ color: "black", textDecoration: "none" }}>
<Link
to={"/user/info"}
to={"/home"}
style={{ color: "black", textDecoration: "none" }}
>
{username?.name ? (
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/lpvs/auth/OAuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public OAuth2User loadUser(OAuth2UserRequest userRequest) throws OAuth2Authentic
return new DefaultOAuth2User(Collections.singleton(new SimpleGrantedAuthority("USER")),
customAttribute,
userNameAttributeName);

}

private Map<String, Object> customAttribute(Map<String, Object> attributes, String userNameAttributeName, MemberProfile memberProfile, String registrationId) {
Expand All @@ -62,7 +61,6 @@ private Map<String, Object> customAttribute(Map<String, Object> attributes, Stri
customAttribute.put("name", memberProfile.getName());
customAttribute.put("email", memberProfile.getEmail());
return customAttribute;

}

private LPVSMember saveOrUpdate(MemberProfile memberProfile) {
Expand All @@ -73,5 +71,4 @@ private LPVSMember saveOrUpdate(MemberProfile memberProfile) {

return lpvsMemberRepository.save(lpvsMember);
}

}
6 changes: 6 additions & 0 deletions src/main/java/com/lpvs/entity/LPVSMember.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,10 @@ public void setNickname(String nickname) {
public void setOrganization(String organization) {
this.organization = organization;
}

public void setJoin(String name, String email, String provider) {
this.name = name;
this.email = email;
this.provider = provider;
}
}
16 changes: 13 additions & 3 deletions src/main/java/com/lpvs/service/LPVSLoginCheckService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
import org.springframework.security.core.Authentication;
import org.springframework.security.oauth2.core.user.OAuth2User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;
import java.util.Optional;

@Service
public class LPVSLoginCheckService {
Expand Down Expand Up @@ -44,14 +46,22 @@ public void loginVerification(Authentication authentication) {
}
}

@Transactional
public LPVSMember getMemberFromMemberMap(Authentication authentication) {
Map<String, Object> memberMap = getOauthLoginMemberMap(authentication);
String name = (String) memberMap.get("name");
String email = (String) memberMap.get("email");
String provider = (String) memberMap.get("provider");

LPVSMember findMember = memberRepository.findByEmailAndProvider(email, provider).get();
Optional<LPVSMember> findMemberOptional = memberRepository.findByEmailAndProvider(email, provider);

return findMember;
if (findMemberOptional.isPresent()) {
return findMemberOptional.get();
} else {
LPVSMember newMember = new LPVSMember();
newMember.setJoin(name, email, provider);
memberRepository.save(newMember);
return newMember;
}
}

}
Loading