From 41d0bd185c19c8a51ed9b85700f52181b6cc5012 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 12 Dec 2017 02:09:15 +0100 Subject: color stuff, building settings form --- public/assets/js/lib/views/login/signup.js | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 public/assets/js/lib/views/login/signup.js (limited to 'public/assets/js/lib/views/login') diff --git a/public/assets/js/lib/views/login/signup.js b/public/assets/js/lib/views/login/signup.js new file mode 100644 index 0000000..d3d407d --- /dev/null +++ b/public/assets/js/lib/views/login/signup.js @@ -0,0 +1,49 @@ +var SignupView = FormView.extend({ + + el: "#signup", + action: "/api/signup", + method: "put", + + initialize: function(opt){ + this.__super__.initialize.call(this) + $("body").removeClass("loading") + this.$("[name=username]").focus() + }, + + validate: function(){ + var errors = [] + if (! this.$("[name=username]").val().length) { + errors.push("Please enter a username") + } + if (! this.$("[name=password]").val().length) { + errors.push("Please enter a password") + } + if (this.$("[name=password]").val() !== this.$("[name=password2]").val()) { + errors.push("Passwords don't match") + } + return errors.length ? errors : null + }, + + showErrors: function(errors){ + $(".errors").show().css({ opacity: 1 }).html(errors.join("
")) + }, + + success: function(data){ + console.log("LOGGED IN?", data) + if (data.user) { + auth.set_user(data.user) + } + else { + this.showErrors() + return + } + if (data.returnTo) { + console.log(data.returnTo) + window.location.href = data.returnTo + } + else { + window.location.href = "/index" + } + }, + +}) -- cgit v1.2.3-70-g09d2