public AuthenticationResponse Authentication(ISession session, AuthenticationRequest request) { var respone = request.CreateResponse <AuthenticationResponse>(); if (string.IsNullOrEmpty(request.AccessToken) || string.IsNullOrEmpty(request.DeviceId)) { respone.Success = false; return(respone); } if (!_accessTokenFastValidator.Validate(request.AccessToken, request.DeviceId, request.UserId)) { respone.Success = false; respone.Error = Errors.AccessTokenInvalid; return(respone); } if (_devicesRepository.GetDevices(request.UserId).All(d => d != request.DeviceId)) { respone.Success = false; respone.Error = Errors.DeviceRegistrationRequired; return(respone); } session.AssignUser(request.AccessToken, request.DeviceId, request.UserId); respone.ServerInfo = GetServerInfo(); _childrenControllers.ForEach(c => c.OnAuthenticating(session, respone)); _server.OnSessionAuthenticated(session); Task.Delay(500).ContinueWith(r => _childrenControllers.ForEach(c => c.OnAuthenticated(session))); return(respone); }
public CreateGroupChatResponse CreateGroupChat(ISession session, CreateGroupChatRequest request) { var response = request.CreateResponse <CreateGroupChatResponse>(); GroupChat group = new GroupChat { GroupId = Guid.NewGuid(), CreatedAt = DateTime.UtcNow, OwnerId = session.UserId }; group.Participants = new List <GroupChatParticipant> { new GroupChatParticipant { UserId = session.UserId } }; group.Participants.AddRange(request.Participants.Select(i => new GroupChatParticipant { UserId = i })); foreach (var participant in group.Participants) { _groupChatsRepository.AddGroupToUser(participant.UserId, group.GroupId); participant.Devices = _devicesRepository.GetDevices(participant.UserId); } foreach (var device in group.Participants.SelectMany(p => p.Devices)) { if (device != session.DeviceId) { _groupChangedEventManager.DeliverEventToDevice(new GroupChangedEvent { ReceiverDeviceId = device, ChangesAuthorId = session.UserId, GroupId = group.GroupId, Participants = group.Participants, Type = GroupChangedEvent.ChangesType.ParticipantsAdded }); } } _groupChatsRepository.UpdateOrCreateGroup(group); response.GroupId = group.GroupId; return(response); }