Ok thanks !
As a matter of fact I have indeed an unique option set for the problematic
values. But I understood it as to prevent 2 same values for 2 different
users : as for an email for example. But here I try to update the profile
of the same user so obviously he should keep the same email or be able to
anyway.
I join the faulty code.
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
# -*- coding: utf-8 -*-
cache.ram.clear()
cache.disk.clear()
@auth.requires_login()
def index():
administrator = True
# verify if user is manager to be able to access administration menu
for row in db(db.auth_user.first_name == db.auth_user.first_name).select():
administrator = row.is_manager
first_name = row.first_name
last_name = row.last_name
nickname = row.nickname
email = row.email
address = row.address
postcode = row.postcode
city = row.city
country = row.country
website = row.website
# expose profile
db.auth_user.first_name.default = first_name
db.auth_user.last_name.default = last_name
db.auth_user.nickname.default = nickname
db.auth_user.email.default = email
db.auth_user.address.default = address
db.auth_user.postcode.default = postcode
db.auth_user.city.default = city
db.auth_user.country.default = country
db.auth_user.website.default = website
# TODO : CRUD TO READ
from gluon.tools import Crud
crud = Crud(db)
form = crud.update(db.auth_user, request.args(0))
if form.process(keepvalues=True, dbio=True).accepted:
response.flash = 'Your data has been updated'
elif form.errors:
response.flash = 'Some errors have been encountered ! Please contact your administrator.'
return dict(administrator=administrator, navbar_disable=False, form=form)
def user():
# CONTEXT DICTIONARY
context = {}
# DELETE COOKIES WHEN LOGOUT
if request.args[0] == 'logout':
for cookie_name in ['session_id_welcome', 'session_id_forums']:
response.cookies[cookie_name] = 'invalid'
response.cookies[cookie_name]['expires'] = -10
response.cookies[cookie_name]['path'] = '/'
# ENABLE REGISTER
if request.args[0] == 'register':
# ### VERIFICATION EMAIL
mail_config = {
'title': auth.default_messages.get('verify_email_subject'),
'subject_title': 'Verification email process..',
'verification_url': URL('default', 'user', scheme='http', args=['verify_email']) + '/%(key)s',
'verification_url_on_site': URL('default', 'browser_email', scheme='http') + '?key=%(key)s',
'verification_url_on_site_enabled': True,
'main_title_enabled': False,
'secondary_title_enabled': False,
'verify_email_block_enabled': True,
'spacer': URL('static', 'images/spacer.gif', scheme='http'),
}
auth.messages.verify_email = response.render('templates/email_verification.html', mail_config)
# AND LAST, RETURN FORM IN DICT
context['form'] = auth()
return context
def browser_email():
mail_config = dict(
title=auth.default_messages.get('verify_email_subject'),
subject_title='Verification email process..',
verification_url=URL('default', 'user', scheme='http',
args=['verify_email']) + '/' + request.vars['key'],
verification_url_on_site='',
verification_url_on_site_enabled=False,
illustration_image_enabled=False,
main_title_enabled=False,
secondary_title_enabled=False,
verify_email_block_enabled=True,
spacer=URL('static', 'images/spacer.gif', scheme='http'),
)
return response.render('templates/email_verification.html', mail_config)
# -*- coding: utf-8 -*-
# File is released under public domain and you can use without limitations
# auto-reload modules when changes are made
from gluon.custom_import import track_changes
track_changes(True)
# app configuration made easy, look inside private/appconfig.ini
from gluon.contrib.appconfig import AppConfig
# TODO : once in production, remove reload=True to gain full speed
my_conf = AppConfig(reload=True)
# connect to database
db = DAL(my_conf.take('db.uri'))
# necessary various imports
from gluon.tools import Auth, Service, PluginManager
auth = Auth(db)
service = Service()
plugins = PluginManager()
# give access to possibly current.(request, session, db, auth, response, T, cache)
# and many custom variables added by the current developer
from gluon import current
current.db = db
current.auth = auth
# if SSL/HTTPS is properly configured and you want all HTTP requests to
# be redirected to HTTPS, uncomment the line below:
# request.requires_https()
# ####################################################### SHARING SESSIONS
# record in a table on the database that the other application will access
session.connect(request, response, tablename='sessions')
# by default give a view/generic.extension to all actions from localhost
# none otherwise. a pattern can be 'controller/function.extension'
response.generic_patterns = ['*'] if request.is_local else []
# choose a style for forms
response.formstyle = my_conf.take('forms.formstyle') # or 'bootstrap3_stacked' or 'bootstrap2' or other
response.form_label_separator = my_conf.take('forms.separator')
# create auth table
db.define_table(
auth.settings.table_user_name,
Field('first_name', length=128),
Field('last_name', length=128),
Field('nickname', length=128, unique=True),
Field('email', length=128, unique=True),
Field('password', 'password', length=512, readable=False, writable=False, label='Password'),
Field('address', length=256),
Field('postcode', length=128),
Field('city', length=128),
Field('country', length=128, requires=IS_IN_SET(countries.COUNTRIES)),
Field('website', length=512),
Field('registration_key', length=512, writable=False, readable=False, default=''),
Field('reset_password_key', length=512, writable=False, readable=False, default=''),
Field('registration_id', length=512, writable=False, readable=False, default=''),
Field('auth_created_on', length=512, writable=False, readable=False, default='',
required=True),
Field('auth_modified_on', length=512, writable=False, readable=False, default='',
required=True),
Field('is_enabled', type='boolean', writable=False, readable=False, default=True,
required=False),
Field('is_manager', type='boolean', writable=False, readable=False, default=True),
migrate=False
)
# configure custom_auth_table
custom_auth_table = db[auth.settings.table_user_name]
custom_auth_table.first_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
custom_auth_table.last_name.requires = IS_NOT_EMPTY(error_message=auth.messages.is_empty)
custom_auth_table.password.requires = [IS_STRONG(min=8), CRYPT(digest_alg='sha512', salt=True)]
custom_auth_table.email.requires = [
IS_EMAIL(error_message=auth.messages.invalid_email),
IS_NOT_IN_DB(db, custom_auth_table.email)
]
# configure auth policy
auth.settings.registration_requires_verification = True
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True
auth.settings.login_after_registration = False
auth.settings.logged_url = URL('profile', 'default', 'index')
auth.settings.showid = False
auth.settings.table_user = custom_auth_table
# define tables
auth.define_tables(username=False, signature=True, migrate=False)
# configure email
mail = auth.settings.mailer
mail.settings.server = my_conf.take('smtp.server') # 'logging' if request.is_local else
mail.settings.sender = my_conf.take('smtp.sender')
mail.settings.login = my_conf.take('smtp.login')
mail.settings.tls = True
auth.messages.reset_password = '<html>Click on the link http://' + request.env.http_host\
+ URL(r=request, c='default', f='user',
args=['reset_password'])\
+ '/%(key)s to reset your password</html>'
# after defining tables, uncomment below to enable auditing
# auth.enable_record_versioning(db)