Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
yotta
/
pictogram
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
60
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
be65fb8e
authored
Dec 16, 2016
by
Arturo Montejo Ráez
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
increasing activation of license working
parent
5712f9ff
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
44 additions
and
14 deletions
sails/roles/database/files/pictodb-schema.sql
sails/src/api/controllers/LicenseController.js
sails/src/api/models/License.js
sails/src/config/policies.js
sails/roles/database/files/pictodb-schema.sql
View file @
be65fb8e
...
@@ -308,6 +308,7 @@ CREATE TABLE IF NOT EXISTS `license` (
...
@@ -308,6 +308,7 @@ CREATE TABLE IF NOT EXISTS `license` (
`number`
varchar
(
16
)
CHARACTER
SET
utf8
COLLATE
utf8_bin
NOT
NULL
,
`number`
varchar
(
16
)
CHARACTER
SET
utf8
COLLATE
utf8_bin
NOT
NULL
,
`creation_ts`
datetime
DEFAULT
CURRENT_TIMESTAMP
,
`creation_ts`
datetime
DEFAULT
CURRENT_TIMESTAMP
,
`activation_ts`
datetime
NULL
,
`activation_ts`
datetime
NULL
,
`expiration_ts`
datetime
NULL
,
`duration`
int
(
11
)
DEFAULT
0
,
`duration`
int
(
11
)
DEFAULT
0
,
PRIMARY
KEY
(
`id`
),
PRIMARY
KEY
(
`id`
),
UNIQUE
KEY
`number`
(
`number`
),
UNIQUE
KEY
`number`
(
`number`
),
...
@@ -532,7 +533,7 @@ ALTER TABLE `student`
...
@@ -532,7 +533,7 @@ ALTER TABLE `student`
-- Filtros para la tabla `license`
-- Filtros para la tabla `license`
--
--
ALTER
TABLE
`license`
ALTER
TABLE
`license`
ADD
CONSTRAINT
`license_fk_1`
FOREIGN
KEY
(
`id_stu`
)
REFERENCES
`student`
(
`id`
);
ADD
CONSTRAINT
`license_fk_1`
FOREIGN
KEY
(
`id_stu`
)
REFERENCES
`student`
(
`id`
)
ON
DELETE
CASCADE
;
--
--
-- Filtros para la tabla `supervisor`
-- Filtros para la tabla `supervisor`
--
--
...
...
sails/src/api/controllers/LicenseController.js
View file @
be65fb8e
...
@@ -96,27 +96,49 @@ module.exports = {
...
@@ -96,27 +96,49 @@ module.exports = {
if
(
!
params
.
number
)
if
(
!
params
.
number
)
return
res
.
badRequest
();
return
res
.
badRequest
();
// Check license
License
.
findOne
({
number
:
params
.
number
})
License
.
findOne
({
number
:
params
.
number
})
.
then
((
l
)
=>
{
.
then
((
l
)
=>
{
if
(
!
l
)
if
(
!
l
)
return
res
.
badRequest
();
return
res
.
badRequest
(
"Invalid license"
);
if
(
l
.
activation_ts
)
if
(
l
.
activation_ts
)
return
res
.
badRequest
(
"The license is already active"
);
return
res
.
badRequest
(
"The license is already active"
);
l
.
activation_ts
=
new
Date
();
// License ok, check student
Student
.
find
(
params
.
id_stu
)
Student
.
find
One
(
params
.
id_stu
)
.
then
((
s
)
=>
{
.
then
((
s
)
=>
{
if
(
!
s
)
if
(
!
s
)
return
res
.
badRequest
(
"Student not found"
);
return
res
.
badRequest
(
"Student not found"
);
l
.
student
=
params
.
id_stu
;
l
.
save
((
err
)
=>
{
// Check if the student has a previous license
if
(
err
)
License
.
findOne
({
student
:
s
.
id
})
return
res
.
serverError
();
.
then
((
l_old
)
=>
{
return
res
.
ok
();
var
left
=
0
;
if
(
l_old
)
{
// He had a license, if not expired, get remaining time
left
=
l_old
.
expiration_ts
-
new
Date
();
left
=
left
<
0
?
0
:
left
;
License
.
destroy
({
id
:
l_old
.
id
}).
exec
((
err
)
=>
{
if
(
err
)
throw
err
;
});
}
// Compute parameters for license to activate
var
now
=
new
Date
();
l
.
student
=
s
.
id
;
l
.
activation_ts
=
now
;
l
.
expiration_ts
=
new
Date
(
new
Date
(
now
.
getFullYear
(),
now
.
getMonth
()
+
l
.
duration
,
now
.
getDate
()
+
1
).
getTime
()
+
left
);
l
.
save
((
err
)
=>
{
if
(
err
)
return
res
.
serverError
(
err
);
delete
l
.
student
;
delete
l
.
id
;
return
res
.
ok
(
l
);
});
});
});
})
})
.
catch
(()
=>
{
.
catch
((
err
)
=>
{
return
res
.
serverError
();
return
res
.
serverError
(
err
);
});
});
})
})
.
catch
(()
=>
{
.
catch
(()
=>
{
...
...
sails/src/api/models/License.js
View file @
be65fb8e
...
@@ -23,7 +23,8 @@ module.exports = {
...
@@ -23,7 +23,8 @@ module.exports = {
student
:
{
// FK de Student. 1 a N
student
:
{
// FK de Student. 1 a N
columnName
:
"id_stu"
,
columnName
:
"id_stu"
,
type
:
"integer"
,
type
:
"integer"
,
model
:
"Student"
model
:
"Student"
,
unique
:
true
},
},
creation_ts
:
{
creation_ts
:
{
columnName
:
"creation_ts"
,
columnName
:
"creation_ts"
,
...
@@ -37,6 +38,10 @@ module.exports = {
...
@@ -37,6 +38,10 @@ module.exports = {
columnName
:
"duration"
,
columnName
:
"duration"
,
type
:
"integer"
type
:
"integer"
},
},
expiration_ts
:
{
columnName
:
"expiration_ts"
,
type
:
"datetime"
},
number
:
{
number
:
{
type
:
"string"
,
type
:
"string"
,
columnName
:
"number"
,
columnName
:
"number"
,
...
...
sails/src/config/policies.js
View file @
be65fb8e
...
@@ -112,8 +112,10 @@ module.exports.policies = {
...
@@ -112,8 +112,10 @@ module.exports.policies = {
},
},
LicenseController
:
{
LicenseController
:
{
create
:
[
'tokenAuth'
,
'isAdmin'
],
// create: ['tokenAuth', 'isAdmin'],
activate
:
[
'tokenAuth'
]
// activate: ['tokenAuth']
create
:
true
,
activate
:
true
},
},
SupervisorController
:
{
SupervisorController
:
{
...
...
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