-
Notifications
You must be signed in to change notification settings - Fork 0
Feat/users registration #22
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
be0e855
feat(core): updated kafka & caches classes for correctly working with…
scobca 51c054d
refactor(service): refactoring code style
scobca 17ea06f
refactor(kafka): update password reset email service for new CachesDto
scobca 92a622e
feat(rpc): updated gRPC .proto
scobca cf31008
feat(service): created pre registration kafka processing service
scobca 91aaeba
feat(service): created mentor-user registration kafka processing service
scobca b6b35a3
feat(cache): created client for temporary passwords cache
scobca 31e2f74
fix(cache): added classes polymorphism
scobca 8f22f23
feat(service): created expert registration kafka processing service
scobca 5f856a2
Update src/main/kotlin/org/careerseekers/csmailservice/dto/CachesDto.kt
scobca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/org/careerseekers/csmailservice/cache/TemporaryPasswordsCache.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.careerseekers.csmailservice.cache | ||
|
||
import org.careerseekers.csmailservice.dto.TemporaryPasswordDto | ||
import org.springframework.cache.CacheManager | ||
import org.springframework.data.redis.core.RedisTemplate | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class TemporaryPasswordsCache( | ||
override val redisTemplate: RedisTemplate<String, TemporaryPasswordDto>, | ||
cacheManager: CacheManager, | ||
) : CacheRetriever<TemporaryPasswordDto> { | ||
override val cacheKey = "temporaryPasswords" | ||
private val cache = cacheManager.getCache(cacheKey) | ||
|
||
override fun getItemFromCache(key: Any): TemporaryPasswordDto? { | ||
val password = cache?.get(key)?.let { | ||
it.get() as? TemporaryPasswordDto | ||
} | ||
|
||
return password | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
src/main/kotlin/org/careerseekers/csmailservice/enums/MailEventTypes.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package org.careerseekers.csmailservice.enums | ||
|
||
enum class MailEventTypes { | ||
REGISTRATION, | ||
PRE_REGISTRATION, | ||
MENTOR_AND_USER_REGISTRATION, | ||
EXPERT_REGISTRATION, | ||
PASSWORD_RESET | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/kotlin/org/careerseekers/csmailservice/services/ExpertRegistrationEmailService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.careerseekers.csmailservice.services | ||
|
||
import org.careerseekers.csmailservice.cache.TemporaryPasswordsCache | ||
import org.careerseekers.csmailservice.dto.EmailSendingTaskDto | ||
import org.careerseekers.csmailservice.enums.MailEventTypes | ||
import org.careerseekers.csmailservice.exceptions.BadRequestException | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.mail.SimpleMailMessage | ||
import org.springframework.mail.javamail.JavaMailSender | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ExpertRegistrationEmailService( | ||
override val mailer: JavaMailSender, | ||
private val temporaryPasswordsCache: TemporaryPasswordsCache, | ||
) : EmailProcessingService { | ||
|
||
@Value("\${spring.mail.username}") | ||
private val senderEmail: String? = null | ||
|
||
override val eventType = MailEventTypes.EXPERT_REGISTRATION | ||
|
||
override fun processEmail(message: EmailSendingTaskDto) { | ||
message.user?.let { user -> | ||
val cacheItem = | ||
temporaryPasswordsCache.getItemFromCache(user.email) ?: throw BadRequestException("Password not found") | ||
|
||
SimpleMailMessage().apply { | ||
from = senderEmail | ||
setTo(user.email) | ||
subject = "Регистрация эксперта в системе Искатели профессий" | ||
text = """ | ||
Уважаемый(-ая) ${user.lastName} ${user.firstName} ${user.patronymic}! | ||
Вас зарегистрировали как Эксперта на чемпионат Искатели профессий. | ||
По ссылке ниже вы можете перейти в личный кабинет Эксперта, где сможете подробно изучить свои возможности и обязанности: | ||
https://github.com/career-seekers | ||
scobca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Реквизиты для входа в личный кабинет: | ||
Логин: ${user.email} | ||
Пароль: ${cacheItem.password} | ||
|
||
Спасибо, | ||
Команда поддержки Искателей профессий. | ||
""".trimIndent() | ||
}.also { | ||
mailer.send(it) | ||
} | ||
} | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
.../kotlin/org/careerseekers/csmailservice/services/MentorAndUserRegistrationEmailService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.careerseekers.csmailservice.services | ||
|
||
import org.careerseekers.csmailservice.dto.EmailSendingTaskDto | ||
import org.careerseekers.csmailservice.enums.MailEventTypes | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.mail.SimpleMailMessage | ||
import org.springframework.mail.javamail.JavaMailSender | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class MentorAndUserRegistrationEmailService( | ||
override val mailer: JavaMailSender | ||
) : EmailProcessingService { | ||
@Value("\${spring.mail.username}") | ||
private val senderEmail: String? = null | ||
|
||
override val eventType = MailEventTypes.MENTOR_AND_USER_REGISTRATION | ||
|
||
override fun processEmail(message: EmailSendingTaskDto) { | ||
message.user?.let { user -> | ||
SimpleMailMessage().apply { | ||
from = senderEmail | ||
setTo(user.email) | ||
subject = "Регистрация наставника в системе Искатели профессий" | ||
text = """ | ||
Уважаемый(-ая) ${user.lastName} ${user.firstName} ${user.patronymic}! | ||
Вы зарегистрировались как наставник чемпионата Искатели профессий. | ||
По ссылке ниже вы можете перейти в личный кабинет Наставника, где можете подробно изучить свои возможности и обязанности: | ||
scobca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
https://github.com/career-seekers | ||
scobca marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Спасибо, | ||
Команда поддержки Искателей профессий. | ||
""".trimIndent() | ||
}.also { | ||
mailer.send(it) | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/kotlin/org/careerseekers/csmailservice/services/PreRegistrationEmailService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.careerseekers.csmailservice.services | ||
|
||
import org.careerseekers.csmailservice.cache.VerificationCodesCache | ||
import org.careerseekers.csmailservice.dto.EmailSendingTaskDto | ||
import org.careerseekers.csmailservice.dto.VerificationCodeDto | ||
import org.careerseekers.csmailservice.enums.MailEventTypes | ||
import org.careerseekers.csmailservice.utils.CodeGenerator.generateVerificationCode | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.mail.SimpleMailMessage | ||
import org.springframework.mail.javamail.JavaMailSender | ||
import org.springframework.security.crypto.password.PasswordEncoder | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class PreRegistrationEmailService( | ||
override val mailer: JavaMailSender, | ||
private val verificationCodesCache: VerificationCodesCache, | ||
private val passwordEncoder: PasswordEncoder, | ||
) : EmailProcessingService { | ||
|
||
@Value("\${spring.mail.username}") | ||
private val senderEmail: String? = null | ||
|
||
override val eventType = MailEventTypes.PRE_REGISTRATION | ||
|
||
override fun processEmail(message: EmailSendingTaskDto) { | ||
message.email?.let { email -> | ||
val code = generateVerificationCode() | ||
verificationCodesCache.loadItemToCache( | ||
VerificationCodeDto( | ||
userEmail = email, | ||
code = passwordEncoder.encode(code), | ||
retries = 0 | ||
) | ||
) | ||
|
||
SimpleMailMessage().apply { | ||
from = senderEmail | ||
setTo(email) | ||
subject = "Регистрация в системе Искатели профессий" | ||
text = """ | ||
Для завершения регистрации введите следующий верификационный код, он действителен в течение 5 минут: $code | ||
Если вы не запрашивали этот код, просто проигнорируйте это письмо. | ||
|
||
Спасибо, | ||
Команда поддержки Искателей профессий. | ||
""".trimIndent() | ||
}.also { | ||
mailer.send(it) | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,5 @@ message User { | |
string role = 9; | ||
int64 avatarId = 10; | ||
bool verified = 11; | ||
bool isMentor = 12; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.