def email_confirmation(request, confirmation_code): try: profile = UserProfile.objects.get(confirmation_code=confirmation_code) user = User.objects.get(pk=profile.user.pk) if user.date_joined > (timezone.now() - datetime.timedelta(days=7)): # Instant log-in after confirmation user.is_active = True user.save() user.backend = "django.contrib.auth.backends.ModelBackend" auth_login(request, user) return render_to_response('account_welcome.html', RequestContext(request, {})) else: # Delete expired user profile and account profile.delete() user.delete() info = _("The link has been expired. Please, sign-up again.") return render_to_response( 'account_error.html', RequestContext(request, { "information": info, })) except: raise Http404
def login(request): username = password = '' if request.POST: print("login post") username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: print("authenticate") if user.is_active: #redirects to admin interface if (username == "admin"): print("user admin") auth_login(request, user) return render(request, 'admin.html', {'username': username}) else: #redirects to user interface auth_login(request, user) return render(request, 'home.html', {'username': username}) else: return render(request, 'fail.html')
def login(request): """ Почти полная копия стандартного login """ redirect_to = request.GET.get('next', '') form = LoginForm(data=request.POST or None, request=request) if form.is_valid(): # Ensure the user-originating redirection url is safe. if not is_safe_url(url=redirect_to, host=request.get_host()): redirect_to = '/login/' # Okay, security check complete. Log the user in. auth_login(request, form.get_user()) if request.session.test_cookie_worked(): request.session.delete_test_cookie() return redirect(redirect_to) request.session.set_test_cookie() context = { 'form': form, 'next': redirect_to, } return TemplateResponse(request, 'auth2/login.html', context)
def is_authenticated(self, request): """ if user is_authenticated: return True else try to autenticate with django and return true/false dependent of result """ self.request = request # is authenticated if self.request.user.is_authenticated(): return True # not authenticated, call authentication form f = AuthenticationForm(data={ 'username': self.request.POST.get('username',''), 'password': self.request.POST.get('password',''), }) # if authenticated log the user in. if f.is_valid(): auth_login(self.request,f.get_user()) # this ** should ** return true return self.request.user.is_authenticated() else: # fail to auth, save form errors self.errors = f.errors return False
def post(self, request, *args, **kwargs): form = dict() form['userName'] = request.POST.get('userName') form['userPassword'] = request.POST.get('userPassword') form['captcha'] = request.POST.get('captcha') user_form = UserForm(request.POST) # print(user_form.is_valid()) if user_form.is_valid(): username = user_form.cleaned_data['userName'] password = user_form.cleaned_data['userPassword'] try: user = User.objects.filter( Q(username=username) | Q(email=username)) if check_password(password, user[0].password): auth_login(request, user[0]) # request.session['is_login'] = True # request.session['user_id'] = user[0].id # request.session['user_name'] = user[0].username # request.user.is_authenticated = True message = '登录成功' return redirect('apps.user:home') else: message = '密码不正确!' except Exception as e: # print(e) message = '用户不存在!' return render(request, 'login.html', {'js': message}) else: if user_form.errors['captcha'][0]: return render(request, 'login.html', {'js': user_form.errors['captcha'][0]}) return render(request, 'login.html', {'js': "输入错误!"})
def register(request, template_name='registration/register.html', register_form=auth_forms.RegisterForm, extra_context=None, redirect_authenticated_user=True): """ Displays the register form and handles the login action. """ if redirect_authenticated_user and request.user.is_authenticated: return http.HttpResponseRedirect('/') elif request.method == "POST": form = register_form(data=request.POST) if form.is_valid(): user = auth_models.User.objects.create_user( form.cleaned_data['username'], form.cleaned_data['email'], form.cleaned_data['password1']) user.save() auth_views.auth_login(request, user) return http.HttpResponseRedirect('/') else: form = register_form() current_site = auth_views.get_current_site(request) context = { 'form': form, 'site': current_site, 'site_name': current_site.name, } if extra_context is not None: context.update(extra_context) return auth_views.TemplateResponse(request, template_name, context)
def login(request): state = next = username = password = '' if request.GET: next = request.GET['next'] if request.POST: username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: auth_login(request, user) state = "You're successfully logged in!" if next == "": return HttpResponseRedirect('../') else: return HttpResponseRedirect(next) else: state = "Your account is not active, please contact the site admin." else: state = "Your username and/or password were incorrect." return render_to_response( 'registration/login.html', { 'msg':state, 'username': username, 'next':next, 'path' : request.path.split('/')[-2], }, context_instance=RequestContext(request) )
def is_authenticated(self, request): """ if user is_authenticated: return True else try to autenticate with django and return true/false dependent of result """ self.request = request # is authenticated if self.request.user.is_authenticated(): return True # not authenticated, call authentication form f = AuthenticationForm( data={ 'username': self.request.POST.get('username', ''), 'password': self.request.POST.get('password', ''), }) # if authenticated log the user in. if f.is_valid(): auth_login(self.request, f.get_user()) # this ** should ** return true return self.request.user.is_authenticated() else: # fail to auth, save form errors self.errors = f.errors return False
def login(request): providers = [] user = get_user_model() state = {} for provider in get_providers(): try: provider.social_app = SocialApp.objects.get(provider=provider.id, sites=settings.SITE_ID) except SocialApp.DoesNotExist: provider.social_app = None providers.append(provider) if request.method == "POST": form = LoginForm(request, data=request.POST) if form.is_valid(): auth_login(request, user) state['result'] = "success" return HttpResponse(json.dumps(state), content_type="application/json") else: return render(request, 'accounts/login_modal_error.html', { 'form': form, }) else: form = LoginForm(request) return render(request, 'accounts/login.html', { 'providers': providers, 'form': form })
def post(self, request, *args, **kwargs): if self.form.is_valid(): self.form.save() self.form.user.backend = 'django.contrib.auth.backends.ModelBackend' auth_login(request, self.form.user) return redirect('settings') return self.get(request, *args, **kwargs)
def login(request,template_name='accounts/login.html', authentication_form=AuthenticationForm, redirect_field_name = REDIRECT_FIELD_NAME, current_app=None): redirect_to = request.REQUEST.get(redirect_field_name,'/') if request.user.is_authenticated(): return HttpResponseRedirect(redirect_to) if request.method == 'POST': form = authentication_form(data = request.POST) if form.is_valid(): auth_login(request,form.get_user()) if request.session.test_cookie_worked(): request.session.delete_test_cookie() #people's circle is made at signup time,if support google account #or other login method,then create a circle in login time #so that everyone has a circle try: Circle.objects.get(user=request.user) except: Circle.objects.create(user=request.user) return HttpResponseRedirect(redirect_to) else: return render_to_response(template_name,RequestContext(request,{'form':form})) else: form = authentication_form(request) request.session.set_test_cookie() current_site = get_current_site(request) context = {'form':form, 'site':current_site, 'site_name':current_site.name,} return TemplateResponse(request,template_name,context,current_app=current_app)
def custom_login(request, url="", template_name='login.html', redirect_field_name=REDIRECT_FIELD_NAME, authentication_form=CustomAuthenticationForm): is_preview = request.REQUEST.get('preview', 0) if request.user.is_authenticated() and not is_preview: return HttpResponseRedirect("/dashboard/") #verify url settings = None if url: for os in Organization_Settings.objects.filter(deleted=0, login_url=url): settings = os if settings: request.session['ORG_SETTINGS'] = settings request.session['USER_ORGANIZATION_NAME'] = settings.organization.name """Displays the login form and handles the login action.""" redirect_to = request.REQUEST.get(redirect_field_name, '') if request.method == "POST": form = authentication_form(data=request.POST) if form.is_valid(): # Light security check -- make sure redirect_to isn't garbage. if not redirect_to or ' ' in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL # Heavier security check -- redirects to http://example.com should # not be allowed, but things like /view/?param=http://example.com # should be allowed. This regex checks if there is a '//' *before* a # question mark. elif '//' in redirect_to and re.match(r'[^\?]*//', redirect_to): redirect_to = settings.LOGIN_REDIRECT_URL # Okay, security checks complete. Log the user in. django_auth_views.auth_login(request, form.get_user()) if request.session.test_cookie_worked(): request.session.delete_test_cookie() log = LogInHistory(user=form.get_user(), date=datetime.now(), ip=request.META['REMOTE_ADDR']) log.save() return HttpResponseRedirect(redirect_to) else: form = authentication_form(request) request.session.set_test_cookie() return render_to_response(template_name, { 'form': form, redirect_field_name: redirect_to, }, context_instance=RequestContext(request))
def email_confirmation(request, confirmation_code): try: profile = UserProfile.objects.get(confirmation_code=confirmation_code) user = User.objects.get(pk=profile.user.pk) if user.date_joined > (timezone.now() - datetime.timedelta(days=7)): # Instant log-in after confirmation user.is_active = True user.save() user.backend = "django.contrib.auth.backends.ModelBackend" auth_login(request, user) info = _("You have successfuly confirmed your e-mail.") return render_to_response('account_information.html', RequestContext(request, { "information": info, })) else: # Delete expired user profile and account profile.delete() user.delete() info = _("The link has been expired. Please, sign-up again.") return render_to_response('account_error.html', RequestContext(request, { "information": info, })) except: raise Http404
def login(request): if request.method == 'POST': username = request.POST['username'] password = request.POST['password'] user = auth.authenticate(username=username, password=password,nopass=True) #profile = Profile.objects.filter(userID_f = request.user) #generatePointsUser(profile) #profile = Profile.objects.filter(userID_f = user) #profile[0].points_f = generatePointsUser(profile[0]) #profile[0].rank_f = generateRank(profile[0]) if user is not None and user.is_active: # Correct password, and the user is marked "active" profile = Profile.objects.filter(userID_f = user)[0] generatePointsUser(profile.userID_f) auth_login(request, user) profile.rank_f = generateRank(profile) profile.save() # Redirect to a success page. return HttpResponseRedirect("/") else: # Show an error page #user.backend = 'django.contrib.auth.backends.ModelBackend' return auth_login(request) #return HttpResponseRedirect("/login/") else: # Show login page return render(request, 'registration/login.html')
def post(self, request): serializer = self.serializer_class(data=request.DATA) if serializer.is_valid(): auth_login(request, serializer.object['user']) user = serializer.object['user'] blah = {"id": user.id, "username": user.username, "is_staff": user.is_staff} return Response(blah)
def signup(request): if request.user.is_authenticated: return redirect('General:home') if request.method == 'POST': SignUp = SignUpForm(request.POST) try: cache = request.session['saved'] except KeyError: cache = {} if SignUp.is_valid(): email = SignUp.cleaned_data.get('email') username = SignUp.cleaned_data.get('email') raw_password = SignUp.cleaned_data.get('password1') try: user = User.objects.create_user(username, email , raw_password) user.save() user = authenticate(username=username, password=raw_password) auth_login(request, user) current = request.user try: time_management_form = TIME_MANAGEMENT_Form(cache,user=current) if time_management_form.is_valid(): time_management_form.save() except Exception as e: pass try: exchange_form = EXCHANGE_Form(cache,user=current) if exchange_form.is_valid(): exchange_form.save() except Exception as e: pass try: voip_form = VOIP_Form(cache,user=current) if voip_form.is_valid(): voip_form.save() except Exception as e: pass try: virtual_machine_form = VIRTUAL_MACHINE_Form(cache,user=current) if virtual_machine_form.is_valid(): virtual_machine_form.save() except Exception as e: pass except IntegrityError: context = add_Menu_and_list(request) context.update({ 'form': SignUp }) context.update({ 'Title': 'Sign up' , 'sigup_error' : 'User Already Exist' }) return render(request, 'General/signup.html', context ) user = authenticate(username=username, password=raw_password) auth_login(request, user) return redirect('General:home') else: SignUp = SignUpForm() context.update({ 'form': SignUp }) context.update({ 'Title': 'Sign up' }) return render(request, 'General/signup.html', context )
def login(request): form = LoginForm(data=request.POST or None) if request.method == "POST" and form.is_valid(): auth_login(request, form.user) return HttpResponseRedirect(reverse("home")) context = { 'form': form, } return render(request, 'login.html', context)
def form_valid(self, form): if self.request.user.is_staff: # and not has_2fa(self.request): logger.info( 'is staff but does not have 2FA, redirecting to Authority account creator' ) auth_login(self.request, form.get_user(), backend='django.contrib.auth.backends.ModelBackend') return redirect('2fa_register') return super(CustomLoginView, self).form_valid(form)
def logincode(request, code): _logincode = LoginCode.objects.get(code=code) user = _logincode.user if not hasattr(user, 'backend'): for backend in settings.AUTHENTICATION_BACKENDS: if user == load_backend(backend).get_user(user.pk): user.backend = backend break if hasattr(user, 'backend'): auth_login(request, user) return profileupdate(request)
def logincode(request, code): logincode = LoginCode.objects.get(code=code) user = logincode.user if not hasattr(user, 'backend'): for backend in settings.AUTHENTICATION_BACKENDS: if user == load_backend(backend).get_user(user.pk): user.backend = backend break if hasattr(user, 'backend'): auth_login(request, user) return profileupdate(request)
def login(request, template_name="registration/login.html"): form = AuthenticationForm() if request.method == "POST": username = request.POST.get("username", "").lower() password = request.POST.get("password", "") print "username: %s" % username print "password: %s" % password """ import pdb; pdb.set_trace() """ username = request.POST.get("username", "").lower() password = request.POST.get("password", "") if username and password: try: user = User.objects.get(username__iexact=username) except User.DoesNotExist: user = None if user: print "user exists" response = auth_login(request) return response else: print "no such user, create it" usercreationform = UserCreationForm({ 'username': username, 'password1': password, 'password2': password, }) print "print creation form is valid", usercreationform.is_valid() if usercreationform.is_valid(): usercreationform.save() response = auth_login(request) return response else: pass print "invald registration, but valid login?" else: print "invalid login form" print "hi" form = AuthenticationForm(data=request.POST) form.is_valid() # just doing this to get the errors to trigger # import pdb; pdb.set_trace() # form = AuthenticationForm() ctx = dict(form=form) print form.errors # if form.errors: # messages.error(request, "Oops, we had a problem logging you in. Can you try again?") return render_to_response( template_name, RequestContext(request, ctx))
def reset_password(request, uidb64, token, query_payload): account_activation_token = TokenGenerator() try: uid = force_text(urlsafe_base64_decode(uidb64)) user = User.objects.get(pk=uid) except (TypeError, ValueError, OverflowError, User.DoesNotExist): user = None if user is not None and account_activation_token.check_token(user, token): signer = TimestampSigner() try: query_payload = query_payload.replace("-", ":") data = signer.unsign(query_payload, max_age=20) except Exception: return HttpResponse('Invalid activation payload') else: secret_data = signing.loads(data) uid = secret_data.get("user_id") reset_access = secret_data.get("reset_access") sec_word = secret_data.get("secret_word") if uid == user.id and reset_access is True and sec_word == "I Love Georgia": if request.method == 'GET': query_payload = query_payload.replace(":", "-") return render(request, "reset_password_page.html", { "uid": uidb64, "token": token, "query_payl": query_payload }) else: data = request.POST password1 = data.get("password1") password2 = data.get("password2") errors = PasswordValidator(password1, password2).get_errors() if len(errors) > 0: return render( request, "reset_password_page.html", { "errors": errors, "uid": uidb64, "token": token, "query_payl": query_payload }) user.set_password(password1) user.save() auth_login(request, user) return HttpResponseRedirect("/") else: return HttpResponse('Activation link is invalid!') else: return HttpResponse('Activation link is invalid!')
def get_auth_token(request): username = request.POST.get('username') password = request.POST.get('password') user = authenticate(username=username, passwword=password) if user is not None: if user.is_active: auth_login(request, user) token, created = Token.objects.get_or_create(user=user) request.session['auth'] = token.key #return redirect('/cliente/', request) return render(request, 'accounts/error.html', {'error': 'Login inválido 3'}) return redirect('accounts/error.html', request)
def login_view(request): if request.method == 'POST': form = AuthenticationForm(data=request.POST) if form.is_valid(): username = form.get_user() user1 = User.objects.get(username=username) auth_login(request, username) if user1.groups.filter(name__in=['Manager']).exists(): return redirect('/project_list') elif user1.groups.filter(name__in=['Developer']).exists(): return redirect('/task_list') else: form = AuthenticationForm() return render(request, 'Project_Management/login.html', {'form': form})
def login(request): username = request.POST.get('username') password = request.POST.get('password') user = authenticate(username=username, password=password) if user is not None: if user.is_active: authview.auth_login(request, user) return render(request, 'learning_logs/index.html', {}) else: return render(request, 'users/login.html', {}) else: context = {'form': AuthenticationForm} return render(request, 'users/login.html', context)
def NewContaView(request): newconta = RegistrationForm(request.POST or None) if newconta.is_valid(): user = newconta.save(commit=False) password = newconta.cleaned_data.get('password') user.set_password(password) user.save() new_user = authenticate(username=user.username, password=password) auth_login(request, new_user) return render(request, './inicio/index.html', {'user': user}) return render(request, './login/create_conta.html', {'newconta': newconta})
def login(request): if request.user.is_authenticated: return redirect('General:home') if request.method == 'POST': login_form = AuthenticationForm(request, data=request.POST) if login_form.is_valid(): auth_login(request, login_form.get_user()) return redirect('General:home') else: context.update({ 'form' : login_form }) return render(request, 'General/login.html', context) login_form = AuthenticationForm() context.update({ 'form' : login_form }) return render(request, 'General/login.html', context)
def login(request): #return auth_login(request) if request.method == "POST": username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: auth_login(request) return redirect('info_url') # invalid login return redirect('index_url')
def signup(request): if request.method == 'POST': form = SignUpForm(request.POST or None) if form.is_valid(): user = form.save(commit=False) user.save() auth_login(request, user) return redirect('accounts:profile') else: form = SignUpForm() context = { 'form': form, } return render(request, 'accounts/signup.html', context)
def activate(request, uidb64, token): account_activation_token = TokenGenerator() try: uid = force_text(urlsafe_base64_decode(uidb64)) user = User.objects.get(pk=uid) except (TypeError, ValueError, OverflowError, User.DoesNotExist): user = None if user is not None and account_activation_token.check_token(user, token): user.is_active = True user.save() auth_login(request, user) return HttpResponseRedirect("/") else: return HttpResponse('Activation link is invalid!')
def loginView(request): if request.method == 'POST': form = AuthenticationForm(data=request.POST) if form.is_valid(): user = form.get_user() auth_login(request, user) return redirect('/list/') else: form2 = AuthenticationForm() form = sea() return render(request, 'registration/login.html', { 'form': form, 'form2': form2 })
def prepare_view(self,): """ request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME, authentication_form=AuthenticationForm): Displays the login form and handles the login action. this is from django.contrib.auth.views """ from django.contrib.auth.views import REDIRECT_FIELD_NAME as redirect_field_name # = 'next' from django.contrib.auth.views import AuthenticationForm as authentication_form from django.contrib.auth.views import auth_login from django.contrib.sites.models import Site, RequestSite redirect_to = self.request.REQUEST.get(redirect_field_name, "") if self.request.method == "POST": self.form = authentication_form(data=self.request.POST) if self.form.is_valid(): # Light security check -- make sure redirect_to isn't garbage. if not redirect_to or " " in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL # Heavier security check -- redirects to http://example.com should # not be allowed, but things like /view/?param=http://example.com # should be allowed. This regex checks if there is a '//' *before* a # question mark. elif "//" in redirect_to and re.match(r"[^\?]*//", redirect_to): redirect_to = settings.LOGIN_REDIRECT_URL # Okay, security checks complete. Log the user in. auth_login(self.request, self.form.get_user()) setattr(self, redirect_field_name, redirect_to) if self.request.session.test_cookie_worked(): self.request.session.delete_test_cookie() raise MustRedirect(redirect_to) else: # Invalid user/password messages.warning(self.request, _("Sorry, that's not a valid username or password")) else: self.form = authentication_form(self.request) self.request.session.set_test_cookie() if Site._meta.installed: self.site = Site.objects.get_current() else: self.site = RequestSite(self.request) setattr(self, redirect_field_name, redirect_to)
def login(request, *args, **kwargs): if not request.user.is_authenticated(): return auth_login(request, *args, **kwargs) else: if checkCredentials(request): return HttpResponseRedirect(reverse('meter-readings-add')) return HttpResponseRedirect(reverse('home'))
def login(request, template_name='auth_ex/user/login.html', redirect_field_name=REDIRECT_FIELD_NAME, authentication_form=UserAuthenticationForm, extra_context=None): return auth_login(request, template_name, redirect_field_name, authentication_form, extra_context)
def login(request, **kwargs): """ This is a replacement for :func:`django.contrib.auth.views.login` that requires two-factor authentication. It's slightly clever: if the user is already authenticated but not verified, it will only ask the user for their OTP token. If the user is anonymous or is already verified by an OTP device, it will use the full username/password/token form. In order to use this, you must supply a template that is compatible with both :class:`~django_otp.forms.OTPAuthenticationForm` and :class:`~django_otp.forms.OTPTokenForm`. This is a good view for :setting:`OTP_LOGIN_URL`. Parameters are the same as :func:`~django.contrib.auth.views.login` except that this view always overrides ``authentication_form``. """ user = request.user if _user_is_anonymous(user) or user.is_verified(): form = OTPAuthenticationForm else: form = partial(OTPTokenForm, user) # A minor hack to make django.contrib.auth.login happy user.backend = request.session[BACKEND_SESSION_KEY] kwargs['authentication_form'] = form return auth_login(request, **kwargs)
def home(request): if request.user.is_authenticated: return redirect('settings') if request.method == 'POST': form = AuthenticationForm(request, data=request.POST) if form.is_valid(): username = form.cleaned_data.get('username') password = form.cleaned_data.get('password') user = authenticate(username=username, password=password) if user: auth_views.auth_login(request, user) return redirect('home') # user = User.objects.get(pk=) # auth_views.auth_login(request, request.POST, backend='django.contrib.auth.backends.ModelBackend') form = AuthenticationForm(request) return render(request, 'home.html', {'form': form})
def login(request, **kwargs): """ This is a replacement for :func:`django.contrib.auth.views.login` that requires two-factor authentication. It's slightly clever: if the user is already authenticated but not verified, it will only ask the user for their OTP token. If the user is anonymous or is already verified by an OTP device, it will use the full username/password/token form. In order to use this, you must supply a template that is compatible with both :class:`~django_otp.forms.OTPAuthenticationForm` and :class:`~django_otp.forms.OTPTokenForm`. This is a good view for :setting:`OTP_LOGIN_URL`. Parameters are the same as :func:`~django.contrib.auth.views.login` except that this view always overrides ``authentication_form``. """ user = request.user if user.is_anonymous() or user.is_verified(): form = OTPAuthenticationForm else: form = partial(OTPTokenForm, user) # A minor hack to make django.contrib.auth.login happy user.backend = request.session[BACKEND_SESSION_KEY] kwargs['authentication_form'] = form return auth_login(request, **kwargs)
def login(request): """Provide a login form if not authenticated, display a message and redirect if authenticated""" if request.user.is_authenticated(): messages.add_message(request, messages.INFO, "You are already logged in") return HttpResponseRedirect(reverse("instructions.views.Pregame")) return auth_login(request)
def login(request): if request.user.is_authenticated(): next_page = request.REQUEST.get('next', 'account_settings') return redirect(next_page) return auth_login(request, template_name='ksp_login/login.html', extra_context=login_providers(request))
def login(request): context = {'university': University.objects.filter(user=None)} if request.method == 'POST': if request.POST['action'] == 'register': form_registration = RegistrationForm(request.POST) form_manager = ManagerForm(request.POST, request.FILES) if form_registration.is_valid() and form_manager.is_valid(): user = User.objects.create_user(request.POST['username'], request.POST['email'], request.POST['password']) user.is_active = False user.save() manager = form_manager.save(commit=False) manager.user = user manager.save() messages.success( request, "Pendaftaran Anda sedang diverifikasi oleh panitia. Selanjutnya Anda akan dihubungi oleh LO." ) else: context['register_error'] = True elif request.POST['action'] == 'login': return auth_login(request, template_name='participant/login.html') if request.GET.get('next', False): context['next'] = request.GET['next'] return render(request, 'participant/login.html', context)
def login_router(request): bundle_name = getattr(settings, 'BUNDLE_NAME', 'FAKE') log.info('current BUNDLE_NAME: {}'.format(bundle_name)) if bundle_name in settings.BUNDLES: return realme_login(request) else: return auth_login(request)
def login(request): providers = [] for provider in get_providers(): try: provider.social_app = SocialApp.objects.get(provider=provider.id, sites=settings.SITE_ID) except SocialApp.DoesNotExist: provider.social_app = None providers.append(provider) ip = get_ip(request) g = GeoIP2() print(ip) if ip is not None and ip is '127.0.0.1': print(g.city('218.85.133.23')) else: print('local or no ip') return auth_login(request, authentication_form=LoginForm, template_name='accounts/login_form.html', extra_context={'providers': providers})
def LoginView(request): if request.method == 'POST': form = AuthenticationForm(request.POST) username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: if user.is_active: auth_login(request, user) return render(request, './inicio/index.html', {'user': user}) else: messages.error(request, 'Usuário ou senha incorretos.') else: form = AuthenticationForm() return render(request, './login/logar_conta.html', {'form': form})
def home(request): if request.user.is_authenticated(): return HttpResponseRedirect('/historical/') fields_set = False for field in fee_defaults: if field in request.GET: fields_set = True business_days_delay = 0 foreign_wire_fee = 0 domestic_wire_fee = 0 fee_schedule = fee_defaults['fee_schedule'] increment = 1 if fields_set: form = FeeSelectorSimple(request.GET) else: form = FeeSelectorSimple() if form.is_valid(): cleaned_data = form.clean() fee_schedule = cleaned_data['fee_schedule'] most_recent_ticker_queryset = TickerHistory.objects.exclude(cb_buy_value=None).order_by('id').reverse()[:1] most_recent_ticker = most_recent_ticker_queryset[0] cost_1 = most_recent_ticker.cb_buy_value usd_50 = (float(1) / float(cost_1)) * 50 env = _get_chart_data(business_days_delay, foreign_wire_fee, domestic_wire_fee, fee_schedule, increment) env['feeform'] = form env['profit_name'] = 'Difference' env['50_usd'] = '%.6f' % usd_50 return auth_login(request, template_name='home.html', extra_context=env)
def login(request): """Provide a login form if not authenticated, display a message and redirect if authenticated""" if request.user.is_authenticated(): messages.add_message(request, messages.INFO, 'You are already logged in') return HttpResponseRedirect(reverse('instructions.views.Pregame')) return auth_login(request)
def login(request, **kwargs): """ If user is signed in redirects to main page, if not returns base django authentication view """ print(request.POST) if request.user.is_authenticated(): return redirect(settings.LOGIN_REDIRECT_URL) return auth_login(request, authentication_form=LoginForm, **kwargs)
def login(request): """ Display the login page. """ context = {'is_testing' : _is_test_url()} context['organisation_name'] = ORGANISATION_NAME return auth_login(request, extra_context=context)
def login(request, *args, **kwargs): response = auth_login(request, *args, **kwargs) if request.user.is_authenticated(): if hasattr(request.user, 'aasheuser'): # If this was an AASHE Account login, cache the Drupal cookie aashe_user = request.user.aasheuser response = set_session_id(request, response, aashe_user.drupal_session_key) return response
def login(request): from django.contrib.auth.views import login as auth_login login = auth_login(request) if request.user.is_authenticated(): # testing celery, delete this: load_contacts.delay('*****@*****.**') user_event(request, u'LI') return login
def rate_limit_login(request): if request.user.is_authenticated(): return redirect(request.GET.get('next', reverse('mapApp:index'))) if request.limited: return redirect(reverse('userApp:rate_limited')) return auth_login(request, template_name='userApp/login.html')
def userregister(request): # Initialize the form either fresh or with the appropriate POST data as the instance if request.method == 'POST': form = CustomUserCreationForm(request.POST) if form.is_valid(): user = form.save() new_user = authenticate(username=user.username, password=request.POST['password1']) auth_login(request, new_user) messages.success(request, 'Registration complete') return HttpResponseRedirect(reverse('profile-update')) else: form = CustomUserCreationForm() return render(request, 'accounts/register.html', { 'form': form, })
def login(request): if request.user.is_authenticated(): return HttpResponseRedirect('index') else: return auth_login(request, 'login.html', extra_context = { "backends": settings.SOCIAL_AUTH_ENABLED_BACKENDS, "local_login": settings.LOCAL_LOGIN, })
def login(request, *args, **kwargs): if request.user and request.user.is_authenticated(): return HttpResponseRedirect(reverse('accounts:edit_dashboard')) return auth_login( request, authentication_form=LoginForm, template_name='accounts/login.html', )
def login(request, template_name='activity/login.html', redirect_field_name=REDIRECT_FIELD_NAME): if hasattr(request, 'user') and request.user.is_authenticated(): redirect_to = request.POST.get(redirect_field_name, request.GET.get(redirect_field_name, '')) if not is_safe_url(url=redirect_to, host=request.get_host()): redirect_to = resolve_url(settings.LOGIN_REDIRECT_URL) return HttpResponseRedirect(redirect_to) return auth_login(request, template_name = template_name, redirect_field_name = redirect_field_name)
def login(request, *args, **kwargs): """ Authentication view. Changes session expiry time """ if request.method == 'POST': if not request.POST.get('remember_me', None): request.session.set_expiry(0) return auth_login(request, *args, **kwargs)
def index(request, template_name='index.html'): """ If logged in, redirect to dashboard. Else, show login form. """ if request.user.is_authenticated(): return HttpResponseRedirect(reverse('bbotweb_dashboard')) return auth_login(request, template_name, redirect_field_name='next')
def custom_login(request, template_name='login.html', redirect_field_name=REDIRECT_FIELD_NAME, authentication_form=CustomAuthenticationForm): if request.user.is_authenticated(): return HttpResponseRedirect("/dashboard/") """Displays the login form and handles the login action.""" redirect_to = request.REQUEST.get(redirect_field_name, '') if request.method == "POST": form = authentication_form(data=request.POST) if form.is_valid(): # Light security check -- make sure redirect_to isn't garbage. if not redirect_to or ' ' in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL # Heavier security check -- redirects to http://example.com should # not be allowed, but things like /view/?param=http://example.com # should be allowed. This regex checks if there is a '//' *before* a # question mark. elif '//' in redirect_to and re.match(r'[^\?]*//', redirect_to): redirect_to = settings.LOGIN_REDIRECT_URL # Okay, security checks complete. Log the user in. django_auth_views.auth_login(request, form.get_user()) if request.session.test_cookie_worked(): request.session.delete_test_cookie() return HttpResponseRedirect(redirect_to) else: form = authentication_form(request) request.session.set_test_cookie() pathway_list = Pathway.get_pathway_list() return render_to_response(template_name, { 'form': form, 'pathway_list':pathway_list, redirect_field_name: redirect_to, }, context_instance=RequestContext(request))