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
0ad2a4c6
Commit
0ad2a4c6
authored
May 12, 2015
by
Evren Kutar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
login service & session
parent
f8661091
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
login_service.js
app/login/login_service.js
+47
-0
No files found.
app/login/login_service.js
View file @
0ad2a4c6
/**
/**
* Created by evren kutar on 12/05/15.
* Created by evren kutar on 12/05/15.
*/
*/
"use strict"
;
// TODO: login url cheange with correct one
angular
.
factory
(
'LoginService'
,
function
(
$http
,
Session
)
{
var
loginService
=
{};
loginService
.
login
=
function
(
credentials
)
{
return
$http
.
post
(
'http://127.0.0.1:8000/login'
,
credentials
)
.
then
(
function
(
res
)
{
Session
.
create
(
res
.
data
.
id
,
res
.
data
.
user
.
id
,
res
.
data
.
user
.
role
);
return
res
.
data
.
user
;
});
};
authService
.
isAuthenticated
=
function
()
{
return
!!
Session
.
userId
;
};
authService
.
isAuthorized
=
function
(
authorizedRoles
)
{
if
(
!
angular
.
isArray
(
authorizedRoles
))
{
authorizedRoles
=
[
authorizedRoles
];
}
return
(
authService
.
isAuthenticated
()
&&
authorizedRoles
.
indexOf
(
Session
.
userRole
)
!==
-
1
);
};
return
authService
;
});
// TODO: initial service not working!!
angular
.
service
(
'Session'
,
function
()
{
this
.
create
=
function
(
sessionId
,
userId
,
userRole
)
{
this
.
id
=
sessionId
;
this
.
userId
=
userId
;
this
.
userRole
=
userRole
;
};
this
.
destroy
=
function
()
{
this
.
id
=
null
;
this
.
userId
=
null
;
this
.
userRole
=
null
;
};
});
\ No newline at end of file
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