Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
first commit to sample code
  • Loading branch information
arihantja1n committed Apr 23, 2014
0 parents commit cd153cf
Show file tree
Hide file tree
Showing 6 changed files with 170 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/backend/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
// Configration area
define('DBNAME', 'sampleDB.sqlite');
define('USERSTBL', 'users');

?>

38 changes: 38 additions & 0 deletions app/backend/getData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/* include config for DB connection */
include_once 'config.php';

/* get params */
$postData = file_get_contents("php://input");
$postArray = json_decode($postData,true);

$resp = array();

/* check for user info into DB */
if(isset($postArray['uname']) && $postArray['uname'] != ''){
$base = new SQLite3(DBNAME);
$query = "SELECT UserKey, CreatedDate, ModifiedDate, UserName, FirstName, LastName, EmailId, Password FROM USERSTBL WHERE UserName ='".$postArray['uname']."'";
$results = $base->query($query);

if ($results) {
$res = $results->fetchArray(SQLITE3_ASSOC);
if ($res['Password'] == md5($postArray['pswd'])) {
$resp['status'] = 0;
$resp['message'] = "Login successful";
$resp['UserKey'] = $res['UserKey'];
$resp['FirstName'] = $res['FirstName'];
$resp['Password'] = $res['Password'];
}
else{
$resp['status'] = 1;
$resp['message'] = "Wrong username or password";
}
}else{
$resp['status'] = 1;
$resp['message'] = "Wrong username or password";
}

/* print response */
exit(json_encode($resp));
}
?>
Binary file added app/backend/sampleDB.sqlite
Binary file not shown.
60 changes: 60 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" ng-app> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<title>AngularJS and Bootstrap</title>
<meta name="description" content="Angular JS and Bootstrap Login from with SQLLite3 BE">
<meta name="author" content="OnG Tech">

<meta name="viewport" content="width=device-width">

<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">
<style>
.form-group .alert {
padding: 0px;
margin-bottom: 0px;
}

.extra-info {
margin-top: 2em;
font-size: smaller;
}

.info{
border: 1px solid;margin: 10px 0px;
padding:10px;color: #00529B;
background-color: #BDE5F8;list-style: none;
}
.err{
border: 1px solid; margin: 10px 0px;
padding:10px; color: #D8000C;
background-color: #FFBABA; list-style: none;
}

</style>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.6/angular.min.js"></script>
<script src="js/new.js"></script>
</head>
<body class="bg-gradient">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<div class="panel-group">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">Login Into Demo Area</h4>
</div>
<div class="panel-body">
<ng-include src="'views/form.html'"></ng-include>
</div>
</div>
</div>
</div>
</div>

</body>
</html>
31 changes: 31 additions & 0 deletions app/js/new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

/* Main controller area */

function MainCtrl($scope, $http) {
$scope.errors = [];
$scope.msgs = [];

$scope.Login = function() {

$scope.errors.splice(0, $scope.errors.length); // remove all error messages
$scope.msgs.splice(0, $scope.msgs.length);

if($scope.username == undefined) //cross-check for dirty value
return;
if($scope.userpassword == undefined) //cross-check for dirty value
return;

$http.post('backend/getData.php', {'uname': $scope.username, 'pswd': $scope.userpassword}
).success(function(data, status, headers, config) {
if (data.message != '') {
$scope.msgs.push(data.message);
}
else {
$scope.errors.push(data.error);
}
}).error(function(data, status) { // called asynchronously if an error occurs
// or server returns response with an error status.
$scope.errors.push(status);
});
}
}
34 changes: 34 additions & 0 deletions app/views/form.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<form name="form" ng-controller="MainCtrl" novalidate>
<!-- message and error-->
<ul>
<li class="err" ng-repeat="error in errors"> {{ error}} </li>
</ul>
<ul>
<li class="info" ng-repeat="msg in msgs"> {{ msg}} </li>
</ul>

<!-- username-->
<div class="form-group clearfix" ng-class="{
'has-error': form.$submitted && form.userName.$invalid,
'has-success': form.$submitted && form.userName.$valid}">
<label class="col-sm-3 control-label" for="userName">Username</label>
<div class="col-sm-8">
<input id="userName" name="userName" class="form-control" type="text" ng-model="username" required autofocus></input>
<div class="alert alert-danger" ng-show="form.userName.$dirty && form.userName.$error.required">Username is required</div>
</div>
</div>
<!-- password-->
<div class="form-group clearfix" ng-class="{
'has-error': form.$submitted && form.password.$invalid,
'has-success': form.$submitted && form.password.$valid}">
<label class="col-sm-3 control-label" for="password">Password</label>
<div class="col-sm-8">
<input id="password" name="password" class="form-control" type="password" ng-model="userpassword" required></input>
<div class="alert alert-danger" ng-show="form.password.$dirty && form.password.$error.required">Password is required</div>
</div>
</div>
<!-- form controls-->
<div class="form-group">
<button ng-click="Login()" class="btn btn-primary" ng-disabled="(form.$invalid)">Login</button>
</div>
</form>

0 comments on commit cd153cf

Please sign in to comment.