コード例 #1
0
def top():
    #    return {'message':ut.session_get('message', True),
    #            'role':Auth.get_role()}
    return template('index',
                    uid=ut.session_get('uid'),
                    name="main1",
                    redirectUrl=redirectUrl,
                    appUrl=appUrl,
                    message=ut.session_get('message', True),
                    role=Auth.get_role())
コード例 #2
0
def top2():
    return template('index2',
                    name="main2",
                    redirectUrl=redirectUrl,
                    appUrl=appUrl,
                    message=ut.session_get('message', True),
                    role=Auth.get_role())
コード例 #3
0
def change_pw():
    uid = ut.session_get('uid')
    if ut.form_get('user'):
        uid = ut.form_get('user')

    current_pw, new_pw1, new_pw2 = [
        ut.form_get(x) for x in ('current_pw', 'new_pw1', 'new_pw2')
    ]
    #print("current_pw="+current_pw+" new_pw1="+new_pw1+" new_pw2="+ new_pw2)

    #管理者の場合はカレントパスワード不要
    if Auth.get_role() == 'admin':
        b, msg = ut.change_pw_super(uid, new_pw1, new_pw2)
    else:
        b, msg = ut.change_pw(uid, current_pw, new_pw1, new_pw2)

    if b:
        #ut.session_set('message', msg)
        if ut.form_get('from_show_users') == "1":
            return template('users',
                            users=ut.users(),
                            appUrl=appUrl,
                            message=msg,
                            role=Auth.get_role())
        else:
            btl.redirect(redirectUrl)
    else:

        return template('change_pw',
                        appUrl=appUrl,
                        message=msg,
                        role=Auth.get_role())
コード例 #4
0
def change_pw_form():
    return template('change_pw',
                    appUrl=appUrl,
                    message=ut.session_get('message', True),
                    role=Auth.get_role(),
                    user=ut.form_get('user'),
                    from_show_users=ut.form_get('from_show_users'))
コード例 #5
0
ファイル: auth.py プロジェクト: ktsuchi-abit/bottleNsession
class Auth:
    '''generating decorators for access control'''
       
    # class attribute
    CLS_ATTR=[
      ('get_role_from_db', lambda uid,pw:None), # lambda uid,pw: role if a record having (uid, pw) exists in the db else None 
      ('logout', ut.logout), # method to clear the session
      ('set_uid', partial(ut.session_set, 'uid')), # method to set uid into the session
      ('set_role', partial(ut.session_set, 'role')), # method to set role into the session
      ('get_uid', lambda:ut.session_get('uid')), # method to get uid from the session
      ('get_role', lambda:ut.session_get('role')), # method to get role from the session
      ('set_message', partial(ut.session_set,'message')), 
    ]
    
    @classmethod
    def config(cls, **kw):
        '''setting static methods'''
        for k,v in cls.CLS_ATTR:
            setattr(cls, k, staticmethod(kw.get(k,v)))
            
    @classmethod    
    def login(cls, uid, pw):
        role=cls.get_role_from_db(uid, pw)
        if role:
            cls.set_uid(uid)
            cls.set_role(role)
        return role
        
    def  __init__(self, appUrl, **kw):
        '''kw parameters are role, message and failure_redirect'''
        for k,v in [('message', 'Login required'), ('failure_redirect', appUrl + '/login')]:
            setattr(self, k, kw.get(k, v))
        self.is_auth=(lambda :kw['role']==self.get_role()) if 'role' in kw else self.get_role
                            
    def __call__(self, fun):
        '''acting as a decorator'''
        @wraps(fun)
        def _f(*a, **k):
            if self.is_auth():
                return fun(*a, **k)
            else:
                self.set_message(self.message)
                return btl.redirect(self.failure_redirect)
        return _f
コード例 #6
0
def add_user_form():
    return template('add_user',
                    appUrl=appUrl,
                    message=ut.session_get('message', True),
                    role=Auth.get_role())
コード例 #7
0
def users():
    return template('users',
                    users=ut.users(),
                    appUrl=appUrl,
                    message=ut.session_get('message', True),
                    role=Auth.get_role())
コード例 #8
0
def login_form():
    return {'message': ut.session_get('message', True)}