Ejemplo n.º 1
0
        /// <summary>
        /// Starts a session with a client.
        /// </summary>
        public override async Task Login(LoginRequest request,
                                         IServerStreamWriter <ServerResponse> responseStream,
                                         ServerCallContext context)
        {
            try
            {
                LoginRequests.Enqueue(request);

                while (true)
                {
                    if (!LoginResponses.ContainsKey(request.Login))
                    {
                        continue;
                    }

                    if (LoginResponses[request.Login].TryDequeue(out var loginResponse))
                    {
                        await SendLoginResponses(request.Login, responseStream, loginResponse);
                    }

                    if (!Responses.ContainsKey(request.Login))
                    {
                        continue;
                    }

                    if (Responses[request.Login].TryDequeue(out var response))
                    {
                        if (response.KeyInput == KeyInput.Exit && response.Login == request.Login)
                        {
                            LoginResponses.TryRemove(request.Login, out _);
                            Responses.TryRemove(request.Login, out _);
                            break;
                        }

                        await responseStream.WriteAsync(response);
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Ejemplo n.º 2
0
        public LoginResponses Auth(LoginRequest model)
        {
            LoginResponses loginresponses = new LoginResponses();

            using (var db = new BolsaContext())
            {
                string spass = Encryptar.GetSHA256(model.Password);
                var    user  = db.Logins.Where(x => x.Usuario == model.Usuario &&
                                               x.Contraseña == spass).FirstOrDefault();
                if (user == null)
                {
                    return(null);
                }
                else
                {
                    loginresponses.Usuario     = user.Usuario;
                    loginresponses.Token       = GetToken(user);
                    loginresponses.TipoUsuario = user.TipoUsuario;
                    loginresponses.Email       = user.Email;
                }
            }
            return(loginresponses);
        }
Ejemplo n.º 3
0
 public LoginResponse(LoginResponses response) => Response = response;