Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(function(){
- $('#username').on('focus',function(){
- $('#error-messages').html('');
- });
- $('#password').on('focus',function(){
- $('#error-messages').html('');
- });
- $('#login-btn').on('click', function() {
- let valid = true;
- if (valid && $('#username').val() == '') {
- $('#error-messages').html('please enter your username');
- valid = false;
- }
- if (valid && $('#password').val() == '') {
- $('#error-messages').html('please enter your password');
- valid = false;
- }
- return valid;
- });
- $('.form-horizontal').on('submit',function(e){
- e.preventDefault();
- $.ajax({url:'/login',
- method:'POST',
- contentType:'application/json',
- data:JSON.stringify({
- username:$('#username').val(),
- password:$('#password').val()
- }),
- success:function(response){
- $('#password').val('');
- if(response.type){
- $('#error-messages').html(response.message);
- }
- else if(response.task){
- $('#error-messages').html('Login Success with ID '+response.id);
- }
- }
- });
- });
- });
- app.post('/login',function (req,res){
- let loginObject=new controller();
- loginObject.verifyLogin(req.body.username,req.body.password,function(data){
- if(data == 201){
- console.log('Invalid Login Credentials');
- res.json({
- message:'Username and Password Not Found',
- type:'ERROR',
- code:data
- });
- }
- else if(data.task){
- console.log(data);
- res.json(data);
- }
- else{
- console.log(data);
- res.json({
- message:'Username and Password Not Found',
- type:'ERROR',
- code:data
- });
- }
- });
- });
Add Comment
Please, Sign In to add comment