mirror of
https://github.com/status-im/status-desktop.git
synced 2025-01-11 06:47:01 +00:00
feat: add authentication modal to join commmunity view
Users that request access to community that are token permissioned need to authenticate and enter their password, so they can reveal their wallet addresses
This commit is contained in:
parent
5e965bcbb7
commit
054ad18532
@ -13,6 +13,9 @@ proc initUniqueUUIDEventEmitter*(events: EventEmitter): UniqueUUIDEventEmitter =
|
||||
result.events = events
|
||||
result.handlerId = genUUID()
|
||||
|
||||
proc emit*(self: UniqueUUIDEventEmitter, name: string, args: Args): void =
|
||||
self.events.emit(name, args)
|
||||
|
||||
proc on*(self: UniqueUUIDEventEmitter, name: string, handler: Handler): void =
|
||||
self.events.onUsingUUID(self.handlerId, name, handler)
|
||||
|
||||
|
@ -14,12 +14,14 @@ import ../../../../app_service/service/wallet_account/service as wallet_account_
|
||||
import ../../../../app_service/service/token/service as token_service
|
||||
import ../../../../app_service/service/community_tokens/service as community_tokens_service
|
||||
import ../../../../app_service/service/visual_identity/service as procs_from_visual_identity_service
|
||||
import ../../shared_modules/keycard_popup/io_interface as keycard_shared_module
|
||||
|
||||
import ../../../core/signals/types
|
||||
import ../../../global/app_signals
|
||||
import ../../../core/eventemitter
|
||||
import ../../../core/unique_event_emitter
|
||||
|
||||
const UNIQUE_MAIN_MODULE_AUTH_IDENTIFIER* = "MainModule-Action-Authentication"
|
||||
|
||||
type
|
||||
Controller* = ref object of RootObj
|
||||
@ -40,6 +42,8 @@ type
|
||||
walletAccountService: wallet_account_service.Service
|
||||
tokenService: token_service.Service
|
||||
communityTokensService: community_tokens_service.Service
|
||||
tmpRequestToJoinCommunityId: string
|
||||
tmpRequestToJoinEnsName: string
|
||||
|
||||
proc newController*(delegate: io_interface.AccessInterface, sectionId: string, isCommunity: bool, events: EventEmitter,
|
||||
settingsService: settings_service.Service, nodeConfigurationService: node_configuration_service.Service,
|
||||
@ -66,6 +70,8 @@ proc newController*(delegate: io_interface.AccessInterface, sectionId: string, i
|
||||
result.walletAccountService = walletAccountService
|
||||
result.tokenService = tokenService
|
||||
result.communityTokensService = communityTokensService
|
||||
result.tmpRequestToJoinCommunityId = ""
|
||||
result.tmpRequestToJoinEnsName = ""
|
||||
|
||||
proc delete*(self: Controller) =
|
||||
self.events.disconnect()
|
||||
@ -79,6 +85,25 @@ proc getIsCurrentSectionActive*(self: Controller): bool =
|
||||
proc setIsCurrentSectionActive*(self: Controller, active: bool) =
|
||||
self.isCurrentSectionActive = active
|
||||
|
||||
proc requestToJoinCommunityAuthenticated*(self: Controller, password: string) =
|
||||
self.communityService.requestToJoinCommunity(self.tmpRequestToJoinCommunityId, self.tmpRequestToJoinEnsName, password)
|
||||
self.tmpRequestToJoinCommunityId = ""
|
||||
self.tmpRequestToJoinEnsName = ""
|
||||
|
||||
proc requestToJoinCommunity*(self: Controller, communityId: string, ensName: string) =
|
||||
self.communityService.requestToJoinCommunity(communityId, ensName, "")
|
||||
|
||||
proc authenticate*(self: Controller, keyUid = "") =
|
||||
let data = SharedKeycarModuleAuthenticationArgs(uniqueIdentifier: UNIQUE_MAIN_MODULE_AUTH_IDENTIFIER,
|
||||
keyUid: keyUid)
|
||||
self.events.emit(SIGNAL_SHARED_KEYCARD_MODULE_AUTHENTICATE_USER, data)
|
||||
|
||||
proc authenticateToRequestToJoinCommunity*(self: Controller, communityId: string, ensName: string) =
|
||||
self.tmpRequestToJoinCommunityId = communityId
|
||||
self.tmpRequestToJoinEnsName = ensName
|
||||
self.authenticate()
|
||||
|
||||
|
||||
proc init*(self: Controller) =
|
||||
self.events.on(SIGNAL_SENDING_SUCCESS) do(e:Args):
|
||||
let args = MessageSendingSuccess(e)
|
||||
@ -147,6 +172,13 @@ proc init*(self: Controller) =
|
||||
self.contactService, self.chatService, self.communityService, self.messageService, self.gifService,
|
||||
self.mailserversService, setChatAsActive = true)
|
||||
|
||||
self.events.on(SIGNAL_SHARED_KEYCARD_MODULE_USER_AUTHENTICATED) do(e: Args):
|
||||
let args = SharedKeycarModuleArgs(e)
|
||||
if args.uniqueIdentifier != UNIQUE_MAIN_MODULE_AUTH_IDENTIFIER:
|
||||
return
|
||||
if self.tmpRequestToJoinCommunityId == self.sectionId:
|
||||
self.delegate.onUserAuthenticated(args.pin, args.password, args.keyUid)
|
||||
|
||||
if (self.isCommunitySection):
|
||||
self.events.on(SIGNAL_COMMUNITY_CHANNEL_CREATED) do(e:Args):
|
||||
let args = CommunityChatArgs(e)
|
||||
|
@ -368,3 +368,9 @@ method onJoinedCommunity*(self: AccessInterface) =
|
||||
|
||||
method onAcceptRequestToJoinFailedNoPermission*(self: AccessInterface, communityId: string, memberKey: string, requestId: string) {.base.} =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method onUserAuthenticated*(self: AccessInterface, pin: string, password: string, keyUid: string) =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
||||
method requestToJoinCommunity*(self: AccessInterface, communityId: string, ensName: string) =
|
||||
raise newException(ValueError, "No implementation available")
|
||||
|
@ -815,6 +815,9 @@ method onKickedFromCommunity*(self: Module) =
|
||||
method onJoinedCommunity*(self: Module) =
|
||||
self.view.setAmIMember(true)
|
||||
|
||||
method onUserAuthenticated*(self: Module, pin: string, password: string, keyUid: string) =
|
||||
self.controller.requestToJoinCommunityAuthenticated(password)
|
||||
|
||||
method onMarkAllMessagesRead*(self: Module, chatId: string) =
|
||||
self.updateBadgeNotifications(chatId, hasUnreadMessages=false, unviewedMentionsCount=0)
|
||||
let chatDetails = self.controller.getChatDetails(chatId)
|
||||
@ -1183,6 +1186,9 @@ method createOrEditCommunityTokenPermission*(self: Module, communityId: string,
|
||||
method deleteCommunityTokenPermission*(self: Module, communityId: string, permissionId: string) =
|
||||
self.controller.deleteCommunityTokenPermission(communityId, permissionId)
|
||||
|
||||
method requestToJoinCommunity*(self: Module, communityId: string, ensName: string) =
|
||||
self.controller.authenticateToRequestToJoinCommunity(communityId, ensName)
|
||||
|
||||
proc buildTokenPermissionItem*(self: Module, tokenPermission: CommunityTokenPermissionDto): TokenPermissionItem =
|
||||
var tokenCriteriaItems: seq[TokenCriteriaItem] = @[]
|
||||
var allTokenCriteriaMet = true
|
||||
|
@ -242,6 +242,9 @@ QtObject:
|
||||
proc createGroupChat*(self: View, communityID: string, groupName: string, pubKeys: string) {.slot.} =
|
||||
self.delegate.createGroupChat(communityID, groupName, pubKeys)
|
||||
|
||||
proc requestToJoinCommunity*(self: View, communityId: string, ensName: string) {.slot.} =
|
||||
self.delegate.requestToJoinCommunity(communityId, ensName)
|
||||
|
||||
proc joinGroupChatFromInvitation*(self: View, groupName: string, chatId: string, adminPK: string) {.slot.} =
|
||||
self.delegate.joinGroupChatFromInvitation(groupName, chatId, adminPK)
|
||||
|
||||
|
@ -123,7 +123,7 @@ proc cancelRequestToJoinCommunity*(self: Controller, communityId: string) =
|
||||
self.communityService.cancelRequestToJoinCommunity(communityId)
|
||||
|
||||
proc requestToJoinCommunity*(self: Controller, communityId: string, ensName: string) =
|
||||
self.communityService.requestToJoinCommunity(communityId, ensName)
|
||||
self.communityService.requestToJoinCommunity(communityId, ensName, password="")
|
||||
|
||||
proc createCommunity*(
|
||||
self: Controller,
|
||||
|
@ -813,9 +813,9 @@ QtObject:
|
||||
error "Error joining the community", msg = e.msg
|
||||
result = fmt"Error joining the community: {e.msg}"
|
||||
|
||||
proc requestToJoinCommunity*(self: Service, communityId: string, ensName: string) =
|
||||
proc requestToJoinCommunity*(self: Service, communityId: string, ensName: string, password: string) =
|
||||
try:
|
||||
let response = status_go.requestToJoinCommunity(communityId, ensName)
|
||||
let response = status_go.requestToJoinCommunity(communityId, ensName, password)
|
||||
self.activityCenterService.parseActivityCenterResponse(response)
|
||||
|
||||
if not self.processRequestsToJoinCommunity(response.result):
|
||||
|
@ -27,10 +27,12 @@ proc getAllCommunities*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
proc spectateCommunity*(communityId: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
result = callPrivateRPC("spectateCommunity".prefix, %*[communityId])
|
||||
|
||||
proc requestToJoinCommunity*(communityId: string, ensName: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
proc requestToJoinCommunity*(communityId: string, ensName: string, password: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
var passwordToSend = password
|
||||
result = callPrivateRPC("requestToJoinCommunity".prefix, %*[{
|
||||
"communityId": communityId,
|
||||
"ensName": ensName
|
||||
"ensName": ensName,
|
||||
"password": if passwordToSend != "": utils.hashPassword(password) else: ""
|
||||
}])
|
||||
|
||||
proc myPendingRequestsToJoin*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
||||
|
@ -3,6 +3,7 @@ import QtQuick.Controls 2.14
|
||||
import QtQuick.Layouts 1.14
|
||||
|
||||
import utils 1.0
|
||||
import shared.popups 1.0
|
||||
|
||||
import "views"
|
||||
import "views/communities"
|
||||
@ -69,7 +70,7 @@ StackLayout {
|
||||
collectiblesModel: root.rootStore.collectiblesModel
|
||||
isInvitationPending: root.rootStore.isCommunityRequestPending(communityData.id)
|
||||
onRevealAddressClicked: {
|
||||
root.rootStore.requestToJoinCommunity(communityData.id, root.rootStore.userProfileInst.name)
|
||||
communityIntroDialog.open()
|
||||
}
|
||||
onInvitationPendingClicked: {
|
||||
root.rootStore.cancelPendingRequest(communityData.id)
|
||||
@ -84,8 +85,28 @@ StackLayout {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CommunityIntroDialog {
|
||||
id: communityIntroDialog
|
||||
|
||||
isInvitationPending: joinCommunityView.isInvitationPending
|
||||
name: communityData.name
|
||||
introMessage: communityData.introMessage
|
||||
imageSrc: communityData.image
|
||||
accessType: communityData.access
|
||||
|
||||
onJoined: {
|
||||
root.rootStore.requestToJoinCommunity(communityData.id, root.rootStore.userProfileInst.name)
|
||||
}
|
||||
|
||||
onCancelMembershipRequest: {
|
||||
root.rootStore.cancelPendingRequest(communityData.id)
|
||||
joinCommunityView.isInvitationPending = root.rootStore.isCommunityRequestPending(communityData.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Component {
|
||||
|
@ -403,7 +403,7 @@ QtObject {
|
||||
}
|
||||
|
||||
function requestToJoinCommunity(id, ensName) {
|
||||
return communitiesModuleInst.requestToJoinCommunity(id, ensName)
|
||||
chatCommunitySectionModule.requestToJoinCommunity(id, ensName)
|
||||
}
|
||||
|
||||
function userCanJoin(id) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user