Commit 7ae6ea4d authored by Evren Kutar's avatar Evren Kutar

login implementasyonu faz 1

parent 5d272471
...@@ -167,8 +167,8 @@ app.config(['$routeProvider', function ($routeProvider) { ...@@ -167,8 +167,8 @@ app.config(['$routeProvider', function ($routeProvider) {
* *
*/ */
var sessionId = $cookies.get('session'); //var sessionId = $cookies.get('session');
$rootScope.loggedInUser = sessionId ? true : false; //$rootScope.loggedInUser = sessionId ? true : false;
$rootScope.$on("$routeChangeStart", function (event, next, current) { $rootScope.$on("$routeChangeStart", function (event, next, current) {
if ($rootScope.loggedInUser == null) { if ($rootScope.loggedInUser == null) {
// no logged user, redirect to /login // no logged user, redirect to /login
......
...@@ -17,7 +17,8 @@ auth.controller('LoginCtrl', function ($scope, $q, $timeout, $routeParams, Gener ...@@ -17,7 +17,8 @@ auth.controller('LoginCtrl', function ($scope, $q, $timeout, $routeParams, Gener
$scope.url = 'simple_login'; $scope.url = 'simple_login';
// todo: change simple login when api ready // todo: change simple login when api ready
Generator.get_form($scope.url, $routeParams).then(function(d){ Generator.get_form($scope.url, $routeParams).then(function(data){
var d = data.data.forms;
$scope.schema = d.schema; $scope.schema = d.schema;
$scope.form = d.form; $scope.form = d.form;
// model is the init data of the form or in edit templates // model is the init data of the form or in edit templates
......
...@@ -9,31 +9,39 @@ ...@@ -9,31 +9,39 @@
// TODO: login url change with correct one // TODO: login url change with correct one
auth.factory('LoginService', function ($http, $rootScope, $location, $log, $cookies, Session, RESTURL) { auth.factory('LoginService', function ($http, $rootScope, $location, $log, $cookies, $window, Session, RESTURL) {
var loginService = {}; var loginService = {};
loginService.login = function (url, credentials) { loginService.login = function (url, credentials) {
// TODO: change this getParams var to service to use app-wide credentials = {login_crd: credentials, cmd: "do"};
var getParams = "?";
for (var k in credentials) {
getParams += k + "=" + credentials[k] + "&";
}
return $http return $http
.get(RESTURL.url + url + getParams) .post(RESTURL.url + url, credentials)
.then(function (res) { .success(function (data, status, headers, config) {
$log.info(res.data[0]); $window.sessionStorage.token = data.token;
res.data = res.data[0];
if (res.data.success) {
$rootScope.loggedInUser = true; $rootScope.loggedInUser = true;
$location.path("/dashboard"); $location.path("/dashboard");
var session = Session.create(res.data.id, res.data.user.id, })
res.data.user.role); .error(function (data, status, headers, config) {
$log.info(session); // Erase the token if the user fails to log in
$cookies.put('sessionId', 123456); delete $window.sessionStorage.token;
console.log($cookies.getAll());
return res.data.user; // Handle login errors here
} $scope.message = 'Error: Invalid user or password';
}); });
//.then(function (res) {
// $log.info(res.data[0]);
// res.data = res.data[0];
// if (res.data.success) {
// $rootScope.loggedInUser = true;
// $location.path("/dashboard");
// var session = Session.create(res.data.id, res.data.user.id,
// res.data.user.role);
// $log.info(session);
// $cookies.put('sessionId', 123456);
// console.log($cookies.getAll());
// return res.data.user;
// }
//});
}; };
loginService.isAuthenticated = function () { loginService.isAuthenticated = function () {
......
...@@ -48,18 +48,21 @@ staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $ ...@@ -48,18 +48,21 @@ staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $
else { else {
form_params['cmd'] = 'add_object'; form_params['cmd'] = 'add_object';
} }
Generator.get_form('personel_duzenle_basitlestirilmis', form_params).then(function (d) { Generator.get_form('personel_duzenle_basitlestirilmis', form_params).then(function (data) {
var d = data.data.forms;
$scope.schema = d.schema; $scope.schema = d.schema;
$scope.form = d.form; $scope.form = d.form;
$scope.form.push({"key": "birth_date", "format": "yyyy-mm-dd"});
$scope.model = d.model ? d.model : {}; $scope.model = d.model ? d.model : {};
$scope.initialModel = angular.copy(d.model); $scope.initialModel = angular.copy(d.model);
$scope.form[0].$asyncValidators = Generator.asyncValidators; //$scope.form.push($asyncValidators: Generator.asyncValidators);
$scope.form.push( $scope.form.push(
{ {
type: "submit", type: "submit",
title: "Save" title: "Save"
} }
); );
console.log($scope);
return $scope; return $scope;
}); });
$scope.onSubmit = function (form) { $scope.onSubmit = function (form) {
......
...@@ -81,6 +81,9 @@ ...@@ -81,6 +81,9 @@
<script type="text/javascript" src="bower_components/tv4/tv4.js"></script> <script type="text/javascript" src="bower_components/tv4/tv4.js"></script>
<script type="text/javascript" src="bower_components/objectpath/lib/ObjectPath.js"></script> <script type="text/javascript" src="bower_components/objectpath/lib/ObjectPath.js"></script>
<script type="text/javascript" src="bower_components/angular-schema-form/dist/schema-form.min.js"></script> <script type="text/javascript" src="bower_components/angular-schema-form/dist/schema-form.min.js"></script>
<script type="text/javascript"
src="bower_components/angular-schema-form-datepicker/"></script>
<script type="text/javascript" src="bower_components/angular-schema-form-datepicker/bootstrap-datepicker.js"></script>
<script type="text/javascript" src="bower_components/angular-schema-form/dist/bootstrap-decorator.min.js"></script> <script type="text/javascript" src="bower_components/angular-schema-form/dist/bootstrap-decorator.min.js"></script>
<script src="app.js"></script> <script src="app.js"></script>
......
...@@ -16,23 +16,10 @@ form_generator.factory('Generator', function ($http, $q, $log, $timeout, RESTURL ...@@ -16,23 +16,10 @@ form_generator.factory('Generator', function ($http, $q, $log, $timeout, RESTURL
return form_items; return form_items;
}; };
generator.get_form = function (url, getParams) { generator.get_form = function (url, getParams) {
//if (getParams) {
// // if form for edit then url will be
// var params = "";
// for (var k in getParams) {
// params += k + "=" + getParams[k] + "&";
// }
// var formUrl = RESTURL.url + url + '?' + params;
//} else {
// // if form for create then url will be
// var formUrl = RESTURL.url + url;
//}
console.log(getParams);
return $http return $http
.post(RESTURL.url + url, getParams) .post(RESTURL.url + url, getParams)
.then(function (res) { .success(function (res) {
if (res.status == 200) { if (res.status == 200) {
console.log(res);
return generator.generate(res.data); return generator.generate(res.data);
} }
// todo: cover all other exceptions (4xx, 5xx) // todo: cover all other exceptions (4xx, 5xx)
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* (GPLv3). See LICENSE.txt for details. * (GPLv3). See LICENSE.txt for details.
*/ */
app.config(['$httpProvider', function ($httpProvider) { app.config(['$httpProvider', function ($httpProvider, $rootScope) {
/** /**
* the interceptor for all requests to check response * the interceptor for all requests to check response
* 4xx - 5xx errors will be handled here * 4xx - 5xx errors will be handled here
...@@ -13,6 +13,7 @@ app.config(['$httpProvider', function ($httpProvider) { ...@@ -13,6 +13,7 @@ app.config(['$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push(function ($q) { $httpProvider.interceptors.push(function ($q) {
return { return {
'request': function(config){ 'request': function(config){
// todo: delete console logs
if (config.method == "POST"){ if (config.method == "POST"){
console.log("post request") console.log("post request")
} else { } else {
...@@ -22,9 +23,14 @@ app.config(['$httpProvider', function ($httpProvider) { ...@@ -22,9 +23,14 @@ app.config(['$httpProvider', function ($httpProvider) {
}, },
'response': function (response) { 'response': function (response) {
//Will only be called for HTTP up to 300 //Will only be called for HTTP up to 300
if(response.is_login){
$rootScope.loggedInUser = response.is_login;
console.log("login", response.is_login);
}
if(response.screen) { if(response.screen) {
location.path(response.screen); location.path(response.screen);
} }
console.log(response);
return response; return response;
}, },
'responseError': function (rejection) { 'responseError': function (rejection) {
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
"angular-cookies": "1.4.x", "angular-cookies": "1.4.x",
"bootstrap": "3.3.4", "bootstrap": "3.3.4",
"angular-schema-form": "*", "angular-schema-form": "*",
"angular-schema-form-datepicker": "*",
"oclazyload": "*" "oclazyload": "*"
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment