This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let fs = require('fs'); | |
| /* No exemplo abaixo, informamos o local que será criado o arquivo | |
| toda a informação que esse arquivo conterá, e por ultimo temos nossa função callback */ | |
| fs.writeFile("./files/example.txt",'Um breve texto aqui!', function(err){ | |
| //Caro ocorra algum erro | |
| if(err){ | |
| return console.log('erro') | |
| } | |
| //Caso não tenha erro, retornaremos a mensagem de sucesso |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function(){ | |
| //Exemplo de detecção de um botão, cujo o class é exampleClass | |
| $('.exampleClass').on('click',function(){ | |
| //Examplo pegando os dados enviados por parametro | |
| var jsonObjeto = [{teste:$(this).data('teste'), nome:$(this).data('nome')}]; | |
| //Examplo pegando os dados diretamente de algum campo | |
| var jsonObjeto = [{teste:$('.classCampo').val(), nome:$('#idCampo').val()}]; | |
| //Chamada do Ajax para trazer os detalhes da ordem | |
| $.ajax({ | |
| url: 'example/post', //selecionando o endereço que iremos acessar no backend |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $(document).ready(function(){ | |
| let Itens = [];//Variavel para adicionar os itens retornado do backend | |
| let divItens = document.getElementById("divItens");//Selecionando a div que irá receber o conteúdo gerado automaticamente | |
| //Chamada do Ajax para trazer os detalhes da ordem | |
| $.ajax({ | |
| url: '/secured/vagas/', //selecionando o endereço que iremos acessar no backend | |
| type: 'GET', //selecionando o tipo de requesição, PUT,GET,POST,DELETE | |
| sucess: function(){},//Em caso de sucesso | |
| error: function(err){//Em caso de erro | |
| console.log(err);//Exibir o erro no console JS do navegador |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="container"> | |
| <div id="divMensagemRetorno" class="row" style="display: none;"> | |
| <h4 id="mensagemRetorno"></h4> | |
| </div> | |
| <hr class="my-4"> | |
| <div id="divItens" class="row"></div> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {#materials} | |
| <div id="divMaterial" class="col-lg-4 col-xl-4 col-sm-12 col-md-4"> | |
| <h4>{nome}</h4> | |
| <a href="/material/{id}">Material {id}</a> | |
| </div> | |
| {/materials} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let db = require('../models') | |
| exports.new = function(req, res) { | |
| //Example of export function | |
| }; | |
| exports.findAll = function(req, res) { | |
| //Example of export function | |
| } | |
| exports.find = function(req, res) { | |
| //Example of export function |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| module.exports = function (app) { | |
| //getting the file which has all the routes to save any materials | |
| let material = require('./routes/material'); | |
| app.get('/material/new',material.new); | |
| app.get('/material',material.findAll); | |
| app.get('/material/:id',material.find); | |
| app.post('/material',material.create); | |
| app.post('/material/:id',material.update); | |
| app.delete('/material/:id',material.destroy); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Here, I isolate one Route in the file route/application | |
| let application = require('./routes/application'); | |
| /* Secured Route | |
| * First, the app will enter in routes/application, so there you can create any validation you want, and use the NEXT function for Node enter in the function that will | |
| * render the page secured | |
| * Following the logic, you can create a lot of routes before it goes to the final rendering HTML | |
| * Example: app.get('/home', route1, route2, route3, routefinal); | |
| */ | |
| app.get('/home',application.IsAuthenticated,function(req,res){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exports.IsAuthenticated = function(req,res,next){ | |
| //Passport creates a function to your session called isAuthenticated(), so you can use it to verify if the user really login in the app | |
| console.log(req.isAuthenticated()); | |
| if(req.isAuthenticated()){ | |
| //So, here you are saying that if the route called had any other function, it will goes to the next one ( which is rendering the HTML ) | |
| next(); | |
| }else{ | |
| //Or else, goes back to login page | |
| res.render('welcome/index',{message:'Ops! This route requires a login!'}); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Using Passport for local strategy | |
| passport.use('local-login', new LocalStrategy ({ | |
| //In this part, passport will use' the input in HTML, by using it's name for the strategy | |
| usernameField : 'login', | |
| passwordField : 'password' | |
| ,passReqToCallback : true},function (req,login,password,done){ | |
| //Querying on database to find the user by the email or the login | |
| db.User.find({ where: { username: req.body.login }}).then(function(result) { | |
| //Verify if the query returns a result | |
| if(result){ |