##// END OF EJS Templates
feat(git lfs path and path to hg large files in *.ini files): moved git lfs path and path of hg large files to *.ini files.
feat(git lfs path and path to hg large files in *.ini files): moved git lfs path and path of hg large files to *.ini files.

File last commit:

r5353:7a7f1159 default
r5535:7350be7a default
Show More
user_schema.py
202 lines | 6.3 KiB | text/x-python | PythonLexer
copyrights: updated for 2023
r5088 # Copyright (C) 2016-2023 RhodeCode GmbH
dan
account: convert change password form to colander schema and fix bug...
r665 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
user-api: use simple schema validator to be consistent how we validate between API and web views.
r1832 import re
dan
account: convert change password form to colander schema and fix bug...
r665 import colander
from rhodecode import forms
Bartłomiej Wołyńczyk
my-account: security change, added select filed with email from extra emails while editing user profile, now adding extra emails required type password. Task #5386
r2592 from rhodecode.model.db import User, UserEmailMap
user-api: use simple schema validator to be consistent how we validate between API and web views.
r1832 from rhodecode.model.validation_schema import types, validators
dan
account: convert change password form to colander schema and fix bug...
r665 from rhodecode.translation import _
from rhodecode.lib.auth import check_password
Bartłomiej Wołyńczyk
my-account: security change, added select filed with email from extra emails while editing user profile, now adding extra emails required type password. Task #5386
r2592 from rhodecode.lib import helpers as h
dan
account: convert change password form to colander schema and fix bug...
r665
@colander.deferred
def deferred_user_password_validator(node, kw):
username = kw.get('username')
user = User.get_by_username(username)
def _user_password_validator(node, value):
if not check_password(value, user.password):
msg = _('Password is incorrect')
raise colander.Invalid(node, msg)
return _user_password_validator
Bartłomiej Wołyńczyk
my-account: security change, added select filed with email from extra emails while editing user profile, now adding extra emails required type password. Task #5386
r2592
dan
account: convert change password form to colander schema and fix bug...
r665 class ChangePasswordSchema(colander.Schema):
current_password = colander.SchemaNode(
colander.String(),
missing=colander.required,
widget=forms.widget.PasswordWidget(redisplay=True),
validator=deferred_user_password_validator)
new_password = colander.SchemaNode(
colander.String(),
missing=colander.required,
widget=forms.widget.CheckedPasswordWidget(redisplay=True),
validator=colander.Length(min=6))
def validator(self, form, values):
if values['current_password'] == values['new_password']:
exc = colander.Invalid(form)
exc['new_password'] = _('New password must be different '
'to old password')
raise exc
user-api: use simple schema validator to be consistent how we validate between API and web views.
r1832
@colander.deferred
def deferred_username_validator(node, kw):
feat(forms): user profile form would detect nicely duplicates and show a form error.
r5353 old_username = kw.get('username')
user-api: use simple schema validator to be consistent how we validate between API and web views.
r1832
def name_validator(node, value):
msg = _(
modernize: updates for python3
r5095 'Username may only contain alphanumeric characters '
'underscores, periods or dashes and must begin with '
'alphanumeric character or underscore')
user-api: use simple schema validator to be consistent how we validate between API and web views.
r1832
if not re.match(r'^[\w]{1}[\w\-\.]{0,254}$', value):
raise colander.Invalid(node, msg)
feat(forms): user profile form would detect nicely duplicates and show a form error.
r5353 if value != old_username:
existing_user = User.get_by_username(value, case_insensitive=True)
if existing_user:
raise colander.Invalid(node, 'Username is already taken')
user-api: use simple schema validator to be consistent how we validate between API and web views.
r1832 return name_validator
@colander.deferred
def deferred_email_validator(node, kw):
# NOTE(marcink): we might provide uniqueness validation later here...
return colander.Email()
class UserSchema(colander.Schema):
username = colander.SchemaNode(
colander.String(),
validator=deferred_username_validator)
email = colander.SchemaNode(
colander.String(),
validator=deferred_email_validator)
password = colander.SchemaNode(
colander.String(), missing='')
first_name = colander.SchemaNode(
colander.String(), missing='')
last_name = colander.SchemaNode(
colander.String(), missing='')
users: description edit fixes...
r4024 description = colander.SchemaNode(
colander.String(), missing='')
user-api: use simple schema validator to be consistent how we validate between API and web views.
r1832 active = colander.SchemaNode(
types.StringBooleanType(),
missing=False)
admin = colander.SchemaNode(
types.StringBooleanType(),
missing=False)
extern_name = colander.SchemaNode(
colander.String(), missing='')
extern_type = colander.SchemaNode(
colander.String(), missing='')
def deserialize(self, cstruct):
"""
Custom deserialize that allows to chain validation, and verify
permissions, and as last step uniqueness
"""
modernize: updates for python3
r5095 appstruct = super().deserialize(cstruct)
user-api: use simple schema validator to be consistent how we validate between API and web views.
r1832 return appstruct
Bartłomiej Wołyńczyk
my-account: security change, added select filed with email from extra emails while editing user profile, now adding extra emails required type password. Task #5386
r2592
@colander.deferred
def deferred_user_email_in_emails_validator(node, kw):
return colander.OneOf(kw.get('user_emails'))
@colander.deferred
def deferred_additional_email_validator(node, kw):
emails = kw.get('user_emails')
def name_validator(node, value):
if value in emails:
msg = _('This e-mail address is already taken')
raise colander.Invalid(node, msg)
user = User.get_by_email(value, case_insensitive=True)
if user:
modernize: updates for python3
r5095 msg = _('This e-mail address is already taken')
Bartłomiej Wołyńczyk
my-account: security change, added select filed with email from extra emails while editing user profile, now adding extra emails required type password. Task #5386
r2592 raise colander.Invalid(node, msg)
c = colander.Email()
return c(node, value)
return name_validator
@colander.deferred
def deferred_user_email_in_emails_widget(node, kw):
import deform.widget
emails = [(email, email) for email in kw.get('user_emails')]
return deform.widget.Select2Widget(values=emails)
class UserProfileSchema(colander.Schema):
username = colander.SchemaNode(
colander.String(),
validator=deferred_username_validator)
firstname = colander.SchemaNode(
colander.String(), missing='', title='First name')
lastname = colander.SchemaNode(
colander.String(), missing='', title='Last name')
users: add edition of description in admin view for users
r4022 description = colander.SchemaNode(
colander.String(), missing='', title='Personal Description',
widget=forms.widget.TextAreaWidget(),
validator=colander.Length(max=250)
)
Bartłomiej Wołyńczyk
my-account: security change, added select filed with email from extra emails while editing user profile, now adding extra emails required type password. Task #5386
r2592 email = colander.SchemaNode(
colander.String(), widget=deferred_user_email_in_emails_widget,
validator=deferred_user_email_in_emails_validator,
description=h.literal(
_('Additional emails can be specified at <a href="{}">extra emails</a> page.').format(
'/_admin/my_account/emails')),
)
users: add edition of description in admin view for users
r4022
Bartłomiej Wołyńczyk
my-account: security change, added select filed with email from extra emails while editing user profile, now adding extra emails required type password. Task #5386
r2592 class AddEmailSchema(colander.Schema):
current_password = colander.SchemaNode(
colander.String(),
missing=colander.required,
widget=forms.widget.PasswordWidget(redisplay=True),
validator=deferred_user_password_validator)
email = colander.SchemaNode(
colander.String(), title='New Email',
validator=deferred_additional_email_validator)