Skip to content

Instantly share code, notes, and snippets.

@jarrettmeyer
Last active August 29, 2015 14:04
Show Gist options
  • Save jarrettmeyer/bcfa0548bda0b5543e12 to your computer and use it in GitHub Desktop.
Save jarrettmeyer/bcfa0548bda0b5543e12 to your computer and use it in GitHub Desktop.
Login View Example
CookieUtil = (function () {
var expirationDays = 14;
function deleteCookie(key) {
var expiration = new Date(0).toGMTString();
document.cookie = key + "=;expires=" + expiration;
}
function getCookie(key) {
}
function getExpiration() {
var now = Date.now();
var expirationDuration = expirationDays * 24 * 60 * 60 * 1000;
var expirationTime = now + expirationDuration;
return new Date(expirationTime);
}
function init(options) {
}
function setCookie(key, value) {
}
return {
getCookie: getCookie,
init: init,
setCookie: setCookie
}
}).call(this);
LoginService = (function () {
function LoginService() {
if (!$) {
throw Error("jQuery is not defined!");
}
}
LoginService.prototype.login = function (data, callback) {
$.post("/login", function(result) {
if (result.isValid) {
callback(null, result);
} else {
callback({ message: "Invalid credentials!" }, result);
}
});
};
return LoginService;
}).call(this);
LoginView = (function () {
function LoginView() {
this.initializeBindings();
this.loginService = new LoginService();
}
LoginView.prototype.initializeBindings = function () {
$("#login-button").on("click", function () {
this.login();
}.bind(this));
};
LoginView.prototype.login = function () {
var data = getLoginData();
this.loginService.login(function (error, result) {
});
};
function getLoginData() {
return {
username: $("#username").val(),
password: $("#password").val()
};
}
return LoginView;
}).call(this);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment