Въведете кода тук...
Excuse me if this is too stupid, but I am new to angular. What I'm trying
to do is to route the users after the successfully log in. What I have now:
app.config(function($routeProvider) {
$routeProvider
.when('/login', {
templateUrl: 'api/welcome.html',
controller: 'contactController'
})
.when('/signup', {
templateUrl: 'templates/signup.html',
controller: 'signupController'
});
});
this is my app.js
var app = angular.module('postLogin', ['ngRoute']);
app.controller('PostController', ['$scope', '$http', function($scope,
$http, $locationgu) {
this.postForm = function() {
var encodedString = 'username=' +
encodeURIComponent(this.inputData.username) +
'&password=' +
encodeURIComponent(this.inputData.password);
$http({
method: 'POST',
url: 'api/userauth.php',
data: encodedString,
headers: {'Content-Type':
'application/x-www-form-urlencoded'}
})
.success(function(data) {
//console.log(data);
if ( data.trim() === 'correct') {
window.location.href = 'api/welcome.php';
} else {
$scope.errorMsg = "Username and password do not
match.";
}
})
}
}]);
and my userauth.php
<?php
/**
* Description: User authentication
* @author Prem Tiwari
*/
//include database connection file
require_once 'config.php';
//define database object
global $dbc;
$stmt = $dbc->prepare("SELECT username,password from dca_users WHERE
username='".$_POST['username']."' && password='".
md5($_POST['password'])."'");
$stmt->execute();
$row = $stmt->rowCount();
if ($row > 0){
echo 'correct';
} else{
echo 'wrong';
}
?>
Now is working with window.location.href, but i want to route it . I'm sure
there's better way to order my code, but as I said, I'm still newbie to
this.
Aprreciate any help!
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.