public async Task <string> FacebookResponse()
        {
            var result = await HttpContext.AuthenticateAsync(FacebookDefaults.AuthenticationScheme);


            var data = AuthResultParser.Parse(result);

            var user = await _service.CheckExistUser(data.Email);

            if (user == null)
            {
                user = await _service.Registration(new RegistrationViewModel
                {
                    Email     = data.Email,
                    FirstName = data.FirstName,
                    LastName  = data.LastName,
                    Password  = data.FirstName + data.LastName + data.UserName,
                    UserName  = data.UserName
                });
            }

            var token = Token.Create(user);

            var response = new
            {
                access_token = token,
                username     = user.UserName
            };

            return(ResponseCreator.Create(response));
        }
Ejemplo n.º 2
0
        public static void SendError(byte[] destination, NetMQSocket socket, ErrorCode errorCode)
        {
            var response = ResponseCreator.Create(new NoEncryption(), destination, MessageType.Error,
                                                  JsonConvert.SerializeObject(errorCode));

            socket.SendMultipartMessage(response);
        }
Ejemplo n.º 3
0
        private void SendPublicKey(byte[] requester, RouterSocket router)
        {
            var response = ResponseCreator.Create(new NoEncryption(), requester, MessageType.SendPublicKey,
                                                  JsonConvert.SerializeObject(_decryptor.PublicKey));

            router.SendMultipartMessage(response);
        }
Ejemplo n.º 4
0
        private void GrantCapability(Guid requesterIdentity, byte[] destination, CapabilityInfo info)
        {
            var infoJson  = JsonConvert.SerializeObject(info);
            var encryptor = _negotiator.GetEncryptorFor(requesterIdentity);

            var response = ResponseCreator.Create(encryptor, destination, MessageType.GrantCapability, infoJson);

            _router.SendMultipartMessage(response);
        }
Ejemplo n.º 5
0
        private void SendChallenge(byte[] requester, Guid requesterIdentity, RouterSocket router, Challenge challenge)
        {
            var challengeJson = JsonConvert.SerializeObject(challenge);
            var encryptor     = GetEncryptorFor(requesterIdentity);

            var response = ResponseCreator.Create(encryptor, requester, MessageType.SendChallenge, challengeJson);

            router.SendMultipartMessage(response);
        }
        public async Task <string> Registration(RegistrationViewModel model)
        {
            if (ModelState.IsValid)
            {
                await _service.Registration(model);
            }
            else
            {
                throw new Exception("All fields must be filled in");
            }

            return(ResponseCreator.Create(true));
        }
Ejemplo n.º 7
0
        public void GetPrice()
        {
            SendPrice sendPrice = async(object obj) =>
            {
                var message = ResponseCreator.Create(new
                {
                    y = DateTime.Now.Millisecond,
                    x = DateTime.Now.Second % 5 == 0 ? DateTime.Now.Second.ToString() : ""
                });

                await _hubContext.Clients.All.SendAsync("Send", message);
            };
            TimerCallback tm    = new TimerCallback(sendPrice);
            Timer         timer = new Timer(tm, null, 0, 1000);
        }
Ejemplo n.º 8
0
        private void InvokeCapability(byte[] destination, Guid requesterIdentity, ICapability capability,
                                      string arguments)
        {
            try
            {
                var encryptor = _negotiator.GetEncryptorFor(requesterIdentity);
                var response  = ResponseCreator.Create(encryptor, destination, MessageType.CapabilityInvocationResult,
                                                       capability.Invoke(arguments));

                _router.SendMultipartMessage(response);
            }
            catch (Exception)
            {
                ErrorMessageSender.SendError(destination, _router, ErrorCode.InvocationError);
            }
        }
        public async Task <string> Login([FromQuery] LoginViewModel model)
        {
            User user;

            if (ModelState.IsValid)
            {
                user = await _service.Login(model);
            }
            else
            {
                throw new Exception("All fields must be filled in");
            }

            var token = Token.Create(user);

            return(ResponseCreator.Create(token));
        }
Ejemplo n.º 10
0
        public void ResponseCreateWithoutPayloadTest()
        {
            var requester = Guid.NewGuid();

            var response = ResponseCreator.Create(new NoEncryption(), requester.ToByteArray(), MessageType.Acknowledge);

            Assert.AreEqual(4, response.FrameCount);

            var to = new Guid(response.Pop().ToByteArray());

            Assert.AreEqual(requester, to);

            Assert.True(response.Pop().IsEmpty);

            var type = (MessageType)response.Pop().ConvertToInt32();

            Assert.AreEqual(MessageType.Acknowledge, type);

            Assert.True(response.Pop().IsEmpty);
        }
Ejemplo n.º 11
0
        public void ResponseCreateWithPayloadTest()
        {
            var requester = Guid.NewGuid();
            var payload   = JsonConvert.SerializeObject(ErrorCode.InvocationError);

            var response =
                ResponseCreator.Create(new NoEncryption(), requester.ToByteArray(), MessageType.Error, payload);

            Assert.AreEqual(4, response.FrameCount);

            var to = new Guid(response.Pop().ToByteArray());

            Assert.AreEqual(requester, to);

            Assert.True(response.Pop().IsEmpty);

            var type = (MessageType)response.Pop().ConvertToInt32();

            Assert.AreEqual(MessageType.Error, type);

            var decodedPayload = JsonConvert.DeserializeObject <ErrorCode>(response.Pop().ConvertToString());

            Assert.AreEqual(ErrorCode.InvocationError, decodedPayload);
        }
Ejemplo n.º 12
0
        private static void SendAcknowledge(byte[] requester, RouterSocket router)
        {
            var response = ResponseCreator.Create(new NoEncryption(), requester, MessageType.Acknowledge);

            router.SendMultipartMessage(response);
        }