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) {
*
*/
var sessionId = $cookies.get('session');
$rootScope.loggedInUser = sessionId ? true : false;
//var sessionId = $cookies.get('session');
//$rootScope.loggedInUser = sessionId ? true : false;
$rootScope.$on("$routeChangeStart", function (event, next, current) {
if ($rootScope.loggedInUser == null) {
// no logged user, redirect to /login
......
......@@ -17,7 +17,8 @@ auth.controller('LoginCtrl', function ($scope, $q, $timeout, $routeParams, Gener
$scope.url = 'simple_login';
// 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.form = d.form;
// model is the init data of the form or in edit templates
......
......@@ -9,31 +9,39 @@
// 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 = {};
loginService.login = function (url, credentials) {
// TODO: change this getParams var to service to use app-wide
var getParams = "?";
for (var k in credentials) {
getParams += k + "=" + credentials[k] + "&";
}
credentials = {login_crd: credentials, cmd: "do"};
return $http
.get(RESTURL.url + url + getParams)
.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;
}
.post(RESTURL.url + url, credentials)
.success(function (data, status, headers, config) {
$window.sessionStorage.token = data.token;
$rootScope.loggedInUser = true;
$location.path("/dashboard");
})
.error(function (data, status, headers, config) {
// Erase the token if the user fails to log in
delete $window.sessionStorage.token;
// 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 () {
......
......@@ -48,18 +48,21 @@ staff.controller('StaffAddEditCtrl', function ($scope, $http, $log, Generator, $
else {
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.form = d.form;
$scope.form.push({"key": "birth_date", "format": "yyyy-mm-dd"});
$scope.model = d.model ? d.model : {};
$scope.initialModel = angular.copy(d.model);
$scope.form[0].$asyncValidators = Generator.asyncValidators;
//$scope.form.push($asyncValidators: Generator.asyncValidators);
$scope.form.push(
{
type: "submit",
title: "Save"
}
);
console.log($scope);
return $scope;
});
$scope.onSubmit = function (form) {
......
......@@ -81,6 +81,9 @@
<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/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 src="app.js"></script>
......
......@@ -16,23 +16,10 @@ form_generator.factory('Generator', function ($http, $q, $log, $timeout, RESTURL
return form_items;
};
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
.post(RESTURL.url + url, getParams)
.then(function (res) {
.success(function (res) {
if (res.status == 200) {
console.log(res);
return generator.generate(res.data);
}
// todo: cover all other exceptions (4xx, 5xx)
......
......@@ -5,7 +5,7 @@
* (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
* 4xx - 5xx errors will be handled here
......@@ -13,6 +13,7 @@ app.config(['$httpProvider', function ($httpProvider) {
$httpProvider.interceptors.push(function ($q) {
return {
'request': function(config){
// todo: delete console logs
if (config.method == "POST"){
console.log("post request")
} else {
......@@ -22,9 +23,14 @@ app.config(['$httpProvider', function ($httpProvider) {
},
'response': function (response) {
//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) {
location.path(response.screen);
}
console.log(response);
return response;
},
'responseError': function (rejection) {
......
......@@ -13,6 +13,7 @@
"angular-cookies": "1.4.x",
"bootstrap": "3.3.4",
"angular-schema-form": "*",
"angular-schema-form-datepicker": "*",
"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