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
ebc987b4
authored
Apr 19, 2016
by
Pablo Molina
Browse files
Options
_('Browse Files')
Download
Plain Diff
Merged origin/master into master
parents
43f9b70f
66ed4620
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
75 deletions
sails/src/api/controllers/SupervisorController.js
sails/src/api/models/Supervisor.js
sails/src/assets/app/img/logo_pictogram.png
sails/src/assets/app/modules/login/controllers/signin.js
sails/src/assets/app/modules/login/views/signin.html
sails/src/api/controllers/SupervisorController.js
View file @
ebc987b4
...
...
@@ -151,20 +151,25 @@ module.exports = {
// adds a new supervisor into the database
//
create
:
function
(
req
,
res
)
{
var
params
=
req
.
params
.
all
();
var
params
=
req
.
params
.
all
();
delete
params
.
email_confirm
;
delete
params
.
password_confirm
;
Supervisor
.
create
(
params
).
exec
(
function
(
err
,
created
)
{
if
(
err
)
{
console
.
log
(
err
);
return
res
.
json
(
500
,
{
error
:
'User not created'
});
}
if
(
created
)
{
// Send email confirmation
console
.
log
(
"sending mail to user"
);
created
.
sendMail
();
return
res
.
json
({
user
:
created
,
token
:
sailsTokenAuth
.
issueToken
(
created
.
id
)});
}
});
Supervisor
.
create
(
params
).
exec
(
function
(
err
,
created
)
{
if
(
err
)
{
console
.
log
(
err
);
return
res
.
json
(
500
,
{
error
:
'User not created'
});
}
if
(
created
)
{
// TODO: Send email confirmation
// created.sendMail();
return
res
.
json
({
user
:
created
,
token
:
sailsTokenAuth
.
issueToken
(
created
.
id
)});
}
else
{
return
res
.
json
(
500
,
{
error
:
'User not created'
});
}
});
},
//
...
...
sails/src/api/models/Supervisor.js
View file @
ebc987b4
...
...
@@ -186,32 +186,33 @@ module.exports = {
//
beforeCreate
:
function
(
attrs
,
next
)
{
//
// Check that user does not exist
// NOTE: This is not needed as uniqueness is granted by DB
//
Supervisor
.
findByEmail
(
attrs
.
email
).
exec
(
function
(
err
,
users
)
{
if
(
err
)
return
next
(
err
);
if
(
users
.
length
>
0
)
return
next
(
new
Error
(
'User exists'
));
});
//
// Encrypt password before insertion
//
var
bcrypt
=
require
(
'bcrypt-nodejs'
);
// We have to encryption AFTER checking user does not exist
// so... we use async.series to ensure task completion
bcrypt
.
genSalt
(
10
,
function
(
err
,
salt
)
{
if
(
err
)
return
next
(
err
);
bcrypt
.
hash
(
attrs
.
password
,
salt
,
null
,
function
(
err
,
hash
)
{
if
(
err
)
return
next
(
err
);
attrs
.
password
=
hash
;
next
();
});
});
async
.
series
([
function
(
cb
)
{
// check email is new
Supervisor
.
findByEmail
(
attrs
.
email
).
exec
(
function
(
err
,
users
)
{
if
(
err
)
return
cb
(
err
);
if
(
users
.
length
>
0
)
return
cb
(
new
Error
(
'User exists'
));
cb
();
});
},
function
(
cb
)
{
// encrypt password
var
bcrypt
=
require
(
'bcrypt-nodejs'
);
bcrypt
.
genSalt
(
10
,
function
(
err
,
salt
)
{
if
(
err
)
return
cb
(
err
);
bcrypt
.
hash
(
attrs
.
password
,
salt
,
null
,
function
(
err
,
hash
)
{
if
(
err
)
return
cb
(
err
);
attrs
.
password
=
hash
;
cb
();
});
});
}
],
function
(
err
)
{
if
(
err
)
return
next
(
err
);
next
();
});
},
//
...
...
@@ -220,37 +221,45 @@ module.exports = {
//
beforeUpdate
:
function
(
attrs
,
next
)
{
//
// Check that user email does not exist
//
if
(
attrs
.
email
){
Supervisor
.
findByEmail
(
attrs
.
email
).
exec
(
function
(
err
,
users
)
{
if
(
err
)
return
next
(
err
);
if
(
users
.
length
>
0
)
return
next
(
new
Error
(
'User email already exists'
));
});
}
//
// Encrypt password before insertion
//
if
(
attrs
.
password
){
var
bcrypt
=
require
(
'bcrypt-nodejs'
);
bcrypt
.
genSalt
(
10
,
function
(
err
,
salt
)
{
if
(
err
)
return
next
(
err
);
bcrypt
.
hash
(
attrs
.
password
,
salt
,
null
,
function
(
err
,
hash
)
{
if
(
err
)
return
next
(
err
);
attrs
.
password
=
hash
;
next
();
});
});
}
else
{
next
();
}
async
.
series
([
function
(
cb
)
{
//
// Check that user email does not exist
//
if
(
attrs
.
email
){
Supervisor
.
findByEmail
(
attrs
.
email
).
exec
(
function
(
err
,
users
)
{
if
(
err
)
return
cb
(
err
);
if
(
users
.
length
>
0
)
return
cb
(
new
Error
(
'User email already exists'
));
cb
();
});
}
else
{
return
cb
(
new
Error
(
'No email in user attributes'
));
}
},
function
(
cb
)
{
//
// Encrypt password before insertion
//
if
(
attrs
.
password
){
var
bcrypt
=
require
(
'bcrypt-nodejs'
);
bcrypt
.
genSalt
(
10
,
function
(
err
,
salt
)
{
if
(
err
)
return
cb
(
err
);
bcrypt
.
hash
(
attrs
.
password
,
salt
,
null
,
function
(
err
,
hash
)
{
if
(
err
)
return
cb
(
err
);
attrs
.
password
=
hash
;
cb
();
});
});
}
else
{
cb
();
}
}],
function
(
err
)
{
if
(
err
)
return
next
(
err
);
next
();
});
},
//
...
...
sails/src/assets/app/img/logo_pictogram.png
View file @
ebc987b4
9.04 KB
|
W:
|
H:
4.5 KB
|
W:
|
H:
2-up
Swipe
Onion skin
sails/src/assets/app/modules/login/controllers/signin.js
View file @
ebc987b4
...
...
@@ -21,7 +21,7 @@ dashboardControllers.controller('SignInCtrl', function SignInCtrl($scope, $http,
lang
:
'es'
};
reCAPTCHA
.
setPublicKey
(
'6Ld
kZwMTAAAAANDR_7_y9_ifEve1gLPcgneM_50o
'
);
reCAPTCHA
.
setPublicKey
(
'6Ld
Ljh0TAAAAANblo_KUGNnmRZuIetOkdjdhj1b6
'
);
/* NOT NECESSARY
// Array of key terms to translate
...
...
@@ -84,8 +84,8 @@ dashboardControllers.controller('SignInCtrl', function SignInCtrl($scope, $http,
$scope
.
alert
=
"alert-danger"
;
$scope
.
message
=
"user_exists"
;
console
.
log
(
"Error from API: "
+
data
.
error
);
console
.
log
(
"Error from API: "
+
status
);
});
};
});
\ No newline at end of file
});
sails/src/assets/app/modules/login/views/signin.html
View file @
ebc987b4
...
...
@@ -102,4 +102,4 @@
</div>
<!-- Fin de container -->
<footer-translate></footer-translate>
\ No newline at end of file
<footer-translate></footer-translate>
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