summaryrefslogtreecommitdiff
path: root/addons/auth_signup/static/src
diff options
context:
space:
mode:
authorMayur Maheshwari (OpenERP) <mma@tinyerp.com>2012-10-10 10:49:17 +0530
committerMayur Maheshwari (OpenERP) <mma@tinyerp.com>2012-10-10 10:49:17 +0530
commit79a84ffc5d2afaec71225b0e70dcccb79ecc8239 (patch)
tree0e6b2ae62ba8d02d7c1d987b438a02ed7baea07f /addons/auth_signup/static/src
parent9487c2d9ba9381e04c677d861864e29895f48e8e (diff)
parent49b102b54a860e655156fced1940ae6b913a7458 (diff)
[MERGE]: Merge with lp:openobject-addons
bzr revid: mma@tinyerp.com-20121010051917-0ep6z3xy0ff92kzo
Diffstat (limited to 'addons/auth_signup/static/src')
-rw-r--r--addons/auth_signup/static/src/css/Makefile3
-rw-r--r--addons/auth_signup/static/src/css/base.css10
-rw-r--r--addons/auth_signup/static/src/css/base.sass13
-rw-r--r--addons/auth_signup/static/src/js/auth_signup.js121
-rw-r--r--addons/auth_signup/static/src/xml/auth_signup.xml44
5 files changed, 130 insertions, 61 deletions
diff --git a/addons/auth_signup/static/src/css/Makefile b/addons/auth_signup/static/src/css/Makefile
new file mode 100644
index 00000000000..d6b4f4b2fc8
--- /dev/null
+++ b/addons/auth_signup/static/src/css/Makefile
@@ -0,0 +1,3 @@
+base.css: base.sass
+ sass --trace -t expanded base.sass base.css
+
diff --git a/addons/auth_signup/static/src/css/base.css b/addons/auth_signup/static/src/css/base.css
new file mode 100644
index 00000000000..3f97e7a9301
--- /dev/null
+++ b/addons/auth_signup/static/src/css/base.css
@@ -0,0 +1,10 @@
+@charset "utf-8";
+.openerp .oe_login .oe_signup_show {
+ display: none;
+}
+.openerp .oe_login_signup .oe_signup_show {
+ display: block !important;
+}
+.openerp .oe_login_signup .oe_signup_hide {
+ display: none;
+}
diff --git a/addons/auth_signup/static/src/css/base.sass b/addons/auth_signup/static/src/css/base.sass
new file mode 100644
index 00000000000..f97665d192c
--- /dev/null
+++ b/addons/auth_signup/static/src/css/base.sass
@@ -0,0 +1,13 @@
+@charset "utf-8"
+
+.openerp
+ // Regular login form
+ .oe_login
+ .oe_signup_show
+ display: none
+ // Signup form
+ .oe_login_signup
+ .oe_signup_show
+ display: block !important
+ .oe_signup_hide
+ display: none
diff --git a/addons/auth_signup/static/src/js/auth_signup.js b/addons/auth_signup/static/src/js/auth_signup.js
index 2ab13aa7598..509fafa35cc 100644
--- a/addons/auth_signup/static/src/js/auth_signup.js
+++ b/addons/auth_signup/static/src/js/auth_signup.js
@@ -5,56 +5,99 @@ openerp.auth_signup = function(instance) {
instance.web.Login.include({
start: function() {
var self = this;
- this.$('a.oe_signup').click(function() {
- var dbname = self.$("form [name=db]").val();
- self.do_action({
- type: 'ir.actions.client',
- tag: 'auth_signup.signup',
- params: {'dbname': dbname},
- target: 'new',
- name: 'Sign up'
- });
- return true;
+ var d = this._super();
+
+ // to switch between the signup and regular login form
+ this.$('a.oe_signup_signup').click(function() {
+ self.$el.addClass("oe_login_signup");
+ });
+ this.$('a.oe_signup_back').click(function() {
+ self.$el.removeClass("oe_login_signup");
+ delete self.params.token;
});
- return this._super();
- },
- });
+ // if there is an error message in params, show it then forget it
+ if (self.params.error_message) {
+ this.show_error(self.params.error_message);
+ delete self.params.error_message;
+ }
- instance.auth_signup.Signup = instance.web.Widget.extend({
- template: 'auth_signup.signup',
- init: function(parent, params) {
- this.params = params;
- return this._super();
+ // in case of a signup, retrieve the user information from the token
+ if (self.params.db && self.params.token) {
+ d = self.rpc("/auth_signup/retrieve", {dbname: self.params.db, token: self.params.token})
+ .done(self.on_token_loaded)
+ .fail(self.on_token_failed);
+ }
+ return d;
},
- start: function() {
- var self = this;
- this.$('input[name=password_confirmation]').keyup(function() {
- var v = $(this).val();
- var $b = self.$('button');
- if (_.isEmpty(v) || self.$('input[name=password]').val() === v) {
- $b.removeAttr('disabled');
+ on_token_loaded: function(result) {
+ // select the right the database
+ this.selected_db = result.db;
+ this.on_db_loaded({db_list: [result.db]});
+ if (result.token) {
+ // switch to signup mode, set user name and login
+ this.$el.addClass("oe_login_signup");
+ this.$("form input[name=name]").val(result.name).attr("readonly", "readonly");
+ if (result.login) {
+ this.$("form input[name=login]").val(result.login).attr("readonly", "readonly");
} else {
- $b.attr('disabled', 'disabled');
+ this.$("form input[name=login]").val(result.email);
}
- });
-
- this.$('form').submit(function(ev) {
- if(ev) {
- ev.preventDefault();
+ } else {
+ // remain in login mode, set login if present
+ delete this.params.token;
+ this.$("form input[name=login]").val(result.login || "");
+ }
+ },
+ on_token_failed: function(result, ev) {
+ if (ev) {
+ ev.preventDefault();
+ }
+ this.show_error("Invalid signup token");
+ delete this.params.db;
+ delete this.params.token;
+ },
+ on_submit: function(ev) {
+ if (ev) {
+ ev.preventDefault();
+ }
+ if (this.$el.hasClass("oe_login_signup")) {
+ // signup user (or reset password)
+ var db = this.$("form [name=db]").val();
+ var name = this.$("form input[name=name]").val();
+ var login = this.$("form input[name=login]").val();
+ var password = this.$("form input[name=password]").val();
+ var confirm_password = this.$("form input[name=confirm_password]").val();
+ if (!db) {
+ this.do_warn("Login", "No database selected !");
+ return false;
+ } else if (!name) {
+ this.do_warn("Login", "Please enter a name.")
+ return false;
+ } else if (!login) {
+ this.do_warn("Login", "Please enter a username.")
+ return false;
+ } else if (!password || !confirm_password) {
+ this.do_warn("Login", "Please enter a password and confirm it.")
+ return false;
+ } else if (password !== confirm_password) {
+ this.do_warn("Login", "Passwords do not match; please retype them.")
+ return false;
}
var params = {
- dbname : self.params.dbname,
- name: self.$('input[name=name]').val(),
- login: self.$('input[name=email]').val(),
- password: self.$('input[name=password]').val(),
+ dbname : db,
+ token: this.params.token || "",
+ name: name,
+ login: login,
+ password: password,
};
var url = "/auth_signup/signup?" + $.param(params);
window.location = url;
- });
- return this._super();
- }
+ } else {
+ // regular login
+ this._super(ev);
+ }
+ },
});
- instance.web.client_actions.add("auth_signup.signup", "instance.auth_signup.Signup");
};
diff --git a/addons/auth_signup/static/src/xml/auth_signup.xml b/addons/auth_signup/static/src/xml/auth_signup.xml
index c2eec846d15..e63bd5863b0 100644
--- a/addons/auth_signup/static/src/xml/auth_signup.xml
+++ b/addons/auth_signup/static/src/xml/auth_signup.xml
@@ -1,28 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- vim:fdl=1:
--->
+<!-- vim:fdl=1: -->
<templates id="template" xml:space="preserve">
-<t t-extend="Login">
- <t t-jquery="form ul:first li:last" t-operation="after">
- <li>
- <a class="oe_signup" href="#">Sign Up</a>
- </li>
+ <t t-extend="Login">
+ <t t-jquery="form ul:first li:contains('Username')" t-operation="before">
+ <li class="oe_signup_show">Name</li>
+ <li class="oe_signup_show"><input name="name" type="text"/></li>
+ </t>
+ <t t-jquery="form ul:first li:contains('Username')" t-operation="replace">
+ <li class="oe_signup_hide">Username</li>
+ <li class="oe_signup_show">Username (Email)</li>
+ </t>
+ <t t-jquery="form ul:first li:has(input[name=password])" t-operation="after">
+ <li class="oe_signup_show">Confirm Password</li>
+ <li class="oe_signup_show"><input name="confirm_password" type="password"/></li>
+ </t>
+ <t t-jquery="form ul:first li:has(button[name=submit])" t-operation="replace">
+ <li class="oe_signup_hide"><button name="submit">Log in</button></li>
+ <li class="oe_signup_show"><button name="submit">Sign in</button></li>
+ </t>
+ <t t-jquery="form ul:first li:last" t-operation="after">
+ <li><a class="oe_signup_hide oe_signup_signup" href="#">Sign Up</a></li>
+ <li><a class="oe_signup_show oe_signup_back" href="#">Back to Login</a></li>
+ </t>
</t>
-</t>
-
-<t t-name="auth_signup.signup">
- <div>
- <form>
- Name = <input type="text" name="name"/><br/>
- Email = <input type="email" name="email"/><br/>
- Password = <input type="password" name="password"/><br/>
- Confirmation = <input type="password" name="password_confirmation"/><br/>
- <button type="submit" disabled="disabled">Signup</button>
- </form>
- </div>
-</t>
-
-
</templates>