当前位置: 首页>>代码示例>>Python>>正文


Python User.grant_permission方法代码示例

本文整理汇总了Python中www.models.User.grant_permission方法的典型用法代码示例。如果您正苦于以下问题:Python User.grant_permission方法的具体用法?Python User.grant_permission怎么用?Python User.grant_permission使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在www.models.User的用法示例。


在下文中一共展示了User.grant_permission方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: admin_invite

# 需要导入模块: from www.models import User [as 别名]
# 或者: from www.models.User import grant_permission [as 别名]
def admin_invite(proj):
    Audit(flask.g, proj, '/admin/invite', '').write()
    if not flask.g.user.has_permission(proj, 'invite'):
        Audit(flask.g, proj, '/admin/invite', '', result='NOT AUTHORIZED').write()
        return home_page()
        
    form=dict()
    form['mode']='form'
    form['invite_name']=''
    form['invite_email']=''
    
    form['invite_subject']=flask.g.site.get_data(proj, 'invite_subject', '')
    form['invite_body']   =flask.g.site.get_data(proj, 'invite_body', '')
    
    #print flask.g.site.bundle
    
    if request.method == 'POST':
        valid=True
        
        form['invite_email'] = request.form['invite_email'].lower().strip()
        if len(form['invite_email'])==0:
            flash(u'Error: you have to provide an email address', 'section_invite')
            valid=False
            
        form['invite_name'] = request.form['invite_name'].strip()
        if len(form['invite_name'])==0:
            flash(u'Error: you have to provide the user\'s name', 'section_invite')
            valid=False
        
        form['invite_subject'] = request.form['invite_subject']
        if len(form['invite_subject'])==0:
            flash(u'Error: you have to provide text for the email subject line', 'section_invite')
            valid=False
        
        form['invite_body'] = request.form['invite_body']
        if len(form['invite_body'])==0:
            flash(u'Error: you have to provide text for the email body', 'section_invite')
            valid=False
        
        if valid :
            email_to   = '"%s" <%s>' % (form['invite_name'], form['invite_email'], )
            email_from = '"%s" <%s>' % (flask.g.site.chrome('admin_name'), flask.g.site.chrome('admin_email'), )
            
            if request.form['mode']=='check':
                #print "FORM BUTTON : %s" % (request.form['check_button'],)
                if request.form['check_button']=='send':
                    user = User(flask.g.site.tag, form['invite_email'], form['invite_name'])
                    user.grant_permission(proj, 'access')
                    #user.set_password('')  # No password : user will be prompted (all attempts will fail)
                    
                    User.add(user)
                    User.commit()  # This sets up the user_id
                    
                    invite_link = url_for('user_invite_with_token', _external=True, user_id=user.id, token=user.invitation_token())
                    
                    for s in ['invite_subject', 'invite_body']:
                        #form[s+'_actual'] = Site.string.Template(request.form[s]).safe_substitute(
                        form[s+'_actual'] = Site.substitute_dollar_strings(request.form[s], flask.g,
                          link = invite_link,
                          name = form['invite_name'], 
                          email = form['invite_email'],
                        )
                    
                    sent = flask.g.site.send_email(
                      flask.g.site.chrome('admin_name'), 
                      flask.g.site.chrome('admin_email'), 
                      form['invite_name'], 
                      form['invite_email'], 
                      form['invite_subject_actual'],
                      form['invite_body_actual'],
                    )
                    
                    Audit(flask.g, proj, '/admin/invite', email_to, result='sent').write()
                    if sent :
                        flash(u'Email sent to %s !' % (email_to,), 'section_sent')
                    else:
                        flash(u'Email NOT sent to %s !' % (email_to,), 'section_invite')  # Looks like an error
                    
                    # Blank out the name and email addresses
                    form['invite_name']=''
                    form['invite_email']=''
                    
                else: # This will default to going back to the entry form
                    Audit(flask.g, proj, '/admin/invite', email_to, result='re-entry').write()
                    pass
                
            else: # if valid form entries, go into check mode for email
                form['mode']='check'
                form['email_to']=email_to
                form['email_from']=email_from
                
                for s in ['invite_subject', 'invite_body']:
                    #form[s+'_actual'] = string.Template(request.form[s]).safe_substitute(
                    form[s+'_actual'] = Site.substitute_dollar_strings(request.form[s], flask.g,
                      #link = 'http://THIS-SITE/user/new/0/123456789',
                      link = url_for('user_invite_with_token', _external=True, user_id=0, token='SAMPLE-ONLY'),
                      name = form['invite_name'], 
                      email = form['invite_email'],
                    )
                    
#.........这里部分代码省略.........
开发者ID:mdda,项目名称:2014-07_Singapore-Maritime-Hackathon,代码行数:103,代码来源:admin.py


注:本文中的www.models.User.grant_permission方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。