Comparing version 0.0.2 to 0.0.4
@@ -6,11 +6,34 @@ var structr = require("structr"), | ||
var host = window.location.protocol + "//" + window.location.host; | ||
if(window.location.port && String(window.location.port).length > 0) { | ||
host += ":" + window.location.port; | ||
} | ||
console.log(host); | ||
// console.log(window.location) | ||
var Account; | ||
return Account = structr({ | ||
/** | ||
*/ | ||
"__construct": function(data) { | ||
_.extend(this, data); | ||
}, | ||
/** | ||
*/ | ||
"save": function() { | ||
//TODO | ||
}, | ||
/** | ||
*/ | ||
"static login": function(data, onLogin) { | ||
if(arguments.length == 1) { | ||
@@ -26,6 +49,22 @@ onLogin = data; | ||
success: function(resp) { | ||
if(resp.errors) return onLogin(new Error(resp.errors[0])); | ||
if(resp.errors) return onLogin(resp.errors); | ||
onLogin(null, new Account(resp.result)); | ||
} | ||
}) | ||
}, | ||
/** | ||
*/ | ||
"static signup": function(data, onSignup) { | ||
$.ajax({ | ||
type: "POST", | ||
data: data, | ||
url: host + "/account.json", | ||
success: function(resp) { | ||
if(resp.errors) return onLogin(resp.errors); | ||
onLogin(null, new Account(resp.result)); | ||
} | ||
}) | ||
} | ||
@@ -32,0 +71,0 @@ }); |
@@ -1,2 +0,3 @@ | ||
var vine = require("vine"); | ||
var vine = require("vine"), | ||
comerr = require("comerr"); | ||
@@ -19,4 +20,4 @@ exports.plugin = function(auth) { | ||
if(/\.json$/.test(req.path)) return res.send(vine.error(new Error("unauthorized"))); | ||
if(/\.json$/.test(req.path)) return res.send(vine.error(new comerr.Unauthorized("you must be logged in to view this page"))); | ||
return res.redirect("/login?redirect_to=" + req.originalUrl); | ||
@@ -23,0 +24,0 @@ // return res.send(vine.error(err)); |
@@ -21,2 +21,17 @@ var step = require("step"), | ||
account.getMainToken(function(err, token) { | ||
req.session.token = token.key; | ||
if(!render) { | ||
if(err) { | ||
return res.send(vine.error(err)); | ||
} else { | ||
var obj = account.toObject(); | ||
delete obj.password; //why is this still here?? | ||
obj.token = token; | ||
res.send(vine.result(obj)); | ||
} | ||
return; | ||
} | ||
if(err) return res.render(render, { | ||
@@ -26,3 +41,2 @@ error: err.message | ||
req.session.token = token.key; | ||
res.redirect(req.query.redirect_to || loader.params("http.loginRedirect") || "/"); | ||
@@ -33,11 +47,13 @@ }); | ||
httpServer.get("/account.json", auth.middleware.authCheckpoint, function(req, res) { | ||
req.account.getMainToken(function(err, token) { | ||
var obj = req.account.toObject(); | ||
obj.token = token; | ||
res.send(vine.result(obj)); | ||
}); | ||
getToken(req, res, req.account); | ||
}); | ||
httpServer.post("/account.json", function(req, res) { | ||
Account.signup(req.body, function(err, account) { | ||
if(err) return res.send(vine.error(err)); | ||
getToken(req, res, account); | ||
}) | ||
}) | ||
httpServer.get("/login", function(req, res) { | ||
@@ -117,2 +133,4 @@ res.render("login", { | ||
httpServer.post("/signup", function(req, res) { | ||
console.log("signing up") | ||
var on = reqOutcome(req, res, "signup"); | ||
@@ -119,0 +137,0 @@ |
var _ = require("underscore"), | ||
access = require("../access"); | ||
access = require("../access"), | ||
comerr = require("comerr"); | ||
@@ -37,3 +38,3 @@ | ||
if(err) return callback(err); | ||
if(!account) return callback(new Error("account does't exist")); | ||
if(!account) return callback(new comerr.NotFound("account does't exist")); | ||
callback(err, account); | ||
@@ -40,0 +41,0 @@ }); |
@@ -10,3 +10,5 @@ var access = require("../access"), | ||
structr = require("structr"), | ||
outcome = require("outcome"); | ||
outcome = require("outcome"), | ||
comerr = require("comerr"), | ||
verify = require("verify")(); | ||
@@ -22,2 +24,5 @@ exports.model = function(options) { | ||
verify.register("password", "Invalid password. Must be at least 6 chars.").len(6); | ||
/** | ||
@@ -135,5 +140,4 @@ */ | ||
var err = new Error("Unauthorized"); | ||
var err = new comerr.Unauthorized(); | ||
return arguments.length ? callback(err) : err; | ||
@@ -212,11 +216,21 @@ } | ||
Account.statics.signup = function(acc, callback) { | ||
var Account = this, | ||
account = new Account(acc); | ||
var Account = this; | ||
if(!verify.check(acc).onError(callback).has("email", "password").success) return; | ||
var on = outcome.error(callback); | ||
console.log("SIGNUP") | ||
account.save(outcome.error(callback).success(function(account) { | ||
callback(null, account); | ||
Account.emit("signup", account); | ||
})); | ||
step( | ||
function() { | ||
Account.findOne({ email: acc.email }, this); | ||
}, | ||
on.success(function(account) { | ||
if(account) return callback(new comerr.AlreadyExists("That account name is already taken.")); | ||
new Account(acc).save(this); | ||
}), | ||
on.success(function(account) { | ||
callback(null, account); | ||
Account.emit("signup", account); | ||
}) | ||
); | ||
} | ||
@@ -243,3 +257,3 @@ | ||
this.findOne(q, outcome.error(callback).success(function(account) { | ||
if(!account) return callback(new Error("incorrect username / password")); | ||
if(!account) return callback(new comerr.IncorrectInput("incorrect username / password")); | ||
callback(null, account); | ||
@@ -246,0 +260,0 @@ })); |
@@ -12,3 +12,4 @@ | ||
_ = require("underscore"), | ||
dsync = require("dsync"); | ||
dsync = require("dsync"), | ||
comerr = require("comerr"); | ||
@@ -162,3 +163,3 @@ exports.model = function(database) { | ||
//404 | ||
if(!token) return callback(new Error("token does not exist")); | ||
if(!token) return callback(new comerr.NotFound("token does not exist", { type: "token" })); | ||
@@ -168,3 +169,3 @@ //expired - TODO - add in query: {$or:[{expiresAt:null},{expiresAt:{$lt:new Date()}}]} | ||
token.remove(); | ||
return callback(new Error("token has expired")); | ||
return callback(new comerr.Expired("token has expired")); | ||
} | ||
@@ -182,3 +183,4 @@ | ||
if(!account) return callback(new Error("account does not exist")); | ||
//this shouldn't happen | ||
if(!account) return callback(new comerr.NotFound("account does not exist", { type: "account" })); | ||
@@ -185,0 +187,0 @@ a = account; |
{ | ||
"name": "auth", | ||
"version": "0.0.2", | ||
"version": "0.0.4", | ||
"description": "ERROR: No README.md file found!", | ||
@@ -21,5 +21,7 @@ "main": "./lib/index.js", | ||
"dsync": "0.0.x", | ||
"vine": "0.0.x", | ||
"vine": "0.1.x", | ||
"dustjs-linkedin": "1.1.x", | ||
"seq": "0.3.x" | ||
"seq": "0.3.x", | ||
"comerr": "0.0.x", | ||
"verify": "0.0.x" | ||
}, | ||
@@ -26,0 +28,0 @@ "browserify": "./browser/index.js", |
35446
10
26
1051
+ Addedcomerr@0.0.x
+ Addedverify@0.0.x
+ Addedcomerr@0.0.9(transitive)
+ Addedsift@0.0.18(transitive)
+ Addedtoarray@0.0.1(transitive)
+ Addedvalidator@0.4.28(transitive)
+ Addedverify@0.0.10(transitive)
+ Addedvine@0.1.1(transitive)
- Removedvine@0.0.14(transitive)
Updatedvine@0.1.x