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 auth_signup
|
||||
import res_users
|
||||
|
|
|
@ -6,16 +6,13 @@
|
|||
'category': 'Authentication',
|
||||
'website': 'http://www.openerp.com',
|
||||
'installable': True,
|
||||
'depends': ['auth_anonymous', 'base_setup'],
|
||||
'depends': ['base_setup'],
|
||||
'data': [
|
||||
'res_config.xml',
|
||||
],
|
||||
'js': [
|
||||
'static/src/js/auth_signup.js',
|
||||
],
|
||||
'css': [
|
||||
'static/src/css/auth_signup.css',
|
||||
],
|
||||
'qweb': [
|
||||
'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) {
|
||||
instance.auth_signup = instance.auth_signup || {};
|
||||
var _t = instance.web._t;
|
||||
|
||||
instance.web.Login.include({
|
||||
start: function() {
|
||||
var self = this;
|
||||
|
||||
this.$('a.oe_signup').click(function() {
|
||||
var db = self.$("form [name=db]").val();
|
||||
if (!db) {
|
||||
self.do_warn(_t("Login"), _t("No database selected!"));
|
||||
return false;
|
||||
}
|
||||
|
||||
var cnx = instance.connection;
|
||||
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);
|
||||
});
|
||||
}
|
||||
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;
|
||||
});
|
||||
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({
|
||||
template: 'auth_signup.signup',
|
||||
init: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this.dataset = new instance.web.DataSet(this, 'auth.signup');
|
||||
init: function(parent, params) {
|
||||
this.params = params;
|
||||
return this._super();
|
||||
},
|
||||
start: function() {
|
||||
var self = this;
|
||||
this.$('input[type=password]').change(function() {
|
||||
this.$('input[name=password_confirmation]').keyup(function() {
|
||||
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');
|
||||
if (e) {
|
||||
if (_.isEmpty(v) || self.$('input[name=password]').val() === v) {
|
||||
$b.removeAttr('disabled');
|
||||
} else {
|
||||
$b.attr('disabled', 'disabled');
|
||||
|
@ -70,36 +43,19 @@ openerp.auth_signup = function(instance) {
|
|||
if(ev) {
|
||||
ev.preventDefault();
|
||||
}
|
||||
var name = self.$('input[name=name]').val();
|
||||
var email = self.$('input[name=email]').val();
|
||||
var password = self.$('input[name=password]').val();
|
||||
|
||||
self.dataset.create({
|
||||
name: name,
|
||||
email: email,
|
||||
password: password
|
||||
}, 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');
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
var params = {
|
||||
dbname : self.params.dbname,
|
||||
name: self.$('input[name=name]').val(),
|
||||
login: self.$('input[name=email]').val(),
|
||||
password: self.$('input[name=password]').val(),
|
||||
};
|
||||
var url = "/auth_signup/signup?" + $.param(params);
|
||||
window.location = url;
|
||||
return false;
|
||||
|
||||
});
|
||||
return $.when(this._super());
|
||||
return this._super();
|
||||
}
|
||||
|
||||
});
|
||||
instance.web.client_actions.add("auth_signup.signup", "instance.auth_signup.Signup");
|
||||
|
||||
|
||||
};
|
||||
|
|
|
@ -14,10 +14,10 @@
|
|||
<t t-name="auth_signup.signup">
|
||||
<div>
|
||||
<form>
|
||||
Name = <input type="text" name="name"/>
|
||||
Email = <input type="email" name="email"/>
|
||||
Password = <input type="password" name="password"/>
|
||||
Confirmation = <input type="password" name="password_confirmation"/>
|
||||
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>
|
||||
|
|
Loading…
Reference in New Issue