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
571ba9fd
Commit
571ba9fd
authored
Jul 07, 2015
by
Evren Kutar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
form service kullanımı ve url değişikliği
interceptor'den sayfayı ayıklama
parent
d1e16543
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
109 additions
and
67 deletions
+109
-67
app.js
app/app.js
+1
-2
app_routes.js
app/app_routes.js
+6
-0
auth_controller.js
app/components/auth/auth_controller.js
+82
-63
auth_service.js
app/components/auth/auth_service.js
+2
-2
form_service_test.js
app/zetalib/forms/form_service_test.js
+15
-0
interceptors.js
app/zetalib/interceptors.js
+3
-0
No files found.
app/app.js
View file @
571ba9fd
...
...
@@ -39,11 +39,10 @@ var app = angular.module(
* Based on the environment it changes from dev to prod
*/
constant
(
"RESTURL"
,
(
function
()
{
var
dev
=
"http://127.0.0.1:
3000/api
/"
;
var
dev
=
"http://127.0.0.1:
8000
/"
;
var
prod
=
""
;
var
ENV
=
"dev"
;
// change to prod in production
return
ENV
==
"dev"
?
{
url
:
dev
}
:
{
url
:
prod
};
//return "http://127.0.0.1:3000/api/";
})()).
/**
* USER_ROLES and AUTH_EVENTS are constant for auth functions
...
...
app/app_routes.js
View file @
571ba9fd
...
...
@@ -9,6 +9,12 @@ app.config(['$routeProvider', function ($routeProvider) {
}],
loadMyService
:
[
'$ocLazyLoad'
,
function
(
$ocLazyLoad
)
{
return
$ocLazyLoad
.
load
(
'components/auth/auth_service.js'
);
}],
loadMyService2
:
[
'$ocLazyLoad'
,
function
(
$ocLazyLoad
)
{
return
$ocLazyLoad
.
load
(
'zetalib/forms/form_service.js'
);
}],
loadMyService3
:
[
'$ocLazyLoad'
,
function
(
$ocLazyLoad
)
{
return
$ocLazyLoad
.
load
(
'zetalib/general.js'
);
}]
}
})
...
...
app/components/auth/auth_controller.js
View file @
571ba9fd
...
...
@@ -12,73 +12,92 @@
// TODO: who field can be removed??
// todo: use zetalib/forms/form_service functions for email validation
var
auth
=
angular
.
module
(
'zaerp.auth'
,
[
'ngRoute'
,
'schemaForm'
,
'ngCookies'
]);
auth
.
controller
(
'LoginCtrl'
,
function
(
$scope
,
$q
,
$timeout
,
LoginService
)
{
$scope
.
schema
=
{
title
:
"Login"
,
type
:
"object"
,
properties
:
{
email
:
{
type
:
"email"
,
title
:
"Email"
},
password
:
{
type
:
"string"
,
title
:
"Password"
},
remember
:
{
type
:
"boolean"
,
title
:
"Remember me?"
},
who
:
{
title
:
"Who are you?"
,
type
:
"string"
,
enum
:
[
"student"
,
"stuff"
,
"dean"
]
}
},
required
:
[
"email"
,
"password"
,
"who"
]
};
$scope
.
model
=
{
email
:
"user@example.com"
,
remember
:
false
};
$scope
.
form
=
[
{
key
:
"email"
,
type
:
"email"
,
validationMessages
:
{
'emailNotValid'
:
'Email is not valid!'
},
$asyncValidators
:
{
emailNotValid
:
function
(
value
)
{
var
deferred
=
$q
.
defer
();
$timeout
(
function
()
{
if
(
LoginService
.
isValidEmail
(
value
))
{
deferred
.
resolve
();
}
else
{
deferred
.
reject
();
}
},
500
);
return
deferred
.
promise
;
}
var
auth
=
angular
.
module
(
'zaerp.auth'
,
[
'ngRoute'
,
'schemaForm'
,
'ngCookies'
,
'general'
]);
auth
.
controller
(
'LoginCtrl'
,
function
(
$scope
,
$q
,
$timeout
,
$routeParams
,
Generator
,
LoginService
)
{
$scope
.
url
=
'simple_login'
;
// todo: change simple login when api ready
Generator
.
get_form
(
$scope
.
url
,
$routeParams
).
then
(
function
(
d
){
$scope
.
schema
=
d
.
schema
;
$scope
.
form
=
d
.
form
;
// model is the init data of the form or in edit templates
$scope
.
model
=
d
.
model
?
d
.
model
:
{};
$scope
.
initialModel
=
angular
.
copy
(
d
.
model
);
// for email validation add asyncvalidator
//$scope.form[0].$asyncValidators = Generator.asyncValidators;
// add submit button to the form todo: move this to form service
$scope
.
form
.
push
(
{
type
:
"submit"
,
title
:
"Save"
}
},
{
key
:
"password"
,
type
:
"password"
},
"remember"
,
"who"
,
{
type
:
"submit"
,
title
:
"Save"
}
];
);
});
//$scope.schema =
//{
// title: "Login",
// type: "object",
// properties: {
// email: {
// type: "email",
// title: "Email"
// },
// password: {
// type: "string",
// title: "Password"
// },
// remember: {
// type: "boolean",
// title: "Remember me?"
// },
// who: {
// title: "Who are you?",
// type: "string",
// enum: ["student", "stuff", "dean"]
// }
// },
// required: ["email", "password", "who"]
//};
//$scope.model = {
// email: "user@example.com",
// remember: false
//};
//$scope.form = [
// {
// key: "email",
// type: "email",
// validationMessages: {
// 'emailNotValid': 'Email is not valid!'
// },
// $asyncValidators: {
// emailNotValid: function (value) {
// var deferred = $q.defer();
// $timeout(function () {
// if (LoginService.isValidEmail(value)) {
// deferred.resolve();
// } else {
// deferred.reject();
// }
// }, 500);
// return deferred.promise;
// }
// }
// },
// {
// key: "password",
// type: "password"
// },
// "remember",
// "who",
// {
// type: "submit",
// title: "Save"
// }
//];
$scope
.
onSubmit
=
function
(
form
)
{
$scope
.
$broadcast
(
'schemaFormValidate'
);
if
(
form
.
$valid
)
{
LoginService
.
login
(
$scope
.
model
);
LoginService
.
login
(
$scope
.
url
,
$scope
.
model
);
}
else
{
console
.
log
(
"not valid"
);
...
...
app/components/auth/auth_service.js
View file @
571ba9fd
...
...
@@ -12,14 +12,14 @@
auth
.
factory
(
'LoginService'
,
function
(
$http
,
$rootScope
,
$location
,
$log
,
$cookies
,
Session
,
RESTURL
)
{
var
loginService
=
{};
loginService
.
login
=
function
(
credentials
)
{
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
]
+
"&"
;
}
return
$http
.
get
(
RESTURL
.
url
+
'login'
+
getParams
)
.
get
(
RESTURL
.
url
+
url
+
getParams
)
.
then
(
function
(
res
)
{
$log
.
info
(
res
.
data
[
0
]);
res
.
data
=
res
.
data
[
0
];
...
...
app/zetalib/forms/form_service_test.js
View file @
571ba9fd
...
...
@@ -60,5 +60,20 @@ describe('form service module', function () {
})
);
it
(
'should post form'
,
inject
(
function
(
Generator
,
$httpBackend
,
RESTURL
)
{
$httpBackend
.
expectGET
(
RESTURL
.
url
+
'student/add'
)
.
respond
(
200
,
[{
data
:
'OK'
}]);
var
cred
=
{
email
:
'test@test.com'
};
Generator
.
submit
(
'student/add'
,
cred
)
.
then
(
function
(
data
)
{
expect
(
data
).
toEqual
({
data
:
'OK'
});
});
$httpBackend
.
flush
();
})
);
});
});
\ No newline at end of file
app/zetalib/interceptors.js
View file @
571ba9fd
...
...
@@ -22,6 +22,9 @@ app.config(['$httpProvider', function ($httpProvider) {
},
'response'
:
function
(
response
)
{
//Will only be called for HTTP up to 300
if
(
response
.
screen
)
{
location
.
path
(
response
.
screen
);
}
return
response
;
},
'responseError'
:
function
(
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