Skip to content

Commit

Permalink
mobile users only login once
Browse files Browse the repository at this point in the history
  • Loading branch information
daleharvey committed Oct 29, 2010
1 parent 42b1be6 commit 43dc9e9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 15 deletions.
51 changes: 38 additions & 13 deletions _attachments/focus.js
@@ -1,13 +1,15 @@
var Focus = (function () {

var dbName = "focus",
var dbName = "focus",
mobilePass = "couch!db",
adminParty = null,
urlPrefix = "/",
router = new Router(),
user = null,
userDoc = null,
profiles = [],
db = null;
urlPrefix = "/",
isMobile = isMobile(),
router = new Router(),
user = null,
userDoc = null,
profiles = [],
db = null;

var xhrCache = {},
docCache = {};
Expand Down Expand Up @@ -86,7 +88,7 @@ var Focus = (function () {
if (user !== null) {
router.go("#!");
} else {
render("#content", "#signup");
renderSignup();
}
});
router.get("!/login", function () {
Expand Down Expand Up @@ -280,17 +282,14 @@ var Focus = (function () {
if (continous) {
opts.continous = true;
}
console.log(db);
$.couch.replicate(source, target, opts, {
error: function() {
console.log(arguments);
},
success: function (data) {
console.log(data);
if (continous) {
db.replicate(target, source, opts, callback);
} else {
console.log("hello");
callback(data);
}
}
Expand Down Expand Up @@ -591,11 +590,19 @@ var Focus = (function () {

function ensureLoggedIn(verb, url, args) {
if (verb === 'GET' && user === null && !anonAccess(url)) {
render("#content", "#signup");
renderSignup();;
return false;
}
return true;
};

function renderSignup() {
var data = !isMobile ? {} : {
display_pass : "style='display:none'",
password : mobilePass
};
render("#content", "#signup", data);
};

function render(dom, tpl, data) {
$("#content").removeClass("loading");
Expand Down Expand Up @@ -626,12 +633,25 @@ var Focus = (function () {
initComet();
}
});
} else if (isMobile) {

// Mobile Browsers will be logged in automatically
$.couch.db("_users").allDocs({
include_docs:true,
success: function(data) {
$.couch.login({
name : data.rows[1].doc.name,
password : mobilePass,
success : function() { window.location.reload(true); }
});
}
});
} else {
router.init();
}
});
};

function loadUsers(callback) {
fetch("user-created", {group:true}, function(users) {
for (var keys = [], i = 0; i < users.rows.length; i += 1) {
Expand Down Expand Up @@ -682,6 +702,11 @@ var Focus = (function () {
});
};

function isMobile() {
return navigator.userAgent.toLowerCase()
.match(/(andoid|iphone|ipod)/) !== null;
};

// I dont like these global events, they are bound to the page permanently
// so may cause conflicts
function bindEvents() {
Expand Down
4 changes: 2 additions & 2 deletions _attachments/index.html
Expand Up @@ -139,7 +139,7 @@ <h3>Focus - Sign Up</h3>
id="signup_email"
value="" name="email" placeholder="username" />
</label>
<label for="password">
<label for="password" {{display_pass}}>
<span>Password</span>
<input type="password" value="" name="password" />
</label>
Expand All @@ -156,7 +156,7 @@ <h3>Focus - Sign Up</h3>
value="local" name="workgroup" placeholder="username" />
</label>
<input type="submit" value="Sign Up" />
or <a href="#!/login">Login</a>
<span {{display_pass}}>or <a href="#!/login">Login</a></span>
</form>
</script>

Expand Down

0 comments on commit 43dc9e9

Please sign in to comment.