sign up with controller
bzr revid: al@openerp.com-20120812170603-mnp54q5xn9htg6vj
This commit is contained in:
parent
dd84bffaa8
commit
875d7541d9
|
@ -1,2 +1,3 @@
|
||||||
|
import controllers
|
||||||
import res_config
|
import res_config
|
||||||
import auth_signup
|
import res_users
|
||||||
|
|
|
@ -6,16 +6,13 @@
|
||||||
'category': 'Authentication',
|
'category': 'Authentication',
|
||||||
'website': 'http://www.openerp.com',
|
'website': 'http://www.openerp.com',
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'depends': ['auth_anonymous', 'base_setup'],
|
'depends': ['base_setup'],
|
||||||
'data': [
|
'data': [
|
||||||
'res_config.xml',
|
'res_config.xml',
|
||||||
],
|
],
|
||||||
'js': [
|
'js': [
|
||||||
'static/src/js/auth_signup.js',
|
'static/src/js/auth_signup.js',
|
||||||
],
|
],
|
||||||
'css': [
|
|
||||||
'static/src/css/auth_signup.css',
|
|
||||||
],
|
|
||||||
'qweb': [
|
'qweb': [
|
||||||
'static/src/xml/auth_signup.xml',
|
'static/src/xml/auth_signup.xml',
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,39 +0,0 @@
|
||||||
from openerp.osv import osv, fields
|
|
||||||
|
|
||||||
class res_users(osv.Model):
|
|
||||||
_inherit = 'res.users'
|
|
||||||
|
|
||||||
_sql_constraints = [
|
|
||||||
('email_uniq', 'UNIQUE (user_email)', 'You can not have two users with the same email!')
|
|
||||||
]
|
|
||||||
|
|
||||||
class signup_signup(osv.TransientModel):
|
|
||||||
_name = 'auth.signup'
|
|
||||||
|
|
||||||
# TODO add captcha
|
|
||||||
_columns = {
|
|
||||||
'name': fields.char('Name', size=64),
|
|
||||||
'email': fields.char('Email', size=64),
|
|
||||||
'password': fields.char('Password', size=64),
|
|
||||||
}
|
|
||||||
|
|
||||||
def create(self, cr, uid, values, context=None):
|
|
||||||
# NOTE here, invalid values raises exceptions to avoid storing
|
|
||||||
# sensitive data into the database (which then are available to anyone)
|
|
||||||
|
|
||||||
new_user = {
|
|
||||||
'name': values['name'],
|
|
||||||
'login': values['email'],
|
|
||||||
'user_email': values['email'],
|
|
||||||
'password': values['password'],
|
|
||||||
'active': True,
|
|
||||||
}
|
|
||||||
|
|
||||||
user_template_id = self.pool.get('ir.config_parameter').get_param(cr, uid, 'auth.signup_template_user_id', 0)
|
|
||||||
if user_template_id:
|
|
||||||
self.pool.get('res.users').copy(cr, 1, user_template_id, new_user, context=context)
|
|
||||||
else:
|
|
||||||
self.pool.get('res.users').create(cr, 1, new_user, context=context)
|
|
||||||
|
|
||||||
# Dont store anything
|
|
||||||
return 0
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
import main
|
||||||
|
|
||||||
|
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -0,0 +1,37 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import werkzeug.urls
|
||||||
|
|
||||||
|
import openerp.modules.registry
|
||||||
|
import openerp.addons.web.controllers.main
|
||||||
|
import openerp.addons.web.common.http as openerpweb
|
||||||
|
|
||||||
|
_logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
class OpenIDController(openerpweb.Controller):
|
||||||
|
_cp_path = '/auth_signup'
|
||||||
|
|
||||||
|
@openerpweb.httprequest
|
||||||
|
def signup(self, req, dbname, name, login, password):
|
||||||
|
registry = openerp.modules.registry.RegistryManager.get(dbname)
|
||||||
|
cr = registry.db.cursor()
|
||||||
|
try:
|
||||||
|
try:
|
||||||
|
u = registry.get('res.users')
|
||||||
|
r = u.auth_signup(cr, 1, name, login, password)
|
||||||
|
cr.commit()
|
||||||
|
return openerp.addons.web.controllers.main.login_and_redirect(req, dbname, login, password)
|
||||||
|
# or
|
||||||
|
req.authenticate(*r)
|
||||||
|
url = "/"
|
||||||
|
except AttributeError:
|
||||||
|
# auth_signup is not installed
|
||||||
|
url = "/#action=auth_signup&error=1"
|
||||||
|
except Exception,e:
|
||||||
|
# signup error
|
||||||
|
url = "/#action=auth_signup&error=2"
|
||||||
|
finally:
|
||||||
|
cr.close()
|
||||||
|
return werkzeug.utils.redirect(url)
|
||||||
|
|
||||||
|
# vim:expandtab:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -0,0 +1,47 @@
|
||||||
|
import openerp
|
||||||
|
from openerp.osv import osv, fields
|
||||||
|
|
||||||
|
class res_users(osv.Model):
|
||||||
|
_inherit = 'res.users'
|
||||||
|
|
||||||
|
def auth_signup_create(self, cr, uid, new_user, context=None):
|
||||||
|
user_template_id = self.pool.get('ir.config_parameter').get_param(cr, uid, 'auth.signup_template_user_id', 0)
|
||||||
|
if user_template_id:
|
||||||
|
self.pool.get('res.users').copy(cr, 1, user_template_id, new_user, context=context)
|
||||||
|
else:
|
||||||
|
self.pool.get('res.users').create(cr, 1, new_user, context=context)
|
||||||
|
|
||||||
|
def auth_signup_check(self, cr, uid, login, key, context=None):
|
||||||
|
res = self.search(cr, uid, [("login","=",login)])
|
||||||
|
if res:
|
||||||
|
user_id = res[0]['id']
|
||||||
|
self.check(cr.dbname, user_id, key)
|
||||||
|
return user_id
|
||||||
|
return False
|
||||||
|
|
||||||
|
def auth_signup(self, cr, uid, name, login, password, context=None):
|
||||||
|
r = (cr.dbname, login, password)
|
||||||
|
try:
|
||||||
|
# check for existing user
|
||||||
|
if not self.auth_signup_check(cr, uid, login, password):
|
||||||
|
print "NEW USER"
|
||||||
|
# new user
|
||||||
|
new_user = {
|
||||||
|
'name': name,
|
||||||
|
'login': login,
|
||||||
|
'user_email': login,
|
||||||
|
'password': password,
|
||||||
|
'active': True,
|
||||||
|
}
|
||||||
|
self.auth_signup_create(cr,uid, new_user)
|
||||||
|
return r
|
||||||
|
else:
|
||||||
|
print "Existing same"
|
||||||
|
# already existing with same password
|
||||||
|
return r
|
||||||
|
except openerp.exceptions.AccessDenied:
|
||||||
|
print "Existing different"
|
||||||
|
# already existing with diffrent password
|
||||||
|
raise
|
||||||
|
|
||||||
|
#
|
|
@ -1,9 +0,0 @@
|
||||||
.openerp .oe_login .oe_login_pane ul.oe_signup a {
|
|
||||||
color: #eeeeee;
|
|
||||||
margin: 0 8px;
|
|
||||||
}
|
|
||||||
.openerp .oe_login .oe_login_pane ul.oe_signup a:hover {
|
|
||||||
text-decoration: underline;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,65 +1,38 @@
|
||||||
openerp.auth_signup = function(instance) {
|
openerp.auth_signup = function(instance) {
|
||||||
|
instance.auth_signup = instance.auth_signup || {};
|
||||||
var _t = instance.web._t;
|
var _t = instance.web._t;
|
||||||
|
|
||||||
instance.web.Login.include({
|
instance.web.Login.include({
|
||||||
start: function() {
|
start: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.$('a.oe_signup').click(function() {
|
this.$('a.oe_signup').click(function() {
|
||||||
var db = self.$("form [name=db]").val();
|
var dbname = self.$("form [name=db]").val();
|
||||||
if (!db) {
|
self.do_action({
|
||||||
self.do_warn(_t("Login"), _t("No database selected!"));
|
type: 'ir.actions.client',
|
||||||
return false;
|
tag: 'auth_signup.signup',
|
||||||
}
|
params: {'dbname': dbname},
|
||||||
|
target: 'new',
|
||||||
var cnx = instance.connection;
|
name: 'Sign up'
|
||||||
if (cnx.session_is_valid()) {
|
});
|
||||||
self._signup();
|
|
||||||
} else {
|
|
||||||
cnx.session_authenticate(db, 'anonymous', 'anonymous', true).then(function() {
|
|
||||||
self._signup();
|
|
||||||
}).fail(function(error, event) {
|
|
||||||
console.log(error);
|
|
||||||
// cannot log as anonymous or auth_signup not installed
|
|
||||||
self.do_warn(_t('Sign Up'), _.str.sprintf(_t('Signup functionnality is not available for database %s'), db), true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
return this._super();
|
return this._super();
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
_signup: function() {
|
|
||||||
this.do_action({
|
|
||||||
type: 'ir.actions.client',
|
|
||||||
tag: 'auth_signup.signup',
|
|
||||||
target: 'new',
|
|
||||||
name: 'Sign up'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
instance.auth_signup = instance.auth_signup || {};
|
|
||||||
instance.auth_signup.Signup = instance.web.Widget.extend({
|
instance.auth_signup.Signup = instance.web.Widget.extend({
|
||||||
template: 'auth_signup.signup',
|
template: 'auth_signup.signup',
|
||||||
init: function() {
|
init: function(parent, params) {
|
||||||
this._super.apply(this, arguments);
|
this.params = params;
|
||||||
this.dataset = new instance.web.DataSet(this, 'auth.signup');
|
return this._super();
|
||||||
},
|
},
|
||||||
start: function() {
|
start: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.$('input[type=password]').change(function() {
|
this.$('input[name=password_confirmation]').keyup(function() {
|
||||||
var v = $(this).val();
|
var v = $(this).val();
|
||||||
var e = !_.isEmpty(v);
|
|
||||||
if (e) {
|
|
||||||
e =_.all(self.$('input[type=password]'), function(i) {
|
|
||||||
return $(i).val() === v;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
var $b = self.$('button');
|
var $b = self.$('button');
|
||||||
if (e) {
|
if (_.isEmpty(v) || self.$('input[name=password]').val() === v) {
|
||||||
$b.removeAttr('disabled');
|
$b.removeAttr('disabled');
|
||||||
} else {
|
} else {
|
||||||
$b.attr('disabled', 'disabled');
|
$b.attr('disabled', 'disabled');
|
||||||
|
@ -70,36 +43,19 @@ openerp.auth_signup = function(instance) {
|
||||||
if(ev) {
|
if(ev) {
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
}
|
}
|
||||||
var name = self.$('input[name=name]').val();
|
var params = {
|
||||||
var email = self.$('input[name=email]').val();
|
dbname : self.params.dbname,
|
||||||
var password = self.$('input[name=password]').val();
|
name: self.$('input[name=name]').val(),
|
||||||
|
login: self.$('input[name=email]').val(),
|
||||||
self.dataset.create({
|
password: self.$('input[name=password]').val(),
|
||||||
name: name,
|
};
|
||||||
email: email,
|
var url = "/auth_signup/signup?" + $.param(params);
|
||||||
password: password
|
window.location = url;
|
||||||
}, function() {
|
|
||||||
self.do_action({
|
|
||||||
type: 'ir.actions.client',
|
|
||||||
tag: 'login',
|
|
||||||
params: {
|
|
||||||
db: instance.connection.db,
|
|
||||||
login: email,
|
|
||||||
password: password,
|
|
||||||
login_successful: function() {
|
|
||||||
self.do_action('home');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
});
|
});
|
||||||
return $.when(this._super());
|
return this._super();
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
instance.web.client_actions.add("auth_signup.signup", "instance.auth_signup.Signup");
|
instance.web.client_actions.add("auth_signup.signup", "instance.auth_signup.Signup");
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,10 +14,10 @@
|
||||||
<t t-name="auth_signup.signup">
|
<t t-name="auth_signup.signup">
|
||||||
<div>
|
<div>
|
||||||
<form>
|
<form>
|
||||||
Name = <input type="text" name="name"/>
|
Name = <input type="text" name="name"/><br/>
|
||||||
Email = <input type="email" name="email"/>
|
Email = <input type="email" name="email"/><br/>
|
||||||
Password = <input type="password" name="password"/>
|
Password = <input type="password" name="password"/><br/>
|
||||||
Confirmation = <input type="password" name="password_confirmation"/>
|
Confirmation = <input type="password" name="password_confirmation"/><br/>
|
||||||
<button type="submit" disabled="disabled">Signup</button>
|
<button type="submit" disabled="disabled">Signup</button>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue