[TYPO] Set the right category for the Point Of Sale
[odoo/odoo.git] / addons / signup / signup.py
1 from openerp.osv import osv, fields
2
3 class res_users(osv.Model):
4     _inherit = 'res.users'
5
6     _sql_constraints = [
7         ('email_uniq', 'UNIQUE (user_email)', 'You can not have two users with the same email!')
8     ]
9
10 class signup_signup(osv.TransientModel):
11     _name = 'signup.signup'
12     _columns = {
13         'name': fields.char('Name', size=64),
14         'email': fields.char('Email', size=64),
15         'password': fields.char('Password', size=64),
16         'password_confirmation': fields.char('Confirm Password', size=64),
17         'state': fields.selection([(x, x) for x in 'draft done missmatch'.split()], required=True),
18     }
19     _defaults = {
20         'state': 'draft',
21     }
22
23     def create(self, cr, uid, values, context=None):
24         # NOTE here, invalid values raises exceptions to avoid storing
25         # sensitive data into the database (which then are available to anyone)
26         if values['password'] != values['password_confirmation']:
27             raise osv.except_osv('Error', 'Passwords missmatch')
28
29         new_user = {
30             'name': values['name'],
31             'login': values['email'],
32             'user_email': values['email'],
33             'password': values['password'],
34             'active': True,
35         }
36
37         user_template_id = self.pool.get('ir.config_parameter').get_param(cr, uid, 'signup.user_template_id', 0)
38         if user_template_id:
39             self.pool.get('res.users').copy(cr, 1, user_template_id, new_user, context=context)
40         else:
41             self.pool.get('res.users').create(cr, 1, new_user, context=context)
42
43         # Dont store the password
44         values = {'state': 'done'}
45         return super(signup_signup, self).create(cr, uid, values, context)
46
47     def signup(self, cr, uid, ids, context=None):
48         return {
49             'type': 'ir.actions.client',
50             'tag': 'login',
51         }
52
53     def onchange_pw(self, cr, uid, ids, pw, cpw, context=None):
54         if pw != cpw:
55             return {'value': {'state': 'missmatch'}}
56         return {'value': {'state': 'draft'}}
57