Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
simcaq-node
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
simcaq
simcaq-node
Commits
c0e9561c
There was a problem fetching the pipeline summary.
Commit
c0e9561c
authored
8 years ago
by
Lucas Gabriel Lima
Browse files
Options
Downloads
Patches
Plain Diff
refactor user route
parent
1a5d1440
No related branches found
No related tags found
1 merge request
!20
Auth
Pipeline
#
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/libs/routes/user.js
+26
-20
26 additions, 20 deletions
src/libs/routes/user.js
with
26 additions
and
20 deletions
src/libs/routes/user.js
+
26
−
20
View file @
c0e9561c
...
...
@@ -14,32 +14,38 @@ const jwt = require('jwt-simple');
function
emailSyntax
(
email
)
{
regex
=
/^
(([^
<>()
\[\]\.
,;:
\s
@
\"]
+
(\.[^
<>()
\[\]\.
,;:
\s
@
\"]
+
)
*
)
|
(\"
.+
\"))
@
(([^
<>()[
\]\.
,;:
\s
@
\"]
+
\.)
+
[^
<>()[
\]\.
,;:
\s
@
\"]{2,})
$/i
;
return
regex
.
test
(
email
);
const
regex
=
/^
(([^
<>()
\[\]\.
,;:
\s
@
\"]
+
(\.[^
<>()
\[\]\.
,;:
\s
@
\"]
+
)
*
)
|
(\"
.+
\"))
@
(([^
<>()[
\]\.
,;:
\s
@
\"]
+
\.)
+
[^
<>()[
\]\.
,;:
\s
@
\"]{2,})
$/i
;
return
regex
.
test
(
email
);
}
userApp
.
post
(
'
/
'
,
(
req
,
res
)
=>
{
userApp
.
post
(
'
/
'
,
(
req
,
res
,
next
)
=>
{
if
(
!
req
.
body
.
email
||
!
req
.
body
.
password
)
{
res
.
json
({
success
:
false
,
msg
:
'
Please pass email and password.
'
});
}
else
{
next
();
}
else
{
if
(
!
emailSyntax
(
req
.
body
.
email
)){
res
.
json
({
success
:
false
,
msg
:
'
Invalid email syntax.
'
});
}
var
newUser
=
new
User
({
email
:
req
.
body
.
email
,
password
:
req
.
body
.
password
});
const
jwt
=
require
(
'
jwt-simple
'
);
// save the user
newUser
.
save
((
err
)
=>
{
if
(
err
)
{
return
res
.
json
({
success
:
false
,
msg
:
'
Email already in use.
'
});
}
res
.
json
({
success
:
true
,
msg
:
'
Successful created new user.
'
});
});
},
(
req
,
res
,
next
)
=>
{
if
(
!
emailSyntax
(
req
.
body
.
email
)){
res
.
json
({
success
:
false
,
msg
:
'
Invalid email syntax.
'
});
}
else
{
next
();
}
},
(
req
,
res
,
next
)
=>
{
var
newUser
=
new
User
({
email
:
req
.
body
.
email
,
password
:
req
.
body
.
password
});
// save the user
newUser
.
save
((
err
)
=>
{
if
(
err
)
{
res
.
json
({
success
:
false
,
msg
:
'
Email already in use.
'
});
}
else
{
res
.
json
({
success
:
true
,
msg
:
'
Successful created new user.
'
});
}
});
});
userApp
.
post
(
'
/authenticate
'
,
(
req
,
res
)
=>
{
...
...
@@ -63,7 +69,7 @@ userApp.post('/authenticate', (req, res) => {
res
.
json
({
success
:
true
,
token
:
'
JWT
'
+
token
});
}
else
{
res
.
send
({
success
:
false
,
msg
:
'
Authentication failed. Wrong password
'
});
res
.
json
({
success
:
false
,
msg
:
'
Authentication failed. Wrong password
'
});
}
})
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment