Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
persona
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Hexang 息壤平台
persona
Commits
fd3b60c7
Commit
fd3b60c7
authored
13 years ago
by
Ben Adida
Browse files
Options
Downloads
Patches
Plain Diff
further refactoring to use express goodness
parent
5042fdc4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
browserid/lib/wsapi.js
+15
-22
15 additions, 22 deletions
browserid/lib/wsapi.js
with
15 additions
and
22 deletions
browserid/lib/wsapi.js
+
15
−
22
View file @
fd3b60c7
...
...
@@ -15,9 +15,7 @@ function checkParams(params) {
if
(
req
.
method
===
"
POST
"
)
{
params_in_request
=
req
.
body
;
}
else
{
var
getArgs
=
req
.
query
;
req
.
get
=
getArgs
;
params_in_request
=
getArgs
;
params_in_request
=
req
.
query
;
}
try
{
...
...
@@ -63,23 +61,24 @@ function setup(app) {
* user via their claimed email address. Upon timeout expiry OR clickthrough
* the staged user account transitions to a valid user account */
app
.
get
(
'
/wsapi/stage_user
'
,
checkParams
([
"
email
"
,
"
pass
"
,
"
pubkey
"
,
"
site
"
]),
function
(
req
,
resp
)
{
var
getArgs
=
req
.
get
;
// bcrypt the password
getArgs
.
hash
=
bcrypt
.
encrypt_sync
(
getArgs
.
pass
,
bcrypt
.
gen_salt_sync
(
10
));
// we should be cloning this object here.
var
stageParams
=
req
.
query
;
stageParams
[
'
hash
'
]
=
bcrypt
.
encrypt_sync
(
req
.
query
.
pass
,
bcrypt
.
gen_salt_sync
(
10
));
try
{
// upon success, stage_user returns a secret (that'll get baked into a url
// and given to the user), on failure it throws
var
secret
=
db
.
stageUser
(
getArg
s
);
var
secret
=
db
.
stageUser
(
stageParam
s
);
// store the email being registered in the session data
if
(
!
req
.
session
)
req
.
session
=
{};
// store inside the session the details of this pending verification
req
.
session
.
pendingVerification
=
{
email
:
getArg
s
.
email
,
hash
:
getArg
s
.
hash
// we must store both email and password to handle the case where
email
:
stageParam
s
.
email
,
hash
:
stageParam
s
.
hash
// we must store both email and password to handle the case where
// a user re-creates an account - specifically, registration status
// must ensure the new credentials work to properly verify that
// the user has clicked throught the email link. note, this salted, bcrypted
...
...
@@ -90,7 +89,7 @@ function setup(app) {
httputils
.
jsonResponse
(
resp
,
true
);
// let's now kick out a verification email!
email
.
sendVerificationEmail
(
getArgs
.
email
,
getArg
s
.
site
,
secret
);
email
.
sendVerificationEmail
(
stageParams
.
email
,
stageParam
s
.
site
,
secret
);
}
catch
(
e
)
{
// we should differentiate tween' 400 and 500 here.
...
...
@@ -145,11 +144,10 @@ function setup(app) {
app
.
get
(
'
/wsapi/authenticate_user
'
,
checkParams
([
"
email
"
,
"
pass
"
]),
function
(
req
,
resp
)
{
var
getArgs
=
req
.
get
;
db
.
checkAuth
(
getArgs
.
email
,
getArgs
.
pass
,
function
(
rv
)
{
db
.
checkAuth
(
req
.
query
.
email
,
req
.
query
.
pass
,
function
(
rv
)
{
if
(
rv
)
{
if
(
!
req
.
session
)
req
.
session
=
{};
req
.
session
.
authenticatedUser
=
getArgs
.
email
;
req
.
session
.
authenticatedUser
=
req
.
query
.
email
;
}
httputils
.
jsonResponse
(
resp
,
rv
);
});
...
...
@@ -157,20 +155,18 @@ function setup(app) {
// FIXME: need CSRF protection
app
.
get
(
'
/wsapi/add_email
'
,
checkAuthed
,
checkParams
([
"
email
"
,
"
pubkey
"
,
"
site
"
]),
function
(
req
,
resp
)
{
var
getArgs
=
req
.
get
;
try
{
// upon success, stage_user returns a secret (that'll get baked into a url
// and given to the user), on failure it throws
var
secret
=
db
.
stageEmail
(
req
.
session
.
authenticatedUser
,
getArgs
.
email
,
getArgs
.
pubkey
);
var
secret
=
db
.
stageEmail
(
req
.
session
.
authenticatedUser
,
req
.
query
.
email
,
req
.
query
.
pubkey
);
// store the email being added in session data
req
.
session
.
pendingAddition
=
getArgs
.
email
;
req
.
session
.
pendingAddition
=
req
.
query
.
email
;
httputils
.
jsonResponse
(
resp
,
true
);
// let's now kick out a verification email!
email
.
sendVerificationEmail
(
getArgs
.
email
,
getArgs
.
site
,
secret
);
email
.
sendVerificationEmail
(
req
.
query
.
email
,
req
.
query
.
site
,
secret
);
}
catch
(
e
)
{
// we should differentiate tween' 400 and 500 here.
httputils
.
badRequest
(
resp
,
e
.
toString
());
...
...
@@ -202,8 +198,7 @@ function setup(app) {
});
app
.
get
(
'
/wsapi/set_key
'
,
checkAuthed
,
checkParams
([
"
email
"
,
"
pubkey
"
]),
function
(
req
,
resp
)
{
var
getArgs
=
req
.
get
;
db
.
addKeyToEmail
(
req
.
session
.
authenticatedUser
,
getArgs
.
email
,
getArgs
.
pubkey
,
function
(
rv
)
{
db
.
addKeyToEmail
(
req
.
session
.
authenticatedUser
,
req
.
query
.
email
,
req
.
query
.
pubkey
,
function
(
rv
)
{
httputils
.
jsonResponse
(
resp
,
rv
);
});
});
...
...
@@ -236,9 +231,7 @@ function setup(app) {
});
app
.
get
(
'
/wsapi/prove_email_ownership
'
,
checkParams
([
"
token
"
]),
function
(
req
,
resp
)
{
var
getArgs
=
req
.
get
;
db
.
gotVerificationSecret
(
getArgs
.
token
,
function
(
e
)
{
db
.
gotVerificationSecret
(
req
.
query
.
token
,
function
(
e
)
{
if
(
e
)
{
console
.
log
(
"
error completing the verification:
"
+
e
);
httputils
.
jsonResponse
(
resp
,
false
);
...
...
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