mirror of
https://gitlab.com/nekoya/web.git
synced 2024-11-22 14:26:29 +01:00
Update login
This commit is contained in:
parent
0810e95952
commit
1dadd2caf0
2 changed files with 47 additions and 5 deletions
|
@ -39,8 +39,26 @@ function register(email, password, first_name, last_name) {
|
|||
.catch(error => console.log(error))
|
||||
}
|
||||
|
||||
function login(email, password, ua, ip) {
|
||||
let params = new URLSearchParams({
|
||||
'email': email,
|
||||
'password': password,
|
||||
'ua': ua,
|
||||
'ip': ip
|
||||
})
|
||||
const conf = {
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded'
|
||||
}
|
||||
}
|
||||
return axios.post(HOST + '/login', params, conf)
|
||||
.then(response => [response.status, response.data])
|
||||
.catch(error => console.log(error))
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getProducts,
|
||||
getProduct,
|
||||
register
|
||||
register,
|
||||
login
|
||||
}
|
|
@ -4,7 +4,6 @@ var registerlogin = require("./registerlogin");
|
|||
|
||||
let controller = require("../controllers/controllers");
|
||||
|
||||
router.post("/login", registerlogin.login);
|
||||
router.get("/verify-email", registerlogin.verifyemail);
|
||||
|
||||
router.get('/', (_req, res) => {
|
||||
|
@ -25,9 +24,34 @@ router.route('/register')
|
|||
});
|
||||
})
|
||||
|
||||
router.get('/login', (_req, res) => {
|
||||
res.render('pages/login');
|
||||
})
|
||||
router.route('/login')
|
||||
.get((_req, res) => {
|
||||
res.render('pages/login');
|
||||
})
|
||||
.post((req, res) => {
|
||||
controller.login(req.body.email, req.body.password, req.headers['user-agent'], req.headers['x-forwarded-for'] || req.socket.remoteAddress).then(data => {
|
||||
console.log(data);
|
||||
if (data[0] == 200) {
|
||||
console.log(data[1])
|
||||
res.render("pages/index");
|
||||
} else if (data[0] == 204){
|
||||
res.render('pages/login', {
|
||||
companyName : 'SALAH',
|
||||
error : 'Please confirm your email'
|
||||
});
|
||||
} else if (data[0] == 401){
|
||||
res.render('pages/login', {
|
||||
companyName : 'SALAH',
|
||||
error : 'Invalid Credential'
|
||||
});
|
||||
} else {
|
||||
res.render('pages/login', {
|
||||
companyName : 'SALAH',
|
||||
error : 'Something went wrong !!!'
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
router.get('/forgot-password', (_req, res) => {
|
||||
res.render('pages/forgot-password');
|
||||
|
|
Loading…
Reference in a new issue