Skip to content

Instantly share code, notes, and snippets.

@ElmahdiMahmoud
Forked from amineeg/app.js
Created April 30, 2014 21:01
Show Gist options
  • Save ElmahdiMahmoud/ba738f4ef51fb37af9ec to your computer and use it in GitHub Desktop.
Save ElmahdiMahmoud/ba738f4ef51fb37af9ec to your computer and use it in GitHub Desktop.
'use strict';
// Declare app level module which depends on filters, and services
var app= angular.module('myApp', ['ngRoute']);
app.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/login', {templateUrl: 'partials/login.html', controller: 'loginCtrl'});
$routeProvider.otherwise({redirectTo: '/login'});
}]);
<!doctype html>
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8">
<title>My AngularJS App</title>
<link rel="stylesheet" href="css/app.css"/>
</head>
<body>
<div ng-view></div>
<!-- In production use:
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
-->
<script src="lib/angular/angular.js"></script>
<script src="lib/angular/angular-route.js"></script>
<script src="js/app.js"></script>
<script src="js/directives/loginDrc.js"></script>
<script src="js/controllers/loginCtrl.js"></script>
<script src="js/services/loginService.js"></script>
</body>
</html>
'use strict';
app.controller('loginCtrl', ['$scope','loginService', function ($scope,loginService) {
$scope.msgtxt='';
$scope.login=function(data){
loginService.login(data,$scope); //call login service
};
}]);
'use strict';
app.directive('loginDirective',function(){
return{
templateUrl:'partials/tpl/login.tpl.html'
}
});
'use strict';
app.factory('loginService',function($http){
return{
login:function(data,scope){
var $promise=$http.post('data/user.php',data); //send data to user.php
$promise.then(function(msg){
if(msg.data=='succes') scope.msgtxt='Correct information';
else scope.msgtxt='incorrect information';
});
}
}
});
<?php
$user=json_decode(file_get_contents('php://input')); //get user from
if($user->mail=='[email protected]' && $user->pass=='1234')
print 'succes';
else
print 'error';
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment