本文整理汇总了Python中pytas.http.TASClient.get_user方法的典型用法代码示例。如果您正苦于以下问题:Python TASClient.get_user方法的具体用法?Python TASClient.get_user怎么用?Python TASClient.get_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pytas.http.TASClient
的用法示例。
在下文中一共展示了TASClient.get_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_projects
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
def user_projects( request, username ):
logger.info( 'User projects requested by admin: %s for user %s', request.user, username )
resp = {
'status': 'error',
'msg': '',
'result': []
}
if username:
tas = TASClient()
try:
userData = tas.get_user(username=username)
try:
userProjects = tas.projects_for_user( username=username )
chameleonProjects = tas.projects_for_group('Chameleon');
if (chameleonProjects and userProjects):
for project in userProjects:
if project in chameleonProjects:
resp['status'] = 'success'
resp['result'].append(project)
logger.info( 'Total chameleon projects for user %s: %s', username, len( resp ) )
except Exception as e:
logger.debug('Error loading projects for user: %s', username)
resp['msg'] = 'Error loading projects for user: %s' %username
except Exception as e:
logger.debug('User not found with username: %s', username)
resp['msg'] = 'User not found.'
return HttpResponse(json.dumps(resp), content_type="application/json")
示例2: email_confirmation
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
def email_confirmation(request):
context = {}
if request.method == 'POST':
form = EmailConfirmationForm(request.POST)
if form.is_valid():
code = request.POST['code']
username = request.POST['username']
try:
tas = TASClient()
user = tas.get_user(username=username)
tas.verify_user(user['id'], code)
activate_local_user(username)
messages.success(request, 'Congratulations, your email has been verified! Please log in now.')
return HttpResponseRedirect(reverse('tas:profile'))
except Exception as e:
logger.exception('Email verification failed')
if e[0] == 'User not found':
form.add_error('username', e[1])
else:
form.add_error('code', 'Email verification failed. Please check your verification code and username and try again.')
else:
form = EmailConfirmationForm(initial={'code': request.GET.get('code', '')})
context['form'] = form
return render(request, 'tas/email_confirmation.html', context)
示例3: profile_edit
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
def profile_edit(request):
tas = TASClient()
tas_user = tas.get_user(username=request.user)
if tas_user['source'] != 'Chameleon':
return HttpResponseRedirect(reverse('tas:profile'))
if request.method == 'POST':
form = UserProfileForm(request.POST, initial=tas_user)
if form.is_valid():
data = form.cleaned_data
if request.POST.get('request_pi_eligibility'):
data['piEligibility'] = 'Requested'
_create_ticket_for_pi_request(tas_user)
else:
data['piEligibility'] = tas_user['piEligibility']
data['source'] = 'Chameleon'
tas.save_user(tas_user['id'], data)
messages.success(request, 'Your profile has been updated!')
return HttpResponseRedirect(reverse('tas:profile'))
else:
form = UserProfileForm(initial=tas_user)
context = {
'form': form,
'user': tas_user,
}
return render(request, 'tas/profile_edit.html', context)
示例4: make_user_pi
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
def make_user_pi(self, request, selected_users, form_url=''):
# The user has already confirmed the action.
# Make the users PI Eligible
if request.POST.get('post'):
tas = TASClient()
for user in selected_users:
try:
tas_user = tas.get_user(username=user.username)
if tas_user['piEligibility'] == 'Eligible':
self.message_user(request, _('User %s already PI Eligible') % user.username, level=messages.WARNING)
else:
tas_user['piEligibility'] = 'Eligible'
tas.save_user(tas_user['id'], tas_user)
self.message_user(request, _('Granted PI Eligible to %s') % user.username)
except:
logger.exception('Unable to Grant PI Eligible to %s' % user.username)
self.message_user(request, _('Unable to Grant PI Eligible to %s') % user.username, level=messages.ERROR)
return None
context = {
'title': _('Grant PI eligibility'),
'opts': self.model._meta,
'selected_users': selected_users,
'form_url': form_url,
'action_checkbox_name':helpers.ACTION_CHECKBOX_NAME
}
context.update(admin.site.each_context())
return TemplateResponse(request,
'admin/tas/make_user_pi.html',
context, current_app=self.admin_site.name)
示例5: TASBackend
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
class TASBackend(ModelBackend):
logger = logging.getLogger(__name__)
def __init__(self):
self.tas = TASClient()
# Create an authentication method
# This is called by the standard Django login procedure
def authenticate(self, username=None, password=None, request=None, **kwargs):
user = None
if username is not None and password is not None:
tas_user = None
if request is not None:
self.logger.info('Attempting login via TAS for user "%s" from IP "%s"' % (username, request.META.get('REMOTE_ADDR')))
else:
self.logger.info('Attempting login via TAS for user "%s" from IP "%s"' % (username, 'unknown'))
try:
# Check if this user is valid on the mail server
if self.tas.authenticate(username, password):
tas_user = self.tas.get_user(username=username)
self.logger.info('Login successful for user "%s"' % username)
else:
raise ValidationError('Authentication Error', 'Your username or password is incorrect.')
except Exception as e:
self.logger.warning(e.args)
if re.search(r'PendingEmailConfirmation', e.args[1]):
raise ValidationError('Please confirm your email address before logging in.')
else:
raise ValidationError(e.args[1])
if tas_user is not None:
UserModel = get_user_model()
try:
# Check if the user exists in Django's local database
user = UserModel.objects.get(username=username)
user.first_name = tas_user['firstName']
user.last_name = tas_user['lastName']
user.email = tas_user['email']
user.save()
except UserModel.DoesNotExist:
# Create a user in Django's local database
self.logger.info('Creating local user record for "%s" from TAS Profile' % username)
user = UserModel.objects.create_user(
username=username,
first_name=tas_user['firstName'],
last_name=tas_user['lastName'],
email=tas_user['email']
)
try:
profile = DesignSafeProfile.objects.get(user=user)
except DesignSafeProfile.DoesNotExist:
profile = DesignSafeProfile(user=user)
profile.save()
return user
示例6: profile
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
def profile(request):
context = {}
try:
tas = TASClient()
resp = tas.get_user(username=request.user)
context['profile'] = resp
except:
context['profile'] = False
# raise Exception('error loading profile')
return render(request, 'tas/profile.html', context)
示例7: profile_edit
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
def profile_edit(request):
tas = TASClient()
user = request.user
tas_user = tas.get_user(username=user.username)
if request.method == 'POST':
form = forms.UserProfileForm(request.POST, initial=tas_user)
if form.is_valid():
data = form.cleaned_data
# punt on PI Eligibility for now
data['piEligibility'] = tas_user['piEligibility']
# retain original account source
data['source'] = tas_user['source']
tas.save_user(tas_user['id'], data)
messages.success(request, 'Your profile has been updated!')
try:
ds_profile = user.profile
ds_profile.ethnicity = data['ethnicity']
ds_profile.gender = data['gender']
ds_profile.save()
except ObjectDoesNotExist as e:
logger.info('exception e: {} {}'.format(type(e), e ))
ds_profile = DesignSafeProfile(
user=user,
ethnicity=data['ethnicity'],
gender=data['gender']
)
ds_profile.save()
return HttpResponseRedirect(reverse('designsafe_accounts:manage_profile'))
else:
try:
tas_user['ethnicity'] = user.profile.ethnicity
tas_user['gender'] = user.profile.gender
except ObjectDoesNotExist:
pass
form = forms.UserProfileForm(initial=tas_user)
context = {
'title': 'Manage Profile',
'form': form,
}
return render(request, 'designsafe/apps/accounts/profile_edit.html', context)
示例8: profile
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
def profile(request):
context = {}
try:
tas = TASClient()
resp = tas.get_user(username=request.user)
context['profile'] = resp
except:
context['profile'] = False
# raise Exception('error loading profile')
if context['profile']['source'] != 'Chameleon':
messages.info(request,
'Your account was created outside of the Chameleon Portal. ' \
'Please visit the <a target="_blank" href="https://portal.tacc.utexas.edu">'\
'TACC User Portal</a> to edit your profile.')
return render(request, 'tas/profile.html', context)
示例9: _process_password_reset_request
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
def _process_password_reset_request(request, form):
if form.is_valid():
# always show success to prevent data leaks
messages.success(request, 'Your request has been received. If an account matching the username you provided is found, you will receive an email with further instructions to complete the password reset process.')
username = form.cleaned_data['username']
logger.info('Password reset request for username: "%s"', username)
try:
tas = TASClient()
user = tas.get_user(username=username)
resp = tas.request_password_reset(user['username'], source='Chameleon')
logger.debug(resp)
except:
logger.exception('Failed password reset request')
return True
else:
return False
示例10: clean
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
def clean(self):
cleaned_data = self.cleaned_data
username = cleaned_data.get('username')
try:
tas = TASClient()
user = tas.get_user(username=username)
except:
self.add_error('username', 'The username provided does not match an existing user.')
raise forms.ValidationError('The username provided does not match an existing user.')
password = cleaned_data.get('password')
confirm_password = cleaned_data.get('confirm_password')
valid, error_message = check_password_policy(user, password, confirm_password)
if not valid:
self.add_error('password', error_message)
self.add_error('confirm_password', '')
raise forms.ValidationError(error_message)
示例11: user_projects
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
def user_projects(request):
context = {}
tas = TASClient()
user = tas.get_user(username=request.user)
context['is_pi_eligible'] = user['piEligibility'] == 'Eligible'
projects = Project.list(username=request.user)
projects = list(p for p in projects if p.source == 'Chameleon')
for proj in projects:
try:
extras = ProjectExtras.objects.get(tas_project_id=proj.id)
proj.__dict__['nickname'] = extras.nickname
except ProjectExtras.DoesNotExist:
project_nickname = None
context['projects'] = projects
return render(request, 'projects/user_projects.html', context)
示例12: handle
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
def handle(self, *args, **options):
users = []
tas = TASClient()
if options['username']:
u = options['username']
try:
djangoUser = User.objects.get(username=u)
users.append(djangoUser)
except ObjectDoesNotExist:
self.stdout.write(self.style.ERROR('No user with username %s' % u))
else:
users = User.objects.all()
usersToUpdate = []
for u in users:
tas_user = tas.get_user(username=u.username)
if u.email != tas_user['email']:
self.stdout.write(self.style.ERROR('For User %s: %s (Chameleon), %s (TAS)' % (u.username, u.email, tas_user['email'])))
u.email = tas_user['email']
usersToUpdate.append(u)
if len(usersToUpdate) > 0:
if options['skip_confirm']:
self._run_update(usersToUpdate)
else:
self.stdout.write(self.style.NOTICE('%s users will have their emails synced with TAS. Continue?' % len(usersToUpdate)))
confirm = raw_input('Y/N: ')
if confirm == 'Y' or confirm == 'y':
self.stdout.write(self.style.NOTICE('Updating user emails'))
self._run_update(usersToUpdate)
else:
self.stdout.write(self.style.NOTICE('Cancelling user email sync'))
else:
self.stdout.write(self.style.NOTICE('There are no user emails to update'))
示例13: clean
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
def clean(self):
cleaned_data = self.cleaned_data
reset_link = reverse('designsafe_accounts:password_reset')
tas = TASClient()
current_password_correct = tas.authenticate(self._username,
cleaned_data['current_password'])
if current_password_correct:
tas_user = tas.get_user(username=self._username)
pw = cleaned_data['new_password']
confirm_pw = cleaned_data['confirm_new_password']
valid, error_message = check_password_policy(tas_user, pw, confirm_pw)
if not valid:
self.add_error('new_password', error_message)
self.add_error('confirm_new_password', error_message)
raise forms.ValidationError(error_message)
else:
err_msg = mark_safe(
'The current password you provided is incorrect. Please try again. '
'If you do not remember your current password you can '
'<a href="%s" tabindex="-1">reset your password</a> with an email '
'confirmation.' % reset_link)
self.add_error('current_password', err_msg)
示例14: email_confirmation
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
def email_confirmation(request, code=None):
context = {}
if request.method == 'POST':
form = forms.EmailConfirmationForm(request.POST)
if form.is_valid():
data = form.cleaned_data
code = data['code']
username = data['username']
password = data['password']
try:
tas = TASClient()
user = tas.get_user(username=username)
if tas.verify_user(user['id'], code, password=password):
messages.success(request,
'Congratulations, your account has been activated! '
'You can now log in to DesignSafe.')
return HttpResponseRedirect(
reverse('designsafe_accounts:manage_profile'))
else:
messages.error(request,
'We were unable to activate your account. Please try '
'again. If this problem persists, please '
'<a href="/help">open a support ticket</a>.')
form = forms.EmailConfirmationForm(
initial={'code': code, 'username': username})
except:
logger.exception('TAS Account activation failed')
form.add_error('__all__',
'Account activation failed. Please confirm your '
'activation code, username and password and try '
'again.')
else:
if code is None:
code = request.GET.get('code', '')
form = forms.EmailConfirmationForm(initial={'code': code})
context['form'] = form
return render(request, 'designsafe/apps/accounts/email_confirmation.html', context)
示例15: get_user_info
# 需要导入模块: from pytas.http import TASClient [as 别名]
# 或者: from pytas.http.TASClient import get_user [as 别名]
def get_user_info(request, username):
#username = request.GET.get('username')
resp = {}
resp['result'] = None
resp['status'] = 'error'
if username is None:
resp['message'] = 'Username is required'
try:
tas = TASClient()
resp['status'] = 'success'
users = tas.get_user(username=username)
projects = tas.projects_for_user(username)
resp['result'] = users
resp['result']['projects'] = projects
except Exception as e:
traceback.print_exc()
raise Exception('Error fetching user.')
return HttpResponse(json.dumps(resp), content_type="application/json")