-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a16f9ae
commit ef32c82
Showing
13 changed files
with
375 additions
and
39 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/com/faforever/userservice/backend/security/CurrentUserService.kt
This file contains 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,30 @@ | ||
package com.faforever.userservice.backend.security | ||
|
||
import com.faforever.userservice.backend.domain.User | ||
import io.quarkus.security.identity.SecurityIdentity | ||
import jakarta.inject.Singleton | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
|
||
@Singleton | ||
class CurrentUserService( | ||
private val securityIdentity: SecurityIdentity, | ||
) { | ||
companion object { | ||
private val log: Logger = LoggerFactory.getLogger(CurrentUserService::class.java) | ||
} | ||
|
||
// TODO: Implement Vaadin auth mechanism and reload from database or something | ||
fun requireUser(): User = User( | ||
5, | ||
"zep", | ||
"thisshouldnotbehere", | ||
email = "iam@faforever.com", | ||
null, | ||
) | ||
|
||
fun invalidate() { | ||
log.debug("Invalidating current user") | ||
// TODO: Invalidate cache | ||
} | ||
} |
This file contains 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
56 changes: 56 additions & 0 deletions
56
src/main/kotlin/com/faforever/userservice/backend/security/PasswordService.kt
This file contains 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,56 @@ | ||
package com.faforever.userservice.backend.security | ||
|
||
import com.faforever.userservice.backend.domain.User | ||
import com.faforever.userservice.backend.domain.UserRepository | ||
import com.faforever.userservice.backend.metrics.MetricHelper | ||
import com.faforever.userservice.config.FafProperties | ||
import jakarta.enterprise.context.ApplicationScoped | ||
import org.slf4j.Logger | ||
import org.slf4j.LoggerFactory | ||
|
||
@ApplicationScoped | ||
class PasswordService( | ||
private val fafProperties: FafProperties, | ||
private val metricHelper: MetricHelper, | ||
private val userRepository: UserRepository, | ||
private val passwordEncoder: PasswordEncoder, | ||
) { | ||
|
||
companion object { | ||
private val log: Logger = LoggerFactory.getLogger(FafTokenService::class.java) | ||
} | ||
|
||
enum class ValidatePasswordResult { | ||
VALID, | ||
TOO_SHORT, | ||
} | ||
|
||
fun validatePassword(password: String) = | ||
if (password.length < fafProperties.security().minimumPasswordLength()) { | ||
ValidatePasswordResult.TOO_SHORT | ||
} else { | ||
ValidatePasswordResult.VALID | ||
} | ||
|
||
enum class ChangePasswordResult { | ||
OK, | ||
PASSWORD_MISMATCH, | ||
} | ||
|
||
fun changePassword(user: User, oldPassword: String, newPassword: String): ChangePasswordResult { | ||
if (!passwordEncoder.matches(oldPassword, user.passwordHash)) { | ||
return ChangePasswordResult.PASSWORD_MISMATCH | ||
} | ||
|
||
userRepository.persist( | ||
user.copy( | ||
passwordHash = passwordEncoder.encode(newPassword), | ||
), | ||
) | ||
metricHelper.userPasswordChangeCounter.increment() | ||
|
||
log.info("Password of user ${user.id} was changed") | ||
|
||
return ChangePasswordResult.OK | ||
} | ||
} |
This file contains 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
80 changes: 80 additions & 0 deletions
80
src/main/kotlin/com/faforever/userservice/ui/layout/UcpLayout.kt
This file contains 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,80 @@ | ||
package com.faforever.userservice.ui.layout | ||
|
||
import com.faforever.userservice.backend.i18n.I18n | ||
import com.faforever.userservice.ui.view.ucp.AccountDataView | ||
import com.vaadin.flow.component.Component | ||
import com.vaadin.flow.component.applayout.AppLayout | ||
import com.vaadin.flow.component.applayout.DrawerToggle | ||
import com.vaadin.flow.component.html.Anchor | ||
import com.vaadin.flow.component.html.H1 | ||
import com.vaadin.flow.component.html.Span | ||
import com.vaadin.flow.component.icon.Icon | ||
import com.vaadin.flow.component.icon.VaadinIcon | ||
import com.vaadin.flow.component.tabs.Tab | ||
import com.vaadin.flow.component.tabs.Tabs | ||
import com.vaadin.flow.router.RouterLayout | ||
import com.vaadin.flow.router.RouterLink | ||
import kotlin.reflect.KClass | ||
|
||
abstract class UcpLayout( | ||
private val i18n: I18n, | ||
) : AppLayout(), RouterLayout { | ||
|
||
init { | ||
val toggle = DrawerToggle() | ||
|
||
val title = H1("FAF User Control Panel") | ||
title.style.set("font-size", "var(--lumo-font-size-l)")["margin"] = "0" | ||
|
||
// createLinks().forEach(::addToDrawer) | ||
addToDrawer(getTabs()) | ||
addToNavbar(toggle, title) | ||
} | ||
|
||
private fun buildAnchor(href: String, i18nKey: String, icon: VaadinIcon) = | ||
Anchor().apply { | ||
setHref(href) | ||
add(icon.create()) | ||
// add(i18n.getTranslation(i18nKey)) | ||
add(i18nKey) | ||
} | ||
|
||
private fun getTabs(): Tabs { | ||
val tabs = Tabs() | ||
tabs.add( | ||
createTab(VaadinIcon.USER_CARD, "Account Data", AccountDataView::class), | ||
createTab(VaadinIcon.LINK, "Account Links", AccountDataView::class, false), | ||
createTab(VaadinIcon.DESKTOP, "Active Devices", AccountDataView::class, false), | ||
createTab(VaadinIcon.USER_HEART, "Friends & Foes", AccountDataView::class, false), | ||
createTab(VaadinIcon.TROPHY, "Avatars", AccountDataView::class, false), | ||
createTab(VaadinIcon.FILE_ZIP, "Uploaded content", AccountDataView::class, false), | ||
createTab(VaadinIcon.SWORD, "Moderation Reports", AccountDataView::class, false), | ||
createTab(VaadinIcon.KEY_O, "Permissions", AccountDataView::class, false), | ||
createTab(VaadinIcon.BAN, "Ban history", AccountDataView::class, false), | ||
createTab(VaadinIcon.EXIT_O, "Delete Account", AccountDataView::class, false), | ||
) | ||
tabs.orientation = Tabs.Orientation.VERTICAL | ||
return tabs | ||
} | ||
|
||
private fun createTab( | ||
viewIcon: VaadinIcon, | ||
viewName: String, | ||
route: KClass<out Component>, | ||
enabled: Boolean = true, | ||
): Tab { | ||
val icon: Icon = viewIcon.create() | ||
icon.getStyle().set("box-sizing", "border-box") | ||
.set("margin-inline-end", "var(--lumo-space-m)") | ||
.set("margin-inline-start", "var(--lumo-space-xs)") | ||
.set("padding", "var(--lumo-space-xs)") | ||
val link = RouterLink() | ||
link.add(icon, Span(viewName)) | ||
// Demo has no routes | ||
link.setRoute(route.java) | ||
link.tabIndex = -1 | ||
return Tab(link).apply { | ||
isEnabled = enabled | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.