2012-07-25 23:02:17 +00:00
|
|
|
openerp.auth_signup = function(instance) {
|
2012-08-12 17:06:03 +00:00
|
|
|
instance.auth_signup = instance.auth_signup || {};
|
2012-08-06 15:38:32 +00:00
|
|
|
var _t = instance.web._t;
|
2012-06-25 12:26:30 +00:00
|
|
|
|
2012-08-06 15:38:32 +00:00
|
|
|
instance.web.Login.include({
|
2012-06-25 12:26:30 +00:00
|
|
|
start: function() {
|
|
|
|
var self = this;
|
2012-09-25 10:40:13 +00:00
|
|
|
var d = this._super();
|
2012-09-25 14:34:33 +00:00
|
|
|
|
2012-09-25 10:40:13 +00:00
|
|
|
// hide the signup fields in the case of a regular login
|
|
|
|
self.on_change_mode()
|
|
|
|
self.$("form input[name=signup]").click(self.on_change_mode);
|
2012-09-25 14:34:33 +00:00
|
|
|
|
|
|
|
// if there is an error message, show it then forget it
|
|
|
|
if (self.params.error_message) {
|
|
|
|
this.$el.addClass('oe_login_invalid');
|
|
|
|
this.$(".oe_login_error_message").text(self.params.error_message);
|
|
|
|
delete self.params.error_message;
|
|
|
|
} else {
|
|
|
|
this.$el.removeClass('oe_login_invalid');
|
|
|
|
this.$(".oe_login_error_message").text("Invalid username or password");
|
|
|
|
}
|
|
|
|
|
2012-09-25 10:40:13 +00:00
|
|
|
// 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;
|
2012-08-06 15:38:32 +00:00
|
|
|
},
|
2012-09-25 10:40:13 +00:00
|
|
|
on_token_loaded: function(result) {
|
|
|
|
// set the name and login of user
|
|
|
|
this.selected_db = result.db;
|
|
|
|
this.on_db_loaded({db_list: [result.db]});
|
|
|
|
this.$("form input[name=signup]").val(result.login ? [] : ["check_signup"]);
|
|
|
|
this.$("form input[name=name]").val(result.name);
|
|
|
|
this.$("form input[name=login]").val(result.login || result.email);
|
|
|
|
this.$("form input[name=password]").val("");
|
|
|
|
this.$("form input[name=confirm_password]").val("");
|
|
|
|
this.on_change_mode();
|
2012-08-07 16:36:19 +00:00
|
|
|
},
|
2012-09-25 14:34:33 +00:00
|
|
|
on_token_failed: function(result, ev) {
|
|
|
|
if (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
this.$el.addClass('oe_login_invalid');
|
|
|
|
this.$(".oe_login_error_message").text("Invalid signup token");
|
|
|
|
delete this.params.db;
|
|
|
|
delete this.params.token;
|
2012-09-25 10:40:13 +00:00
|
|
|
},
|
|
|
|
on_change_mode: function() {
|
|
|
|
// 'mode' has changed: regular login, sign up, reset password
|
|
|
|
var is_signup = this.$("input[name=signup]:checked").val();
|
|
|
|
this.$(".oe_signup").toggleClass('oe_form_invisible', false && !is_signup);
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
on_submit: function(ev) {
|
|
|
|
if (ev) {
|
|
|
|
ev.preventDefault();
|
|
|
|
}
|
|
|
|
if (this.params.token || this.$("input[name=signup]:checked").val()) {
|
|
|
|
// signup user (or reset password)
|
2012-09-25 14:34:33 +00:00
|
|
|
var db = this.$("form [name=db]").val();
|
2012-09-25 10:40:13 +00:00
|
|
|
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();
|
2012-09-25 14:34:33 +00:00
|
|
|
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;
|
2012-08-07 16:36:19 +00:00
|
|
|
}
|
2012-09-25 14:34:33 +00:00
|
|
|
var params = {
|
|
|
|
dbname : db,
|
|
|
|
token: this.params.token || "",
|
|
|
|
name: name,
|
|
|
|
login: login,
|
|
|
|
password: password,
|
|
|
|
};
|
|
|
|
var url = "/auth_signup/signup?" + $.param(params);
|
|
|
|
window.location = url;
|
2012-09-25 10:40:13 +00:00
|
|
|
} else {
|
|
|
|
// regular login
|
|
|
|
this._super(ev);
|
|
|
|
}
|
|
|
|
},
|
2012-08-07 16:36:19 +00:00
|
|
|
});
|
|
|
|
|
2012-06-25 12:26:30 +00:00
|
|
|
};
|