diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website_profile/models | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website_profile/models')
| -rw-r--r-- | addons/website_profile/models/__init__.py | 6 | ||||
| -rw-r--r-- | addons/website_profile/models/gamification_badge.py | 9 | ||||
| -rw-r--r-- | addons/website_profile/models/res_users.py | 66 | ||||
| -rw-r--r-- | addons/website_profile/models/website.py | 10 |
4 files changed, 91 insertions, 0 deletions
diff --git a/addons/website_profile/models/__init__.py b/addons/website_profile/models/__init__.py new file mode 100644 index 00000000..e5d082ad --- /dev/null +++ b/addons/website_profile/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import gamification_badge +from . import website +from . import res_users diff --git a/addons/website_profile/models/gamification_badge.py b/addons/website_profile/models/gamification_badge.py new file mode 100644 index 00000000..3c02cedb --- /dev/null +++ b/addons/website_profile/models/gamification_badge.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models + + +class GamificationBadge(models.Model): + _name = 'gamification.badge' + _inherit = ['gamification.badge', 'website.published.mixin'] diff --git a/addons/website_profile/models/res_users.py b/addons/website_profile/models/res_users.py new file mode 100644 index 00000000..6b184ddc --- /dev/null +++ b/addons/website_profile/models/res_users.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import hashlib +import uuid + +from datetime import datetime +from werkzeug import urls +from odoo import api, models + +VALIDATION_KARMA_GAIN = 3 + + +class Users(models.Model): + _inherit = 'res.users' + + def __init__(self, pool, cr): + init_res = super(Users, self).__init__(pool, cr) + type(self).SELF_WRITEABLE_FIELDS = list( + set( + self.SELF_WRITEABLE_FIELDS + + ['country_id', 'city', 'website', 'website_description', 'website_published'])) + type(self).SELF_READABLE_FIELDS = type(self).SELF_READABLE_FIELDS + ['karma'] + return init_res + + @api.model + def _generate_profile_token(self, user_id, email): + """Return a token for email validation. This token is valid for the day + and is a hash based on a (secret) uuid generated by the forum module, + the user_id, the email and currently the day (to be updated if necessary). """ + profile_uuid = self.env['ir.config_parameter'].sudo().get_param('website_profile.uuid') + if not profile_uuid: + profile_uuid = str(uuid.uuid4()) + self.env['ir.config_parameter'].sudo().set_param('website_profile.uuid', profile_uuid) + return hashlib.sha256((u'%s-%s-%s-%s' % ( + datetime.now().replace(hour=0, minute=0, second=0, microsecond=0), + profile_uuid, + user_id, + email + )).encode('utf-8')).hexdigest() + + def _send_profile_validation_email(self, **kwargs): + if not self.email: + return False + token = self._generate_profile_token(self.id, self.email) + activation_template = self.env.ref('website_profile.validation_email') + if activation_template: + params = { + 'token': token, + 'user_id': self.id, + 'email': self.email + } + params.update(kwargs) + base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') + token_url = base_url + '/profile/validate_email?%s' % urls.url_encode(params) + with self._cr.savepoint(): + activation_template.sudo().with_context(token_url=token_url).send_mail( + self.id, force_send=True, raise_exception=True) + return True + + def _process_profile_validation_token(self, token, email): + self.ensure_one() + validation_token = self._generate_profile_token(self.id, email) + if token == validation_token and self.karma == 0: + return self.write({'karma': VALIDATION_KARMA_GAIN}) + return False diff --git a/addons/website_profile/models/website.py b/addons/website_profile/models/website.py new file mode 100644 index 00000000..76a37eba --- /dev/null +++ b/addons/website_profile/models/website.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class Website(models.Model): + _inherit = 'website' + + karma_profile_min = fields.Integer(string="Minimal karma to see other user's profile", default=150) |
