示例#1
0
    def init_auth(self):
        """ Auth """

        request = current.request
        settings = self.app_settings

        auth = Auth(self.db)
        self.auth = auth
        auth.settings.hmac_key = settings.security_key  # before define_tables()

        #If I use janrain to login, disable register.
        if settings.register_method in ['Disabled', 'Janrain']:
            # disable register
            auth.settings.actions_disabled.append('register')

        # If I use Recaptcha to register.
        if settings.register_method in ['Recaptcha']:
            auth.settings.captcha = Recaptcha(request,
                                              settings.recaptcha_public_key,
                                              settings.recaptcha_private_key)

        self.auth_def()  # the auth definition

        # creates all needed tables
        auth.define_tables(username=True, migrate=settings.migrate)
        auth.settings.mailer = self.mail  # for user email verification

        if settings.register_method in ['None', 'Recaptcha', 'Approval']:
            auth.settings.registration_requires_verification = False
        else:
            auth.settings.registration_requires_verification = True

        if settings.register_method in ['Approval']:
            auth.settings.registration_requires_approval = True
        else:
            auth.settings.registration_requires_approval = False

        auth.settings.reset_password_requires_verification = True

        if settings.register_method in ['Janrain']:
            base_http = 'http://' + str(request.env.http_host)
            auth.settings.actions_disabled = [
                'register', 'change_password', 'request_reset_password'
            ]
            auth.settings.login_form = RPXAccount(request,
                                            api_key=settings.janrain_api_key,
                                            domain=settings.janrain_domain,
                                            url=base_http + \
                                            '/%s/default/user/login' % \
                                            request.application)

        auth.messages.verify_email = settings.verify_email
        auth.messages.reset_password = settings.reset_password

        return auth
示例#2
0
    'default', 'user', args=['verify_email']) + '/%(key)s to verify your email'
auth.settings.reset_password_requires_verification = True
auth.messages.reset_password = '******' + request.env.http_host + URL(
    'default', 'user', args=['reset_password'
                             ]) + '/%(key)s to reset your password'

#########################################################################
## If you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with janrain.com, uncomment and customize following
from gluon.contrib.login_methods.rpx_account import RPXAccount
auth.settings.actions_disabled = [
    'register', 'change_password', 'request_reset_password'
]
auth.settings.login_form = RPXAccount(
    request,
    api_key='613112282abcb65840d3ffe0a4e4c19bc89ebc78',
    domain='web2py',
    url='http://' + request.env.http_host +
    "/%s/default/user/login" % request.application)
## other login methods are in gluon/contrib/login_methods
#########################################################################

crud.settings.auth = None  # =auth to enforce authorization on crud

#########################################################################
## Define your tables below (or better in another model file) for example
##
## >>> db.define_table('mytable',Field('myfield','string'))
##
## Fields can be 'string','text','password','integer','double','boolean'
##       'date','time','datetime','blob','upload', 'reference TABLENAME'
## There is an implicit 'id integer autoincrement' field
示例#3
0
scheme = True
try:
    scheme = settings['scheme']
except:
    pass

if settings['login_with_openid'] == 'True':
    from gluon.contrib.login_methods.rpx_account import RPXAccount
    auth.settings.actions_disabled = [
        'register', 'change_password', 'request_reset_password'
    ]
    u = URL('/user/login', scheme=scheme, host=True)
    auth.settings.login_form = RPXAccount(request,
                                          api_key=settings['api_key'],
                                          domain=settings['domain'],
                                          url=u,
                                          embed=True)

db.auth_user.first_name.requires = IS_NOT_EMPTY(
    error_message=auth.messages.is_empty)
db.auth_user.last_name.requires = IS_NOT_EMPTY(
    error_message=auth.messages.is_empty)
db.auth_user.password.requires = CRYPT(key=auth.settings.hmac_key)
db.auth_user.username.requires = IS_NOT_IN_DB(db, db.auth_user.username)
db.auth_user.registration_id.requires = IS_NOT_IN_DB(
    db, db.auth_user.registration_id)
db.auth_user.email.requires = (IS_EMAIL(
    error_message=auth.messages.invalid_email),
                               IS_NOT_IN_DB(db, db.auth_user.email))
auth.define_tables(migrate=settings.migrate)
示例#4
0
                           request.application).read().strip()
except:
    janrain_api_key = ''
try:
    host = conf.get("hosting", "hostdomain")
except:
    host = "localhost:8000"

from gluon.contrib.login_methods.rpx_account import RPXAccount

auth.settings.actions_disabled = [
    'register', 'change_password', 'request_reset_password'
]
auth.settings.login_form = RPXAccount(request,
                                      api_key=janrain_api_key,
                                      domain='opentree',
                                      url="http://%s/%s/default/user/login" %
                                      (host, request.application))

if request.controller == 'default' and request.function == 'user' and request.args(
        0) == 'login':
    auth.settings.login_next = session._next or URL('index')
else:
    session._next = request.env.path_info

#########################################################################
## Define your tables below (or better in another model file) for example
##
## >>> db.define_table('mytable',Field('myfield','string'))
##
## Fields can be 'string','text','password','integer','double','boolean'
示例#5
0
## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with janrain.com, write your domain:api_key in private/janrain.key
from gluon.contrib.login_methods.rpx_account import RPXAccount
from gluon.contrib.login_methods.extended_login_form import ExtendedLoginForm
#other_form = RPXAccount(request, api_key='594f1fcf7f1981b293d3e6a704180310da42a0e6', domain='beta.poderopedia.org', url='https://poderopedia.rpxnow.com/')
#auth.settings.login_form = ExtendedLoginForm(request,
#    auth, other_form, signals=['token'])
if request.vars._next:
    url = "http://beta.poderopedia.org/sociales/login?_next=%s" % request.vars._next
else:
    url = "http://beta.poderopedia.org/sociales/login"

rpxform = RPXAccount(request,
                     api_key='594f1fcf7f1981b293d3e6a704180310da42a0e6',
                     domain='poderopedia',
                     url=url,
                     language="es",
                     embed=True)
#auth.settings.login_form = RPXAccount(request,
#    api_key='594f1fcf7f1981b293d3e6a704180310da42a0e6',
#    domain='beta.poderopedia.org',
#    url = "https://poderopedia.rpxnow.com/")

#########################################################################
## Define your tables below (or better in another model file) for example
##
## >>> db.define_table('mytable',Field('myfield','string'))
##
## Fields can be 'string','text','password','integer','double','boolean'
##       'date','time','datetime','blob','upload', 'reference TABLENAME'
## There is an implicit 'id integer autoincrement' field
示例#6
0
recaptcha = Recaptcha(request, recaptcha_public_key, recaptcha_private_key)
auth.settings.register_captcha = recaptcha
auth.settings.retrieve_username_captcha = recaptcha
auth.settings.retrieve_password_captcha = recaptcha

mailhide_api_key = open(
    os.path.join(request.folder, 'private', 'mailhide_api_key.txt'),
    'r').read().strip()

# disabled auth actions
auth.settings.actions_disabled.append('profile')

# define where to go after RPX login
if request.vars._next:
    url = "http://%s/%s/default/user/login?_next=%s" % (
        mydomain, request.application, request.vars._next)
else:
    url = "http://%s/%s/default/user/login" % (mydomain, request.application)

# we read a key from a file because we want to keep it private
janrain_api_key = open(
    os.path.join(request.folder, 'private', 'janrain_api_key.txt'),
    'r').read().strip()

rpxform = RPXAccount(request,
                     api_key=janrain_api_key,
                     domain='cvstash',
                     url=url,
                     language="en",
                     embed=True)
# enable generic views for all actions for testing purpose
response.generic_patterns = ['*']

mail.settings.server = settings.email_server
mail.settings.sender = settings.email_sender
mail.settings.login = settings.email_login
auth.settings.hmac_key = settings.security_key

# add any extra fields you may want to add to auth_user
auth.settings.extra_fields['auth_user'] = []

# user username as well as email
auth.define_tables(migrate=settings.migrate,username=True)
auth.settings.mailer = mail
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.messages.verify_email = 'Click on the link http://'+request.env.http_host+URL('default','user', args=['verify_email'])+'/%(key)s to verify your email'
auth.settings.reset_password_requires_verification = True
auth.messages.reset_password = '******'+request.env.http_host+URL('default','user', args=['reset_password'])+'/%(key)s to reset your password'

if settings.login_method=='janrain':
   from gluon.contrib.login_methods.rpx_account import RPXAccount
   auth.settings.actions_disabled=['register', 'change_password', 'request_reset_password']
   auth.settings.login_form = RPXAccount(request,
       api_key = settings.login_config.split(':')[-1],
       domain = settings.login_config.split(':')[0],
       url = "http://%s/%s/default/user/login" % \
             (request.env.http_host, request.application)) 

示例#8
0
文件: db.py 项目: rif/talkexperience
## configure email
mail = auth.settings.mailer
mail.settings.server = 'gae'
mail.settings.sender = '*****@*****.**'
#mail.settings.login = '******'

## configure auth policy
auth.settings.registration_requires_verification = False
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

from gluon.contrib.login_methods.rpx_account import RPXAccount
from gluon.contrib.login_methods.extended_login_form import ExtendedLoginForm

rpx_form = RPXAccount(request,
                      api_key="7a5ffb2bec55c2cb5067ef87770dc93c8446657e",
                      domain="sonicalabs",
                      url=URL('default', 'user', args='login', scheme=True))
auth.settings.login_form = ExtendedLoginForm(auth, rpx_form, signals=['token'])

# if request.env.web2py_runtime_gae:            # if running on Google App Engine
#     from gluon.contrib.login_methods.gae_google_account import GaeGoogleAccount
#     auth.settings.login_form = GaeGoogleAccount()
#     #auth.settings.actions_disabled.append('profile')

from gravatar import Gravatar


def get_username(row):
    u = db.auth_user(
        row.sounds.created_by) if 'created_by' in row.sounds.keys() else None
    return u.first_name + ' ' + u.last_name if u else T("Anonymous")
示例#9
0
# change default session login time from 1 hour to 24 hours
auth.settings.expiration = 3600 * 24

## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with janrain.com, write your domain:api_key in private/janrain.key
#from gluon.contrib.login_methods.rpx_account import use_janrain
#use_janrain(auth,filename='private/janrain.key')
from gluon.contrib.login_methods.rpx_account import RPXAccount
from gluon.contrib.login_methods.extended_login_form import ExtendedLoginForm

janrain_url = 'http://%s/%s/default/user/login' % (request.env.http_host,
                                                   request.application)

janrain_form = RPXAccount(
    request,
    api_key=settings.janrain_api_key,  # set in 1.py
    domain=settings.janrain_domain,  # set in 1.py
    url=janrain_url)
auth.settings.login_form = ExtendedLoginForm(
    auth, janrain_form)  # uncomment this to use both Janrain and web2py auth
#auth.settings.login_form = auth # uncomment this to just use web2py integrated authentication

request.janrain_form = janrain_form  # save the form so that it can be added to the user/register controller

#########################################################################
## Define your tables below (or better in another model file) for example
##
## >>> db.define_table('mytable',Field('myfield','string'))
##
## Fields can be 'string','text','password','integer','double','boolean'
##       'date','time','datetime','blob','upload', 'reference TABLENAME'
示例#10
0
文件: db.py 项目: rif/onlineshop
    'default', 'user', args=['verify_email']) + '/%(key)s to verify your email'
auth.settings.reset_password_requires_verification = True
auth.messages.reset_password = '******' + request.env.http_host + URL(
    'default', 'user', args=['reset_password'
                             ]) + '/%(key)s to reset your password'

#########################################################################
## If you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with janrain.com, uncomment and customize following
from gluon.contrib.login_methods.rpx_account import RPXAccount
auth.settings.actions_disabled = [
    'register', 'change_password', 'request_reset_password'
]
auth.settings.login_form = RPXAccount(
    request,
    api_key='a8d801a4a48a3f134b6910a6c26e532192339ec0',
    domain='rif',
    url="http://localhost:8000/%s/default/user/login" % request.application)

## other login methods are in gluon/contrib/login_methods
#########################################################################

crud.settings.auth = None  # =auth to enforce authorization on crud

#########################################################################
## Define your tables below (or better in another model file) for example
##
## >>> db.define_table('mytable',Field('myfield','string'))
##
## Fields can be 'string','text','password','integer','double','boolean'
##       'date','time','datetime','blob','upload', 'reference TABLENAME'
示例#11
0
    Field('longi', 'double'),
    Field('review')
]

## before auth.define_tables(username=True)

# create all tables needed by auth if not custom tables
auth.define_tables(username=False, signature=False)

from gluon.contrib.login_methods.rpx_account import RPXAccount
auth.settings.actions_disabled = [
    'register', 'change_password', 'request_reset_password'
]
auth.settings.login_form = RPXAccount(
    request,
    api_key='fe4b8c586a1c8835b73b8b93e36fbcf3ee80a4ec',
    domain='storefrontbyfence',
    url=URL('default', 'user/login', host=True))
#url="http://localhost:8000/%s/default/user/login" % request.application)

# configure email
mail = auth.settings.mailer
mail.settings.server = 'logging' if request.is_local else myconf.get(
    'smtp.server')
mail.settings.sender = myconf.get('smtp.sender')
mail.settings.login = myconf.get('smtp.login')
mail.settings.tls = myconf.get('smtp.tls') or False
mail.settings.ssl = myconf.get('smtp.ssl') or False

# configure auth policy
auth.settings.registration_requires_verification = False
示例#12
0
auth.settings.register_onaccept = _setup_group_membership

auth.settings.login_captcha = False
auth.settings.captcha = Recaptcha(request,
    '6LfPzMASAAAAAPx0VBi4NkfbUko1r2SbsA1285x7',
    '6LfPzMASAAAAALA1S9vApCUEMcEDCq5QG_HNVYkj',
    label='Are you human ?',
    error_message='Your text didn\'t match. Try again')
#auth.settings.captcha = False

if settings.rpx_domain:
    from gluon.contrib.login_methods.rpx_account import RPXAccount
    auth.settings.actions_disabled=['register','change_password',
                                    'request_reset_password']
    auth.settings.login_form = RPXAccount(request,
                                          api_key=settings.rpx_apikey,
                                          domain=settings.rpx_domain,
                                          url = settings.home_url+"/user/login")
    if request.function=='user' and request.args(0)=='register':
        if not auth.user_id: redirect(URL('user',args='login'))
        else: redirect(URL('user',args='profile'))
    if auth.user and not auth.user.registered:
        if not (request.function=='user' and request.args(0)=='profile'):
            redirect(URL('user',args='profile'))


db.define_table('paypal_txns',
    Field('txn_id', 'string'),
    Field('tracker', 'string'),
    Field('ipn_vars', 'text'),
    Field('time_recvd', 'datetime', default=request.now),
    Field('status', 'boolean'))
示例#13
0
if host == "rickroll":
    host = "www.reelab.net"
else:
    try:
        host = conf.get("hosting", "hostdomain")
    except:
        host = "localhost:8000"

from gluon.contrib.login_methods.rpx_account import RPXAccount

auth.settings.actions_disabled = [
    'register', 'change_password', 'request_reset_password'
]
auth.settings.login_form = RPXAccount(
    request,
    api_key='9435bcb6253fa24c4680cbbd0d4e75a0accde8b3',
    domain='phylografter',
    url="http://%s/%s/default/user/login" % (host, request.application))

if request.controller == 'default' and request.function == 'user' and request.args(
        0) == 'login':
    auth.settings.login_next = session._next or URL('index')
else:
    session._next = request.env.path_info

## other login methods are in gluon/contrib/login_methods
#########################################################################

crud.settings.auth = None  # =auth to enforce authorization on crud

# from http://www.web2pyslices.com/main/slices/take_slice/8
示例#14
0
    #auth.settings.login_form = RPXAccount(request,
    #api_key='4f608d8fa6a0ad46654e51f484fc504334a5ba01',
    #domain='netdecisionmaking',
    #url = "https://testdecisionmaking.appspot.com/%s/default/user/login" % request.application)
elif settings.logon_methods == 'web2pyandjanrain':  # this is now proving useless as no providers really work
    #Dual login sort of working but not fully tested with Janrain - doesnt work with gae
    #from gluon.contrib.login_methods.extended_login_form import ExtendedLoginForm
    #from gluon.contrib.login_methods.rpx_account import RPXAccount
    #other_form = use_janrain(auth, filename='private/janrain.key')
    #auth.settings.login_form = ExtendedLoginForm(auth, other_form, signals=['token'])
    from gluon.contrib.login_methods.extended_login_form import ExtendedLoginForm
    from gluon.contrib.login_methods.rpx_account import RPXAccount
    filename = 'private/janrain.key'
    path = os.path.join(current.request.folder, filename)
    if os.path.exists(path):
        request = current.request
        domain, key = open(path, 'r').read().strip().split(':')
        host = current.request.env.http_host
        url = URL('default', 'user', args='login', scheme=True)
        other_form = RPXAccount(request, api_key=key, domain=domain, url=url)
        auth.settings.login_form = ExtendedLoginForm(auth,
                                                     other_form,
                                                     signals=['token'])

#########################################################################
## Define your tables below (or better in another model file)
##
## >>>setup tables are all defined in db__first.py
## >>>main tables are all defined in db_gdms.py
#########################################################################
示例#15
0
auth.settings.registration_requires_approval = False
auth.settings.reset_password_requires_verification = True

## if you need to use OpenID, Facebook, MySpace, Twitter, Linkedin, etc.
## register with janrain.com, write your domain:api_key in private/janrain.key
from gluon.contrib.login_methods.rpx_account import use_janrain, RPXAccount
#use_janrain(auth,filename='private/janrain.key')
#auth.settings.actions_disabled.append('retrieve_username')
from gluon.contrib.login_methods.extended_login_form import ExtendedLoginForm
# define where to go after RPX login
if request.vars._next:
    url = "http://www.fansubcheck.com/fansubcheck/default/user/login?_next=%s" % request.vars._next
else:
    url = "http://www.fansubcheck.com/fansubcheck/default/user/login"
other_form = RPXAccount(request,
                        api_key='56b1a6942038b92a67db2c17ba4bd2ce1dbf5dd8',
                        domain='fansubcheck',
                        url=url)
auth.settings.login_form = ExtendedLoginForm(auth,
                                             other_form,
                                             signals=['token'])

#########################################################################
## Define your tables below (or better in another model file) for example
##
## >>> db.define_table('mytable',Field('myfield','string'))
##
## Fields can be 'string','text','password','integer','double','boolean'
##       'date','time','datetime','blob','upload', 'reference TABLENAME'
## There is an implicit 'id integer autoincrement' field
## Consult manual for more options, validators, etc.
##
示例#16
0
    host = "www.reelab.net"
else:
    try:
        host = conf.get("hosting", "hostdomain")
    except:
        host = "localhost:8000"

rpx_api_key = conf.get("RPX", "api_key")
rpx_domain = conf.get("RPX", "domain")
from gluon.contrib.login_methods.rpx_account import RPXAccount
auth.settings.actions_disabled = [
    'register', 'change_password', 'request_reset_password'
]
auth.settings.login_form = RPXAccount(request,
                                      api_key=rpx_api_key,
                                      domain=rpx_domain,
                                      url="http://%s/%s/default/user/login" %
                                      (host, request.application))

if request.controller == 'default' and request.function == 'user' and request.args(
        0) == 'login':
    ## _next = session._next
    ## if _next and 'plugin_' in _next:
    ##     _next = URL('default', 'index')
    ##     session._next = _next
    ## auth.settings.login_next = _next
    session._next = URL('default', 'index')  #request.env.path_info
else:
    session._next = URL('default', 'index')  #request.env.path_info

## other login methods are in gluon/contrib/login_methods
示例#17
0
# There is an implicit 'id integer autoincrement' field
# Consult manual for more options, validators, etc.
#
# More API examples for controllers:
#
# >>> db.mytable.insert(myfield='value')
# >>> rows = db(db.mytable.myfield == 'value').select(db.mytable.ALL)
# >>> for row in rows: print row.id, row.myfield
# -------------------------------------------------------------------------

# -------------------------------------------------------------------------
# after defining tables, uncomment below to enable auditing
# -------------------------------------------------------------------------
# auth.enable_record_versioning(db)

mail.settings.server = settings.email_server
mail.settings.sender = settings.email_sender
mail.settings.login = settings.email_login

from gluon.contrib.login_methods.rpx_account import RPXAccount
auth.settings.actions_disabled = [
    'register', 'change_password', 'request_reset_password'
]
auth.settings.login_form = RPXAccount(
    request,
    api_key=
    'c1038aabebb715927616160d874fb2e44b4daa65',  #settings.login_config.split(':')[-1],
    domain='skrin-pythonanywhere',  #settings.login_config.split(':')[0],
    url="http://%s/%s/default/user/login" %
    (request.env.http_host, request.application))