Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.post('/login', (req, res)=> {
- var username = req.body.username;
- var password = common.md5(req.body.password + common.MD5_SUFFIX);
- db.query(`SELECT * FROM admin_table WHERE username='${username}'`, (err, data)=> {
- if (err) {
- console.log(err);
- res.status(500).send('database error').end();
- } else {
- if (data.length == 0) {
- res.status(404).send('no this admin').end();
- } else {
- if (data[0].password == password) {
- req.session['admin_id']=data[0].ID;
- res.redirect('/');
- } else {
- res.status(404).send('This password is not incorrect!').end();
- }
- }
- }
- });
- });
- router.get('/login',(req,res)=>{
- res.render('admin/login.ejs',{layout:'/admin/layout.ejs',title:'Login'});
- });
- router.get('/',(req,res)=>{
- res.render('admin/index.ejs',{layout:'/admin/layout.ejs',title:'Index',username:username});
- });
Add Comment
Please, Sign In to add comment