本文整理汇总了Python中forum.models.User类的典型用法代码示例。如果您正苦于以下问题:Python User类的具体用法?Python User怎么用?Python User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_authentication_request
def process_authentication_request(self, request):
logout_request = request.POST.get('logoutRequest', None)
if logout_request:
if settings.CAS_LOGOUT_REQUESTS_ENABLED:
handle_logout_request(request, logout_request)
raise InvalidAuthentication('CAS logout request processed')
else:
raise InvalidAuthentication('CAS logout request ignored, disabled in configuration')
ticket = request.GET.get('ticket', None)
if not ticket:
raise InvalidAuthentication(_('Login failed. CAS ticket is missing.'))
service = service_url(request)
username, attributes = validate(ticket, service)
if not username:
raise InvalidAuthentication(_('Login failed. CAS ticket is invalid.'))
try:
_user = User.objects.get(username=username)
self._sync_user_attributes(_user, attributes)
except User.DoesNotExist:
_user = User(username=username)
_user.set_unusable_password()
self._sync_user_attributes(_user, attributes)
_user.save()
UserJoinsAction(user=_user, ip=request.META['REMOTE_ADDR']).save()
request.session[CAS_TICKET_SESSION_ATTR] = ticket
return _user
示例2: get_openid_user
def get_openid_user(cls, assoc_key):
try:
authmap = drupal.Authmap.objects.using(DRUPAL_DB).get(authname=assoc_key)
drupal_user = drupal.Users.objects.using(DRUPAL_DB).get(uid=authmap.uid)
try:
user = User.objects.get(username=drupal_user.name)
except User.DoesNotExist:
user = User(username=drupal_user.name)
cls.get_user_data(drupal_user, user)
user.save()
return user
except drupal.Authmap.DoesNotExist, drupal.Users.DoesNotExist:
return None
示例3: get_openid_user
def get_openid_user(cls, assoc_key):
try:
user_openid = lernanta.UserOpenID.objects.using(LERNANTA_DB).get(display_id__exact=assoc_key)
lernanta_user = lernanta.UserProfile.objects.using(LERNANTA_DB).get(user=user_openid.user)
try:
user = User.objects.get(username=lernanta_user.username)
except User.DoesNotExist:
user = User(username=lernanta_user.username)
cls.get_user_data(lernanta_user, user)
user.save()
return user
except lernanta.UserOpenID.DoesNotExist, lernanta.UserProfile.DoesNotExist:
return None
示例4: global_variables
def global_variables(request):
return {
'hot_nodes': Node.hot(),
'hot_topics': Topic.hot(),
'hot_users': User.hot(),
'latest_topics': Topic.objects.order_by('-id')[:10],
'central_banks': CentralBank.objects.all(),
}
示例5: register
def register(request):
if request.method == "POST":
form = ClassicRegisterForm(request.POST)
email_feeds_form = SimpleEmailSubscribeForm(request.POST)
if form.is_valid() and email_feeds_form.is_valid():
username = form.cleaned_data["username"]
password = form.cleaned_data["password1"]
email = form.cleaned_data["email"]
user_ = User(username=username, email=email)
user_.set_password(password)
if User.objects.all().count() == 0:
user_.is_superuser = True
user_.is_staff = True
user_.save()
UserJoinsAction(user=user_, ip=request.META["REMOTE_ADDR"]).save()
if email_feeds_form.cleaned_data["subscribe"] == "n":
user_.subscription_settings.enable_notifications = False
user_.subscription_settings.save()
return login_and_forward(request, user_, None, _("A welcome email has been sent to your email address. "))
else:
form = ClassicRegisterForm(initial={"next": "/"})
email_feeds_form = SimpleEmailSubscribeForm()
return render_to_response(
"auth/complete.html",
{"form1": form, "email_feeds_form": email_feeds_form},
context_instance=RequestContext(request),
)
示例6: register
def register(request):
if request.method == 'POST':
form = ClassicRegisterForm(request.POST)
email_feeds_form = SimpleEmailSubscribeForm(request.POST)
if form.is_valid() and email_feeds_form.is_valid():
username = form.cleaned_data['username']
password = form.cleaned_data['password1']
email = form.cleaned_data['email']
user_ = User(username=username, email=email)
user_.set_password(password)
if User.objects.all().count() == 0:
user_.is_superuser = True
user_.is_staff = True
user_.save()
UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save()
if email_feeds_form.cleaned_data['subscribe'] == 'n':
user_.subscription_settings.enable_notifications = False
user_.subscription_settings.save()
return login_and_forward(request, user_, None, _("A welcome email has been sent to your email address. "))
else:
form = ClassicRegisterForm(initial={'next':'/'})
email_feeds_form = SimpleEmailSubscribeForm()
return render_to_response('auth/complete.html', {
'form1': form,
'email_feeds_form': email_feeds_form
}, context_instance=RequestContext(request))
示例7: register
def register(request):
if request.method == 'POST':
form = ClassicRegisterForm(request.POST.copy())
#form = ClassicRegisterForm(request.POST)
logging.info(form)
if form.is_valid():
logging.error(form.cleaned_data)
username = form.cleaned_data['username']
password = form.cleaned_data['password1']
#email = form.cleaned_data['email']
#user_ = User(username=username, email=email)
user_ = User(username=username)
user_.set_password(password)
if User.objects.all().count() == 0:
user_.is_superuser = True
user_.is_staff = True
user_.save()
#UserJoinsAction(user=user_, ip=request.META['REMOTE_ADDR']).save()
return login_and_forward(request, user_, None, _("A welcome email has been sent to your email address. "))
else:
#form = ClassicRegisterForm(initial={'next':'/'})
form = ClassicRegisterForm()
return render_to_response('auth/complete.html', {
'form1': form
}, context_instance=RequestContext(request))
示例8: authenticate
def authenticate(self, username=None, password=None):
try:
drupal_user = drupal.Users.objects.using(DRUPAL_DB).get(name=username)
except drupal.Users.DoesNotExist:
return None
if User.objects.filter(username=drupal_user.name):
# Only authenticates users that have not being migrated to the django database.
return None
user = User(username=username)
pwd_valid = self.check_password(drupal_user, user, password)
if pwd_valid:
DrupalAuthBackend.get_user_data(drupal_user, user)
if User.objects.all().count() == 0:
user.is_superuser = True
user.is_staff = True
user.save()
return user
else:
return None
示例9: update_forum_user
def update_forum_user(request):
""" Create or Update Forum User model """
try:
# Customise User Model
# username = request.user.username.split('@')[0]
user = User.objects.get(user_ptr_id=request.user.id)
user.user_ptr = request.user
user.save()
except ObjectDoesNotExist:
obj = User()
obj.user_ptr = request.user
obj.email_isvalid = True
obj.last_seen = request.user.last_login
obj.username = request.user.username if '@' not in request.user.username else request.user.username.split('@')[0]
obj.real_name = "%s %s" % (request.user.first_name, request.user.last_name)
# obj.is_active = request.user.is_active
obj.email = request.user.email
obj.profile_image_url = request.session['profile_image'] if 'profile_image' in request.session else ''
obj.save()
示例10: register
def register(request):
banned_ips = cache.get(BANNED_IPS_KEY, set())
ip = get_client_ip(request)
if ip in banned_ips:
logging.warning("Spammer returned ip:%s" % ip)
return HttpResponseRedirect("http://www.pudelek.pl/artykul/x/")
if request.method == "POST":
banned_emails = cache.get(BANNED_EMAILS_KEY, set())
if request.POST["email"] in banned_emails:
logging.warning("Spammer returned:%s, ip:%s" % (request.POST["email"], ip))
return HttpResponseRedirect("http://www.pudelek.pl/artykul/x/")
form = ClassicRegisterForm(request.POST)
if form.is_valid():
username = form.cleaned_data["username"]
password = form.cleaned_data["password1"]
email = form.cleaned_data["email"]
# Honeypot checks
if request.POST.get("age", None):
logging.warning("Age honeypot filled, will not register for email:%s, ip:%s" % (email, ip))
ban(email, ip)
return HttpResponseRedirect(reverse("index"))
if request.POST.get("birthday", None):
logging.warning("Birthday honeypot filled, will not register for email:%s, ip:%s" % (email, ip))
ban(email, ip)
return HttpResponseRedirect(reverse("index"))
if request.POST.get("website", None):
logging.warning("Website honeypot filled, will not register for email:%s, ip:%s" % (email, ip))
ban(email, ip)
return HttpResponseRedirect(reverse("index"))
user_ = User(username=username, email=email)
user_.set_password(password)
if User.objects.all().count() == 0:
user_.is_superuser = True
user_.is_staff = True
user_.save()
UserJoinsAction(user=user_, ip=request.META["REMOTE_ADDR"]).save()
logging.info("New user joined with email:%s from ip:%s" % (email, ip))
return login_and_forward(request, user_, None, _("A welcome email has been sent to your email address. "))
else:
form = ClassicRegisterForm(initial={"next": "/"})
return render_to_response(
"auth/register.html",
{"form1": form, "bigicon_providers": _get_bigicon_providers(request)},
context_instance=RequestContext(request),
)
示例11: process_authentication_request
def process_authentication_request(self, request):
# Check for the Shibboleth session header.
if 'HTTP_SHIB_SESSION_ID' in request.META and request.META['HTTP_SHIB_SESSION_ID']:
# Fetch the username and email from Shibboleth headers.
utf8_username = request.META['HTTP_SSONAME'].decode('utf-8')
# Create an ASCII compatible version of the username,
# because OSQA/Django have bugs handling UTF8 strings in usernames.
username = unicodedata.normalize('NFKD', utf8_username).encode('ascii', 'ignore')
email = request.META['HTTP_SSOCONTACTMAIL']
# Try to load the user from the database, by its email.
user = None
try:
user = User.objects.get(email=email)
except:
pass
if user is None:
# The user was not found, so it must be a new user.
# Let's create it on the database.
user = User(username=username, email=email)
user.email_isvalid = True
user.set_unusable_password()
user.save()
UserJoinsAction(user=user, ip=request.META['REMOTE_ADDR']).save()
# Return the User object of the authenticated user.
return user
else:
raise InvalidAuthentication("Shibboleth Authentication Failure.")
示例12: register
def register(request):
email = request.POST['emailRegister']
if validateEmail(email):
user = User(email = email,display_name = email)
user.save();
raw_password = randint(1000000,9999999)
user.set_password(str(raw_password))
user.save()
send_mail('Welcome to Claremont Academia!','You temporary password is '+ str(raw_password) +'.', \
'[email protected]',[email],fail_silently=False)
return redirect('/login/')
else: return render(request,'loginpage.html',{'invalid_email':True})
示例13: process_authentication_request
def process_authentication_request(self, request):
username = request.POST["username"].strip()
password = request.POST["password"]
uid = str(settings.LDAP_USER_MASK) % username
# an empty password will cause ldap to try an anonymous bind. This is picked up here
if not password:
raise InvalidAuthentication(
_("Login failed. Please enter valid username and password (both are case-sensitive)")
)
ldapo = ldap.initialize(str(settings.LDAP_SERVER))
if settings.LDAP_USE_TLS:
ldapo.start_tls_s()
ldapo.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
try:
ldapo.simple_bind_s(str(settings.LDAP_BIND_DN), str(settings.LDAP_BIND_SECRET))
search = ldapo.search_s(str(settings.LDAP_BASE_DN), ldap.SCOPE_SUBTREE, uid)
except ldap.LDAPError:
# could not bind using credentials specified in ldap config
raise InvalidAuthentication(_("Login failed - LDAP bind error. Please contact your system administrator"))
ldapo.unbind_s()
if not search:
# could not find user
raise InvalidAuthentication(
_("Login failed. Please enter valid username and password (both are case-sensitive)")
)
# now try to bind as selected user; should raise exception if bind fails
ldapo = ldap.initialize(str(settings.LDAP_SERVER))
if settings.LDAP_USE_TLS:
ldapo.start_tls_s()
ldapo.set_option(ldap.OPT_PROTOCOL_VERSION, 3)
try:
ldapo.simple_bind_s(search[0][1][str(settings.LDAP_DN)][0], password)
except ldap.LDAPError:
# could not bind as user - password is incorrect
raise InvalidAuthentication(
_("Login failed. Please enter valid username and password (both are case-sensitive)")
)
ldapo.unbind_s()
try:
return User.objects.get(username=username)
except User.DoesNotExist:
userinfo = search[0][1]
_user = User(
username=userinfo[str(settings.LDAP_UID)][0],
email=userinfo[str(settings.LDAP_MAIL)][0],
real_name=userinfo[str(settings.LDAP_NAME)][0],
)
_user.email_isvalid = True
_user.set_unusable_password()
_user.save()
UserJoinsAction(user=_user, ip=request.META["REMOTE_ADDR"]).save()
return _user
示例14: authenticate
def authenticate(self, username=None, password=None):
try:
lernanta_user = lernanta.UserProfile.objects.using(LERNANTA_DB).get(username=username)
except lernanta.UserProfile.DoesNotExist:
return None
try:
user = User.objects.get(username=lernanta_user.username)
user.is_active = lernanta_user.user.is_active
user.save()
except User.DoesNotExist:
user = User(username=username)
if not lernanta_user.user.is_active or not lernanta_user.password:
return None
pwd_valid = self.check_password(lernanta_user, user, password)
if pwd_valid:
LernantaAuthBackend.get_user_data(lernanta_user, user)
if User.objects.all().count() == 0:
user.is_superuser = True
user.is_staff = True
user.save()
return user
else:
return None
示例15: oauth
def oauth(request, provider):
code = request.GET.get('code')
if not code:
# 认证返回的params中没有code,肯定出错了
# 重定向到某处,再做处理
raise
social_sites = SocialSites(settings.SOCIALOAUTH_SITES)
s = social_sites.get_site_object_by_name(provider)
# 用code去换取认证的access_token
s.get_access_token(code)
u = User.from_oauth(s.name, s.uid, s.access_token, s.avatar)
login_user(request, u)
return redirect('index')