|
17 | 17 | import io.jsonwebtoken.JwtBuilder; |
18 | 18 | import io.jsonwebtoken.Jwts; |
19 | 19 | import io.jsonwebtoken.security.Keys; |
| 20 | +import org.apache.commons.collections4.CollectionUtils; |
20 | 21 | import org.apache.commons.lang3.time.StopWatch; |
21 | 22 | import org.springframework.beans.factory.annotation.Autowired; |
22 | 23 | import org.springframework.data.mongodb.core.FindAndModifyOptions; |
@@ -98,8 +99,13 @@ public LoginResponse getLoginSignUpResponseJson(User user) { |
98 | 99 | user.setPassword(null); |
99 | 100 |
|
100 | 101 | List<Member> orgsForUser = getOrgsForUser(user.getId()); |
| 102 | + if (CollectionUtils.isNotEmpty(orgsForUser)) { |
| 103 | + Member member = orgsForUser.get(0); |
| 104 | + Organization org = getOrganizationForId(member.getOrganizationId()); |
| 105 | + return new LoginResponse("Bearer " + jwtToken, safeUser, org.getSlug(), member.getRole()); |
| 106 | + } |
101 | 107 |
|
102 | | - return new LoginResponse("Bearer " + jwtToken, safeUser); |
| 108 | + return new LoginResponse("Bearer " + jwtToken, safeUser, null, null); |
103 | 109 | } |
104 | 110 |
|
105 | 111 | /** |
@@ -145,6 +151,7 @@ public void sendMagicLink(String to, String linkCode) { |
145 | 151 | + "<h1 style=\"color: #333333;\">Your Verification Code</h1>" |
146 | 152 | + "<p style=\"font-size: 16px; color: #666666;\">Use the following verification code to complete your sign-in process:</p>" |
147 | 153 | + "<p style=\"font-size: 32px; font-weight: bold; color: #007BFF; background-color: #e9ecef; padding: 10px; border-radius: 5px; display: inline-block; text-align: center; margin: 20px 0;\">" + linkCode + "</p>" |
| 154 | + + "<p style=\"font-size: 16px; color: #666666;\">This code is only valid for 10 minutes.</p>" |
148 | 155 | + "<p style=\"font-size: 16px; color: #666666;\">If you didn't request this code, please ignore this email.</p>" |
149 | 156 | + "</div>" |
150 | 157 | + "</body>" |
@@ -223,4 +230,10 @@ public Member getMemberForSlug(String userId, String orgSlug) { |
223 | 230 |
|
224 | 231 | return mongoTemplateFactory.getDefaultMongoTemplate().findOne(new Query(Criteria.where(Member.FIELD_USER_ID).is(userId).and(Member.FIELD_ORGANIZATION_ID).is(organization.getId())), Member.class); |
225 | 232 | } |
| 233 | + |
| 234 | + // Todo: add cache |
| 235 | + private Organization getOrganizationForId(String organizationId) { |
| 236 | + return mongoTemplateFactory.getDefaultMongoTemplate().findOne(new Query(Criteria.where(Organization.FIELD_ID).is(organizationId)), Organization.class); |
| 237 | + } |
| 238 | + |
226 | 239 | } |
0 commit comments