def verify_email(form): from gluon.utils import web2py_uuid if str2bool(self.config.take('auth_local.admin_registration_requires_verification')): d = dict(form.vars) key = web2py_uuid() link = URL('default', 'user', args=('verify_email', key), scheme=True) d = dict(form.vars) plain_password = web2py_uuid().split('-')[0] md5_password = self.db.auth_user.password.validate(plain_password)[0] d.update(dict(registration_key=key, password=md5_password)) self.db(self.db['auth_user']._id==form.vars.id).update(**d) from myapp import Mailer notification = Mailer() if notification.send_email(form.vars.email, 'VERIFY YOUR EMAIL', 'verify_email', link=link, password=plain_password): self.session.flash = "Email sent to the user for verification" else: self.session.flash = "Email unsent, uppss there is a error"
def grid(self): fields = dict(auth_user=[self.db.auth_user.first_name, self.db.auth_user.email, self.db.auth_user.registration_key]) self.db.auth_user.registration_key.readable = True if str2bool(self.config.take('auth_local.admin_registration_requires_verification')): self.db.auth_user.password.readable = False self.db.auth_user.password.writable = False else: self.db.auth_user.password.readable = True self.db.auth_user.password.writable = True fields["auth_user"][2].represent = lambda value, row: SPAN('active', _class='label label-success') \ if value == "" else SPAN(value, _class='label label-info') links = dict(auth_user=[ lambda row: A('Enable', _class="btn-success btn-mini", callback=URL('users', 'action', args=[str(row.id), 'enable'])) if row.registration_key == 'blocked' or row.registration_key == 'disabled' else "", lambda row: A('Block', _class="btn-danger btn-mini", callback=URL('users', 'action', args=[str(row.id), 'block'])) if row.registration_key == '' else "", lambda row: A('Approve', _class="btn btn-info btn-mini", callback=URL('users', 'action', args=[str(row.id), 'enable'])) if row.registration_key == 'pending' else "",]) def verify_email(form): from gluon.utils import web2py_uuid if str2bool(self.config.take('auth_local.admin_registration_requires_verification')): d = dict(form.vars) key = web2py_uuid() link = URL('default', 'user', args=('verify_email', key), scheme=True) d = dict(form.vars) plain_password = web2py_uuid().split('-')[0] md5_password = self.db.auth_user.password.validate(plain_password)[0] d.update(dict(registration_key=key, password=md5_password)) self.db(self.db['auth_user']._id==form.vars.id).update(**d) from myapp import Mailer notification = Mailer() if notification.send_email(form.vars.email, 'VERIFY YOUR EMAIL', 'verify_email', link=link, password=plain_password): self.session.flash = "Email sent to the user for verification" else: self.session.flash = "Email unsent, uppss there is a error" linked_tables = ['auth_membership'] if self.config.take('general.auth_type') == 'local': grid = SQLFORM.smartgrid(self.db.auth_user, ui='web2py', linked_tables=linked_tables, fields=fields, #orderby=fields[-2], links=links, csv=False, searchable=True, create=True, details=True, editable=True, deletable=True, oncreate=verify_email,) else: grid = SQLFORM.smartgrid(self.db.auth_user, ui='web2py', linked_tables=linked_tables, fields=fields, #orderby=fields[-2], links=links, csv=False, searchable=True, create=False, details=True, editable=False, deletable=True) return grid
def grid(self): fields = dict( auth_user=[self.db.auth_user.first_name, self.db.auth_user.email, self.db.auth_user.registration_key] ) self.db.auth_user.registration_key.readable = True if str2bool(self.config.take("auth_local.admin_registration_requires_verification")): self.db.auth_user.password.readable = False self.db.auth_user.password.writable = False else: self.db.auth_user.password.readable = True self.db.auth_user.password.writable = True fields["auth_user"][2].represent = ( lambda value, row: SPAN("active", _class="label label-success") if value == "" else SPAN(value, _class="label label-info") ) links = dict( auth_user=[ lambda row: A( "Enable", _class="btn-success btn-mini", callback=URL("users", "action", args=[str(row.id), "enable"]), ) if row.registration_key == "blocked" or row.registration_key == "disabled" else "", lambda row: A( "Block", _class="btn-danger btn-mini", callback=URL("users", "action", args=[str(row.id), "block"]) ) if row.registration_key == "" else "", lambda row: A( "Approve", _class="btn btn-info btn-mini", callback=URL("users", "action", args=[str(row.id), "enable"]), ) if row.registration_key == "pending" else "", ] ) def verify_email(form): from gluon.utils import web2py_uuid if str2bool(self.config.take("auth_local.admin_registration_requires_verification")): d = dict(form.vars) key = web2py_uuid() link = URL("default", "users", args=("verify_email", key), scheme=True) d = dict(form.vars) plain_password = web2py_uuid().split("-")[0] md5_password = self.db.auth_user.password.validate(plain_password)[0] d.update(dict(registration_key=key, password=md5_password)) self.db(self.db["auth_user"]._id == form.vars.id).update(**d) from myapp import Mailer notification = Mailer() if notification.send_email( form.vars.email, "VERIFY YOUR EMAIL", "verify_email", link=link, password=plain_password ): self.session.flash = "Email sent to the user for verification" else: self.session.flash = "Email unsent, uppss there is a error" linked_tables = [self.db.auth_membership] if self.config.take("general.auth_type") == "local": grid = SQLFORM.smartgrid( self.db.auth_user, ui="web2py", fields=fields, links=links, linked_tables=linked_tables, # orderby=fields[-2], csv=False, searchable=True, create=True, details=True, editable=True, deletable=True, oncreate=verify_email, ) else: grid = SQLFORM.smartgrid( self.db.auth_user, ui="web2py", linked_tables=linked_tables, fields=fields, # orderby=fields[-2], links=links, csv=False, searchable=True, create=False, details=True, editable=False, deletable=True, ) return grid