summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/login/signup.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/assets/js/lib/views/login/signup.js')
-rw-r--r--public/assets/js/lib/views/login/signup.js49
1 files changed, 49 insertions, 0 deletions
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("<br>"))
+ },
+
+ 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"
+ }
+ },
+
+})