本文整理汇总了Python中utils.authenticate函数的典型用法代码示例。如果您正苦于以下问题:Python authenticate函数的具体用法?Python authenticate怎么用?Python authenticate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了authenticate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_get_playbooks
def test_get_playbooks(client):
without_login = client.get('/api/playbook/all')
authenticate(client)
playbooks = client.get('/api/playbook/all').json
logout(client)
assert without_login.status_code == 302
assert isinstance(playbooks['playbooks'], list)
开发者ID:krahser,项目名称:DJBot,代码行数:7,代码来源:test_playbook.py
示例2: test_save_playbook
def test_save_playbook(client):
without_login = client.post('/api/playbook/save')
wrong_method = client.get('/api/playbook/save')
authenticate(client)
change_pb = client.post('/api/playbook/get', data={
'key': 1,
}).json
change_pb['name'] = 'Modified initial setup'
change_pb['description'] = 'Modified description'
save_pb = client.post('/api/playbook/save', data=change_pb).json
check_pb = client.post('/api/playbook/get', data={
'key': 1,
}).json
wrong_id = client.post('/api/playbook/save', data={
'key': 0,
'name': 'Not Good',
'description': 'This is a test of a non valid id'
}).json
logout(client)
assert without_login.status_code == 302
assert wrong_method.status_code == 405
assert save_pb['messageMode'] == 0
assert wrong_id['messageMode'] == 1
assert check_pb['name'] == 'Modified initial setup'
assert check_pb['description'] == 'Modified description'
assert isinstance(check_pb['tasks'], list)
开发者ID:krahser,项目名称:DJBot,代码行数:26,代码来源:test_playbook.py
示例3: test_get_inventory
def test_get_inventory(client):
without_login = client.get('/api/inventory/all')
authenticate(client)
room = client.get('/api/inventory/all').json
logout(client)
assert without_login.status_code == 302
assert isinstance(room['rooms'], list)
开发者ID:krahser,项目名称:DJBot,代码行数:7,代码来源:test_inventory.py
示例4: test_change_password
def test_change_password(client):
# TODO: Fix the change password repetition code
without_login = client.post('/change',
data={"password": "password",
"new_password": "new_password",
"new_password_confirm": "new_password"})
authenticate(client)
new_password = client.post(
'/change',
data={
"password": "password",
"new_password": "new_password",
"new_password_confirm": "new_password",
}
)
password = client.post(
'/change',
data={
"password": "new_password",
"new_password": "password",
"new_password_confirm": "password",
}
)
logout(client)
assert without_login.status_code == 302
print new_password.data
assert '/#/settings/user' in new_password.location
assert password.status_code == 302
assert '/#/settings/user' in password.location
开发者ID:krahser,项目名称:DJBot,代码行数:30,代码来源:test_users.py
示例5: decorated
def decorated(*args, **kwargs):
auth = request.authorization
if not auth:
return authenticate()
elif not check_auth(auth.username, auth.password):
return authenticate()
return f(*args, **kwargs)
开发者ID:cassac,项目名称:api_demo,代码行数:7,代码来源:messages.py
示例6: test_get_all
def test_get_all(client):
without_login = client.get('/api/user/all')
authenticate(client)
user_login = client.get('/api/user/all')
logout(client)
users = user_login.json
assert without_login.status_code == 302
assert 2 == len(users['users'])
开发者ID:krahser,项目名称:DJBot,代码行数:8,代码来源:test_users.py
示例7: process_request
def process_request(self, request):
"""
Writes the signed_request into the Session
"""
fb = get_session(request)
setattr(request, 'fb_session', fb)
application = get_app_dict()
logger.debug('Request Method = %s\n, AccessToken=%s' % (request.method, fb.access_token))
if 'feincms' in settings.INSTALLED_APPS:
# if feincms is installed, try to get the application from the page
from facebook.feincms.utils import get_application_from_request
page_app = get_application_from_request(request)
if application:
application = get_app_dict(page_app)
# Temporary OAuth2.0 fix due to missing access_token in cookie sr:
if 'access_token' in request.GET:
fb.store_token(request.GET.get('access_token'))
# default POST/GET request from facebook with a signed request
if 'signed_request' in request.POST:
parsed_request = parseSignedRequest(request.POST['signed_request'], application['SECRET'])
logger.debug(u'got signed_request from facebook: %s' % parsed_request)
if 'user' in parsed_request:
language = parsed_request['user']['locale']
logger.debug('language: %s' %language)
request.LANGUAGE_CODE = language
translation.activate(language)
fb.signed_request = parsed_request
logger.debug('stored signed_request')
expires = None
# rewrite important data
if 'oauth_token' in parsed_request:
expires = datetime.fromtimestamp(float(parsed_request['expires']))
fb.store_token(parsed_request['oauth_token'], expires)
elif 'access_token' in parsed_request:
expires = datetime.fromtimestamp(float(parsed_request['expires']))
fb.store_token(parsed_request['access_token'], expires)
else:
#The chance is good that there is already a valid token in the session. Remove it.
fb.store_token(None)
if 'user_id' in parsed_request:
fb.user_id = parsed_request['user_id']
else:
logger.debug("Signed Request didn't contain public user info.")
if expires:
logger.debug('Signed Request issued at: %s' % datetime.fromtimestamp(float(parsed_request['issued_at'])))
# auth via callback from facebook
elif 'code' in request.GET and 'facebook' in request.META.get('HTTP_REFERER', u''):
authenticate(request.REQUEST['code'], fb, application,
request.build_absolute_uri().split('?')[0] \
.replace(application['CANVAS-URL'], application['CANVAS-PAGE']))
开发者ID:cuongluu,项目名称:django-tutorial,代码行数:57,代码来源:middleware.py
示例8: test_custom_post_change_view
def test_custom_post_change_view(client):
authenticate(client)
response = client.post('/change', data={
'password': 'password',
'new_password': 'newpassword',
'new_password_confirm': 'newpassword'
}, follow_redirects=True)
assert b'Profile Page' in response.data
开发者ID:jirikuncar,项目名称:flask-security,代码行数:9,代码来源:test_changeable.py
示例9: test_roles_accepted
def test_roles_accepted(client):
for user in ("[email protected]", "[email protected]"):
authenticate(client, user)
response = client.get("/admin_or_editor")
assert b'Admin or Editor Page' in response.data
logout(client)
authenticate(client, "[email protected]")
response = client.get("/admin_or_editor", follow_redirects=True)
assert b'Home Page' in response.data
开发者ID:guoqiao,项目名称:flask-security,代码行数:10,代码来源:test_common.py
示例10: test_multiple_role_required
def test_multiple_role_required(client):
for user in ("[email protected]", "[email protected]"):
authenticate(client, user)
response = client.get("/admin_and_editor", follow_redirects=True)
assert b'Home Page' in response.data
client.get('/logout')
authenticate(client, '[email protected]')
response = client.get("/admin_and_editor", follow_redirects=True)
assert b'Admin and Editor Page' in response.data
开发者ID:guoqiao,项目名称:flask-security,代码行数:10,代码来源:test_common.py
示例11: test_user_deleted_during_session_reverts_to_anonymous_user
def test_user_deleted_during_session_reverts_to_anonymous_user(app, client):
authenticate(client)
with app.test_request_context('/'):
user = app.security.datastore.find_user(email='[email protected]')
app.security.datastore.delete_user(user)
app.security.datastore.commit()
response = client.get('/')
assert b'Hello [email protected]' not in response.data
开发者ID:guoqiao,项目名称:flask-security,代码行数:10,代码来源:test_common.py
示例12: test_categories
def test_categories(client):
without_login = client.get('/api/task/categories')
authenticate(client)
categories = client.get('/api/task/categories').json
logout(client)
assert without_login.status_code == 302
assert isinstance(categories, dict)
assert isinstance(categories['categories'], list)
开发者ID:krahser,项目名称:DJBot,代码行数:10,代码来源:test_task.py
示例13: test_context_processors
def test_context_processors(client, app):
@app.security.forgot_password_context_processor
def forgot_password():
return {"foo": "bar"}
response = client.get("/reset")
assert b"bar" in response.data
@app.security.login_context_processor
def login():
return {"foo": "bar"}
response = client.get("/login")
assert b"bar" in response.data
@app.security.register_context_processor
def register():
return {"foo": "bar"}
response = client.get("/register")
assert b"bar" in response.data
@app.security.reset_password_context_processor
def reset_password():
return {"foo": "bar"}
response = client.get("/reset")
assert b"bar" in response.data
@app.security.change_password_context_processor
def change_password():
return {"foo": "bar"}
authenticate(client)
response = client.get("/change")
assert b"bar" in response.data
@app.security.send_confirmation_context_processor
def send_confirmation():
return {"foo": "bar"}
response = client.get("/confirm")
assert b"bar" in response.data
@app.security.mail_context_processor
def mail():
return {"foo": "bar"}
with app.mail.record_messages() as outbox:
client.post("/reset", data=dict(email="[email protected]"))
email = outbox[0]
assert "bar" in email.html
开发者ID:davidcorry,项目名称:flask-security,代码行数:53,代码来源:test_context_processors.py
示例14: test_category
def test_category(client):
without_login = client.post('/api/task/category')
authenticate(client)
category = client.post('/api/task/category',
data={'name': 'cloud'}).json
not_valid_form = client.post('/api/task/category').json
logout(client)
assert without_login.status_code == 302
assert isinstance(category['modules'], list)
assert category['category_name'] == 'cloud'
assert isinstance(not_valid_form, dict)
开发者ID:krahser,项目名称:DJBot,代码行数:12,代码来源:test_task.py
示例15: test_basic_custom_forms
def test_basic_custom_forms(app, sqlalchemy_datastore):
class MyLoginForm(LoginForm):
email = StringField('My Login Email Address Field')
class MyRegisterForm(RegisterForm):
email = StringField('My Register Email Address Field')
class MyForgotPasswordForm(ForgotPasswordForm):
email = StringField(
'My Forgot Email Address Field',
validators=[
email_required,
email_validator,
valid_user_email])
class MyResetPasswordForm(ResetPasswordForm):
password = StringField('My Reset Password Field')
class MyChangePasswordForm(ChangePasswordForm):
password = PasswordField('My Change Password Field')
app.security = Security(app,
datastore=sqlalchemy_datastore,
login_form=MyLoginForm,
register_form=MyRegisterForm,
forgot_password_form=MyForgotPasswordForm,
reset_password_form=MyResetPasswordForm,
change_password_form=MyChangePasswordForm)
populate_data(app)
client = app.test_client()
response = client.get('/login')
assert b'My Login Email Address Field' in response.data
response = client.get('/register')
assert b'My Register Email Address Field' in response.data
response = client.get('/reset')
assert b'My Forgot Email Address Field' in response.data
with capture_reset_password_requests() as requests:
response = client.post('/reset', data=dict(email='[email protected]'))
token = requests[0]['token']
response = client.get('/reset/' + token)
assert b'My Reset Password Field' in response.data
authenticate(client)
response = client.get('/change')
assert b'My Change Password Field' in response.data
开发者ID:AshtonShapcott,项目名称:flask-security,代码行数:52,代码来源:test_misc.py
示例16: test_trackable_flag
def test_trackable_flag(app, client):
e = '[email protected]'
authenticate(client, email=e)
logout(client)
authenticate(client, email=e, headers={'X-Forwarded-For': '127.0.0.1'})
with app.app_context():
user = app.security.datastore.find_user(email=e)
assert user.last_login_at is not None
assert user.current_login_at is not None
assert user.last_login_ip == 'untrackable'
assert user.current_login_ip == '127.0.0.1'
assert user.login_count == 2
开发者ID:0x37N0w4N,项目名称:flask-security,代码行数:13,代码来源:test_trackable.py
示例17: test_get_user
def test_get_user(client):
user = {
"admin": True,
"email": "[email protected]",
"key": 1,
"username": "admin"
}
without_login = client.get('/api/user/get')
authenticate(client)
user_login = client.get('/api/user/get')
logout(client)
assert without_login.status_code == 302
assert user == user_login.json
开发者ID:krahser,项目名称:DJBot,代码行数:13,代码来源:test_users.py
示例18: test_get_playbook
def test_get_playbook(client):
wrong_method = client.get('/api/playbook/get')
without_login = client.post('/api/playbook/get')
authenticate(client)
check_pb = client.post('/api/playbook/get', data={
'key': 1,
}).json
logout(client)
assert without_login.status_code == 302
assert wrong_method.status_code == 405
assert check_pb['name'] == 'Initial setup'
assert check_pb['description'] == 'Hardening of the operative system'
assert isinstance(check_pb['tasks'], list)
开发者ID:krahser,项目名称:DJBot,代码行数:13,代码来源:test_playbook.py
示例19: test_trackable_with_multiple_ips_in_headers
def test_trackable_with_multiple_ips_in_headers(app, client):
e = '[email protected]'
authenticate(client, email=e)
logout(client)
authenticate(client, email=e, headers={
'X-Forwarded-For': '99.99.99.99, 88.88.88.88'})
with app.app_context():
user = app.security.datastore.find_user(email=e)
assert user.last_login_at is not None
assert user.current_login_at is not None
assert user.last_login_ip == 'untrackable'
assert user.current_login_ip == '88.88.88.88'
assert user.login_count == 2
开发者ID:guoqiao,项目名称:flask-security,代码行数:14,代码来源:test_trackable.py
示例20: test_set_unauthorized_handler
def test_set_unauthorized_handler(app, client):
@app.security.unauthorized_handler
def unauthorized():
app.unauthorized_handler_set = True
return 'unauthorized-handler-set', 401
app.unauthorized_handler_set = False
authenticate(client, "[email protected]")
response = client.get("/admin", follow_redirects=True)
assert app.unauthorized_handler_set is True
assert b'unauthorized-handler-set' in response.data
assert response.status_code == 401
开发者ID:jirikuncar,项目名称:flask-security,代码行数:14,代码来源:test_misc.py
注:本文中的utils.authenticate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论