Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
ulakbus-ui
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ulakbus
ulakbus-ui
Commits
31af5bec
Commit
31af5bec
authored
Jul 08, 2015
by
Evren Kutar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
logout directive
httpprovider with credentials
parent
7ae6ea4d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
52 additions
and
20 deletions
+52
-20
app.js
app/app.js
+21
-5
app_routes.js
app/app_routes.js
+4
-1
auth_service.js
app/components/auth/auth_service.js
+12
-2
login.html
app/components/auth/login.html
+3
-3
index.html
app/index.html
+2
-0
interceptors.js
app/zetalib/interceptors.js
+10
-9
No files found.
app/app.js
View file @
31af5bec
...
@@ -31,7 +31,7 @@ var app = angular.module(
...
@@ -31,7 +31,7 @@ var app = angular.module(
config
([
'$ocLazyLoadProvider'
,
function
(
$ocLazyLoadProvider
)
{
config
([
'$ocLazyLoadProvider'
,
function
(
$ocLazyLoadProvider
)
{
$ocLazyLoadProvider
.
config
({
$ocLazyLoadProvider
.
config
({
// todo: turn debug false on prod
// todo: turn debug false on prod
debug
:
tru
e
debug
:
fals
e
});
});
}]).
}]).
/**
/**
...
@@ -66,16 +66,16 @@ var app = angular.module(
...
@@ -66,16 +66,16 @@ var app = angular.module(
// todo: not working properly, get it done!
// todo: not working properly, get it done!
directive
(
'activeLink'
,
[
'$location'
,
function
(
$location
)
{
directive
(
'activeLink'
,
[
'$location'
,
function
(
$location
)
{
return
{
return
{
restrict
:
'A'
,
restrict
:
'A'
,
link
:
function
(
$scope
,
$element
,
$attrs
)
{
link
:
function
(
$scope
,
$element
,
$attrs
)
{
var
clazz
=
$attrs
.
activeLink
;
var
clazz
=
$attrs
.
activeLink
;
var
path
=
$location
.
path
();
var
path
=
$location
.
path
();
path
=
path
//hack because path does not
path
=
path
//hack because path does not
// return including hashbang
// return including hashbang
$scope
.
location
=
$location
;
$scope
.
location
=
$location
;
$scope
.
$watch
(
'location.path()'
,
function
(
newPath
)
{
$scope
.
$watch
(
'location.path()'
,
function
(
newPath
)
{
if
(
path
===
newPath
)
{
if
(
path
===
newPath
)
{
console
.
log
(
path
,
newPath
);
console
.
log
(
path
,
newPath
);
$element
.
addClass
(
clazz
);
$element
.
addClass
(
clazz
);
...
@@ -86,7 +86,23 @@ var app = angular.module(
...
@@ -86,7 +86,23 @@ var app = angular.module(
});
});
}
}
};
};
}]);
}]).
/**
* logout directive
*/
directive
(
'logout'
,
function
(
$http
,
$location
){
return
{
link
:
function
(
$scope
,
$element
,
$rootScope
){
$element
.
on
(
'click'
,
function
(){
$http
.
post
(
'http://127.0.0.1:9001/logout'
,
{}).
then
(
function
()
{
$rootScope
.
loggedInUser
=
false
;
$location
.
path
(
"/login"
);
});
});
}
}
});
// test the code with strict di mode to see if it works when minified
// test the code with strict di mode to see if it works when minified
//angular.bootstrap(document, ['zaerp'], {
//angular.bootstrap(document, ['zaerp'], {
...
...
app/app_routes.js
View file @
31af5bec
...
@@ -180,4 +180,7 @@ app.config(['$routeProvider', function ($routeProvider) {
...
@@ -180,4 +180,7 @@ app.config(['$routeProvider', function ($routeProvider) {
}
}
}
}
});
});
});
}).
config
([
'$httpProvider'
,
function
(
$httpProvider
)
{
\ No newline at end of file
// to send cookies CORS
$httpProvider
.
defaults
.
withCredentials
=
true
;
}]);
\ No newline at end of file
app/components/auth/auth_service.js
View file @
31af5bec
...
@@ -17,13 +17,13 @@ auth.factory('LoginService', function ($http, $rootScope, $location, $log, $cook
...
@@ -17,13 +17,13 @@ auth.factory('LoginService', function ($http, $rootScope, $location, $log, $cook
return
$http
return
$http
.
post
(
RESTURL
.
url
+
url
,
credentials
)
.
post
(
RESTURL
.
url
+
url
,
credentials
)
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
.
success
(
function
(
data
,
status
,
headers
,
config
)
{
$window
.
sessionStorage
.
token
=
data
.
token
;
//
$window.sessionStorage.token = data.token;
$rootScope
.
loggedInUser
=
true
;
$rootScope
.
loggedInUser
=
true
;
$location
.
path
(
"/dashboard"
);
$location
.
path
(
"/dashboard"
);
})
})
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
.
error
(
function
(
data
,
status
,
headers
,
config
)
{
// Erase the token if the user fails to log in
// Erase the token if the user fails to log in
delete
$window
.
sessionStorage
.
token
;
//
delete $window.sessionStorage.token;
// Handle login errors here
// Handle login errors here
$scope
.
message
=
'Error: Invalid user or password'
;
$scope
.
message
=
'Error: Invalid user or password'
;
...
@@ -44,6 +44,16 @@ auth.factory('LoginService', function ($http, $rootScope, $location, $log, $cook
...
@@ -44,6 +44,16 @@ auth.factory('LoginService', function ($http, $rootScope, $location, $log, $cook
//});
//});
};
};
loginService
.
logout
=
function
()
{
console
.
log
(
"logout"
);
$http
.
post
(
RESTURL
.
url
+
'logout'
,
{}).
then
(
function
(){
$rootScope
.
loggedInUser
=
false
;
$location
.
path
(
"/login"
);
});
console
.
log
(
"loggedout"
);
};
loginService
.
isAuthenticated
=
function
()
{
loginService
.
isAuthenticated
=
function
()
{
return
!!
Session
.
userId
;
return
!!
Session
.
userId
;
};
};
...
...
app/components/auth/login.html
View file @
31af5bec
<div
ng-app=
"zaerp.
login
"
>
<div
ng-app=
"zaerp.
auth
"
>
<div
class=
"col-md-6"
ng-controller=
"LoginCtrl"
>
<div
class=
"col-md-6"
>
<h1>
Zaerp
Login Form
</h1>
<h1>
Ulakbüs
Login Form
</h1>
<form
name=
"loginForm"
sf-schema=
"schema"
sf-form=
"form"
sf-model=
"model"
ng-submit=
"onSubmit(loginForm)"
></form>
<form
name=
"loginForm"
sf-schema=
"schema"
sf-form=
"form"
sf-model=
"model"
ng-submit=
"onSubmit(loginForm)"
></form>
</div>
</div>
</div>
</div>
\ No newline at end of file
app/index.html
View file @
31af5bec
...
@@ -37,6 +37,8 @@
...
@@ -37,6 +37,8 @@
<ul
class=
"nav navbar-nav navbar-right"
>
<ul
class=
"nav navbar-nav navbar-right"
>
<li><a
href=
"#/dashboard"
>
Dashboard
</a></li>
<li><a
href=
"#/dashboard"
>
Dashboard
</a></li>
<li><a
href=
"#/login"
>
Login
</a></li>
<li><a
href=
"#/login"
>
Login
</a></li>
<li><a
href=
"javascript:void(0);"
logout
>
Logout
</a></li>
</ul>
</ul>
<form
class=
"navbar-form navbar-right"
>
<form
class=
"navbar-form navbar-right"
>
<input
type=
"text"
class=
"form-control"
placeholder=
"Search..."
>
<input
type=
"text"
class=
"form-control"
placeholder=
"Search..."
>
...
...
app/zetalib/interceptors.js
View file @
31af5bec
...
@@ -5,12 +5,12 @@
...
@@ -5,12 +5,12 @@
* (GPLv3). See LICENSE.txt for details.
* (GPLv3). See LICENSE.txt for details.
*/
*/
app
.
config
([
'$httpProvider'
,
function
(
$httpProvider
,
$rootScope
)
{
app
.
config
([
'$httpProvider'
,
function
(
$httpProvider
)
{
/**
/**
* 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
*/
*/
$httpProvider
.
interceptors
.
push
(
function
(
$q
)
{
$httpProvider
.
interceptors
.
push
(
function
(
$q
,
$rootScope
,
$location
)
{
return
{
return
{
'request'
:
function
(
config
){
'request'
:
function
(
config
){
// todo: delete console logs
// todo: delete console logs
...
@@ -23,23 +23,24 @@ app.config(['$httpProvider', function ($httpProvider, $rootScope) {
...
@@ -23,23 +23,24 @@ app.config(['$httpProvider', function ($httpProvider, $rootScope) {
},
},
'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
){
if
(
response
.
data
.
is_login
){
$rootScope
.
loggedInUser
=
response
.
is_login
;
$rootScope
.
loggedInUser
=
response
.
data
.
is_login
;
console
.
log
(
"login"
,
response
.
is_login
);
console
.
log
(
"login"
,
response
.
data
.
is_login
);
$location
.
path
(
"/dashboard"
);
}
}
if
(
response
.
screen
)
{
if
(
response
.
screen
)
{
location
.
path
(
response
.
screen
);
$
location
.
path
(
response
.
screen
);
}
}
console
.
log
(
response
);
console
.
log
(
"login"
,
response
);
return
response
;
return
response
;
},
},
'responseError'
:
function
(
rejection
)
{
'responseError'
:
function
(
rejection
)
{
// if unauthorized then redirect to login page
// if unauthorized then redirect to login page
if
(
rejection
.
status
===
400
)
{
if
(
rejection
.
status
===
400
)
{
location
.
reload
();
$
location
.
reload
();
}
}
if
(
rejection
.
status
===
401
)
{
if
(
rejection
.
status
===
401
)
{
location
.
path
(
'#
/login'
);
$location
.
path
(
'
/login'
);
}
}
return
$q
.
reject
(
rejection
);
return
$q
.
reject
(
rejection
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment