private dynamic OnFriendRequestReply(dynamic arg) { var helper = new SerializeHelper(); var requestReply = helper.DeserializeObject <FriendRequestReply>(Request.Body); $"Got a friend request reply from { requestReply.Request.TargetAccount.Name } to { requestReply.Request.RequesterAccount.Name }" .WriteToConsole(); Guid senderId = requestReply.Id; SessionAuth clientAuth = Request.Headers.GetSessionAuth(); if (!AccountStateService.Instance.IsAuthorized(senderId, clientAuth.ClientToken)) { throw new ClientNotAuthorizedException(senderId); } AccountStateService stateService = AccountStateService.Instance; UserInformerService informerService = UserInformerService.Instance; FriendRequestService friendRequestService = FriendRequestService.Instance; ComplexFriendRequest processedRequest = friendRequestService.ReplyToRequest(requestReply); Task.Run(() => { informerService.NotifyUserAboutFriendReply(requestReply.Request.RequesterAccount.Id, requestReply); }); requestReply.EstablishedDate = processedRequest.DecisionDate; var serialized = helper.Serialize(requestReply); return(serialized); }
private dynamic OnSearchFriendRequestRequest(dynamic arg) { var searchRequest = new SerializeHelper().DeserializeObject <SearchRequest>(Request.Body); SearchEntity searchEntity = searchRequest.Entity; if (searchEntity != SearchEntity.IncomingFriendRequests && searchEntity != SearchEntity.OutgoingFriendRequests) { throw new InvalidOperationException($"Search entity '{ searchEntity }' must not be sent to this controller"); } AccountStateService stateService = AccountStateService.Instance; FriendRequestService requestService = FriendRequestService.Instance; SessionAuth clientAuth = Request.Headers.GetSessionAuth(); if (!stateService.IsAuthorized(searchRequest.SenderId, clientAuth.ClientToken)) { throw new ClientNotAuthorizedException(searchRequest.SenderId); } IEnumerable <ComplexFriendRequest> requests = searchEntity == SearchEntity.IncomingFriendRequests ? requestService.GetIncomingRequests(searchRequest.SenderId) : requestService.GetOutgoingRequests(searchRequest.SenderId); IEnumerable <FriendRequest> clientModels = requests.Select(complexModel => complexModel.ToSimple()); string serialized = new SerializeHelper().Serialize(clientModels); return(serialized); }
//private bool _loginStarted = false; //private static readonly Object obj = new Object(); public D7ServicesClient(IFileSystemShim fsShim, ISerializer serializer) { _fsShim = fsShim; _serialzr = ForwardLogs(serializer); _client = ForwardLogs(new RestSharpClientShim()); _auth = ForwardLogs(new SessionAuth(fsShim, serializer)); _batchr = ForwardLogs(new BatchSender(_client, _auth)); _client.ResponseReceived += (s, e) => RaiseResponseReceived(e.Value); }
private dynamic OnSearhUserAvatars(dynamic arg) { var searchRequest = new SerializeHelper().DeserializeObject <SearchRequest>(Request.Body); var imageService = ImageService.Instance; var stateService = AccountStateService.Instance; Guid senderId = Request.Headers.GetClientId(); SessionAuth clientAuth = Request.Headers.GetSessionAuth(); if (!stateService.IsAuthorized(senderId, clientAuth.ClientToken)) { return(HttpStatusCode.Forbidden); } if (string.IsNullOrWhiteSpace(searchRequest.SearchFilter)) { return(HttpStatusCode.BadRequest); } var responceData = new UserAvatarsReply(); IEnumerable <Guid> userIds = searchRequest.SearchFilter.Split(';').Select(Guid.Parse).ToList(); if (searchRequest.Entity == SearchEntity.UserAvatars) { var avatars = imageService .GetUserAvatars(userIds) .Select(complexAvatar => new BinaryDataModel { Blob = complexAvatar.AvatarBlob, LastModified = complexAvatar.LastModified }) .ToList(); responceData.UserAvatars = avatars; } else if (searchRequest.Entity == SearchEntity.UserAvatarsCache) { List <ObjectModificationTime> avatarsCache = imageService.GetUserAvatarsCache(userIds).ToList(); responceData.AvatarsModifications = avatarsCache; } var responce = new JsonResponse <UserAvatarsReply>(responceData, new DefaultJsonSerializer()); responce.Headers.Add(FreengyHeaders.Server.ServerSessionTokenHeaderName, clientAuth.ServerToken); return(responce); }
/// <summary> /// Deserialize <see cref="ISessionAuth"/>. /// </summary> /// <returns><see cref="ISessionAuth"/> object</returns> private ISessionAuth DeserializeSessionAuth() { bool isNull = this.binaryReader.ReadBoolean(); if (isNull) { return(null); } SessionAuth sessionAuth = new SessionAuth(); sessionAuth.IsSuperSession = this.binaryReader.ReadBoolean(); sessionAuth.ClientIP = this.binaryReader.ReadNullableString(); sessionAuth.ClientDigest = this.binaryReader.ReadNullableString(); sessionAuth.ClientIdentity = this.binaryReader.ReadNullableString(); return(sessionAuth); }
private dynamic OnSyncAccountRequest(dynamic arg) { var stateService = AccountStateService.Instance; Guid senderId = Request.Headers.GetClientId(); SessionAuth clientAuth = Request.Headers.GetSessionAuth(); if (!stateService.IsAuthorized(senderId, clientAuth.ClientToken)) { throw new ClientNotAuthorizedException(senderId); } ComplexAccountState currentState = AccountStateService.Instance.GetStatusOf(senderId); var responce = new JsonResponse <AccountStateModel>(currentState.ToSimple(), new DefaultJsonSerializer()); responce.Headers.Add(FreengyHeaders.Server.ServerSessionTokenHeaderName, currentState.ClientAuth.ServerToken); return(responce); }
private dynamic OnEditAccount(dynamic arg) { var editRequest = new SerializeHelper().DeserializeObject <EditAccountModel>(Request.Body); Guid senderId = Request.Headers.GetClientId(); var stateService = AccountStateService.Instance; SessionAuth clientAuth = Request.Headers.GetSessionAuth(); if (!stateService.IsAuthorized(senderId, clientAuth.ClientToken)) { return(HttpStatusCode.Forbidden); } //ComplexAccountState editedAccount = stateService.GetStatusOf(senderId); //editedAccount.StateModel. stateService.EditAccountProps(senderId, editRequest); return(HttpStatusCode.Accepted); }
private static void SetAuthHeaders(IDictionary <string, string> headers, SessionAuth auth) { headers.Add(FreengyHeaders.Client.ClientAddressHeaderName, auth.ClientToken); headers.Add(FreengyHeaders.Server.ServerSessionTokenHeaderName, auth.ServerToken); }
public BatchSender(IClientShim clientShim, SessionAuth sessionAuth) { _client = clientShim; _auth = sessionAuth; }