Code igniter angular js php login with mysqli

  angularjs, codeigniter, mysql-insert-id, mysqli, php

Working on updating a project that was written years ago. on the login once i click on login the form just refreshes no errors.

 function AuthController($scope, $http) {
    $scope.SignIn = function() {
    
        var f1=$('#username').val();
        var f2=$('#password').val();
       
        
        if(f1!='' && f2!=''){
        
        $http({
            method: "POST",
            url: "<?php  echo base_url (); ?>login/authenticate",
            data :JSON.stringify({uname: $scope.username, pswd: $scope.password}),
            headers: {'Content-Type': 'application/x-www-form-urlencoded'} 
           })
       
        .success(function(data) {
          
             if (data.msg !='') {
            window.location="<?php echo base_url()?>dashboard";
            
        }

Controller:

    
    public function index()
    {
        $this->load->view('login');
        $this->load->helper(array('form','url'));
    }
    public function authenticate(){ 
        $connect = mysqli_connect("localhost", "root", "", "tms");
        $data = json_decode(file_get_contents("php://input"), true);
        $username = mysqli_real_escape_string($connect,$data['uname']);
        $password = mysqli_real_escape_string($connect,$data['pswd']);

        $this->load->model('user_model','',TRUE);
        $username = $username;
        $password = md5($password);
        $result = $this->user_model->authenticate($username, $password);

Model:

function authenticate($username, $password)
    {
        $where = array ('username'=>$username,'password'=>$password,'status'=>'1');
         
    
        $this -> db -> select('*');
        $this -> db -> from('ets_users');
        $this -> db -> where($where); 
        $this -> db -> limit(1);

        $query = $this -> db -> get();

        if($query -> num_rows() == 1)
        {
            return $query->result();
        }
        else
        {
            return false;
        }

    }

Source: AngularJS Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.