示例#1
0
        public LoginHelper Login(string usuario, string senha)
        {
            try
            {
                var user_autenticado = context.users
                                       .Where(p => p.email == usuario)
                                       .AsEnumerable()
                                       .Where(p => Crypt.Decrypt(senha, p.pass) == true)
                                       .Select(p => new User
                {
                    Id    = p.Id,
                    email = p.email,
                    role  = p.role,
                    name  = p.name
                })
                                       .First();

                senha = "";

                string tk = GenerateToken.set(user_autenticado, config.Value.JwtKey.ToString());

                status = !status;
                return(new LoginHelper()
                {
                    status = true,
                    user = user_autenticado.Id,
                    token = tk
                });
            }
            catch (System.Exception)
            {
                return(new LoginHelper()
                {
                    status = false,
                    user = "",
                    token = ""
                });

                throw;
            }
        }