def login(request): """ Login view """ if request.method == 'POST': form = AuthenticationForm(data=request.POST) if form.is_valid(): user = authenticate(email=request.POST['email'], password=request.POST['password']) if user is not None: if user.is_active: django_login(request, user) return redirect('/') else: return redirect('/') #: if form is invalid, would rather flash an error message on login page... #message = request.session['message'] = 'Hello view2!' #return render_to_response('accounts/login.html', { #'form': form, #'message': message, #}, context_instance=RequestContext(request)) else: form = AuthenticationForm() return render_to_response('auth/login.html', { 'form': form, }, context_instance=RequestContext(request))
def LoginView(request): """ Log in view """ if request.method == 'POST': form = AuthenticationForm(data=request.POST) content = {} if form.is_valid(): user = authenticate(username=request.POST['username'], password=request.POST['password']) if user is not None: if user.is_active: login(request, user) return HttpResponseRedirect('test') else: content = {} form = TargetUserForm() content['form'] = form content['user'] = user return render(request, 'target_user_create.html', content) else: content['info'] = "can not login in" return render(request, 'login.html', content) else: form = AuthenticationForm() return render_to_response('login.html', { 'form': form, }, context_instance=RequestContext(request))
def login_user(request): next = request.GET.get('next') form = AuthenticationForm() if request.method == 'POST': print 1 form = AuthenticationForm(data=request.POST) if form.is_valid(): print 2 user = authenticate(username=request.POST['username'], password=request.POST['password']) if user is not None: print 3 if user.is_active: print 4 django_login(request, user) if next: return HttpResponseRedirect(next) else: return HttpResponseRedirect(next) else: messages.error(request, "Нет такого пользователя или он не активирован!") else: messages.error(request, "Неверный пользователь или пароль!") return render_to_response('accounts/login.html', { 'form': form, }, context_instance=RequestContext(request))
def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME): redirect_to = request.REQUEST.get(redirect_field_name, '') if not redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL if request.user.is_authenticated(): return HttpResponseRedirect(redirect_to) if request.method == "POST": form = AuthenticationForm(data=request.POST) if form.is_valid(): from django.contrib.auth import login login(request, form.get_user()) if request.session.test_cookie_worked(): request.session.delete_test_cookie() if not redirect_to or '//' in redirect_to or ' ' in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL return HttpResponseRedirect(redirect_to) else: form = AuthenticationForm(request) request.session.set_test_cookie() return render(request, template_name, { 'form': form, redirect_field_name: redirect_to, })
def index(): """Application entry point.""" error = None status = None form = AuthenticationForm(request.form) if request.method == 'POST' and form.validate(): # We need positional arguments for nova client # and keywords arguments for neutron client keys = ['username', 'password', 'tenant_name', 'auth_url'] args = [getattr(form, key).data for key in keys] kwargs = dict(zip(keys, args)) try: topology = Topology(*args, **kwargs) return render_template('map.html', data=topology.build(), tenant_name=kwargs['tenant_name'], auth_url=kwargs['auth_url']), 200 except Exception as e: try: # Handle Neutron client exceptions first error = json.loads(e.message).pop('error') status = error.get('code', 500) except ValueError: # Wrap Nova client and other exceptions # into a serializable object status = getattr(e, 'http_status', 500) error = {'title': type(e).__name__, 'message': str(e), 'code': status} return render_template('index.html', form=form, error=error), status
def submit_policy_authentication(): form = AuthenticationForm(csrf_enabled=False) if form.validate_on_submit(): patient_id = form.identifier.data redirected_url = '/patient/' + patient_id return redirect(redirected_url) return render_template('authentication.html',form=form)
def index(): user = None if 'username' in session: user = User().get(session['username']) authform = AuthenticationForm(request.form) if request.method == "POST" and authform.validate(): user = User().authentication(authform.email.data, authform.password.data) session['username'] = user.name if user.is_staff: return redirect(url_for('admin')) else: return redirect(url_for('home')) else: return render_template('index.html', authform=authform, user=user)
def home(): project_form = ProjectForm() auth_form = AuthenticationForm() return render_template("home.html", project_form=project_form, auth_form=auth_form, session=session)
def signin(request): error = "" if request.method == 'POST': form = AuthenticationForm(request.POST) if form.is_valid(): login = form.cleaned_data['login'] password = form.cleaned_data['password'] user = Service().client.service.ReadByLoginAndPassword(login.lower(), password) if user and user.IsAdmin and user.IsConfirmed: request.session['login'] = login request.session['id'] = user.Id return redirect('index') error = "Неверный логин или пароль" if not user else "Вы не были подтверждены" if user.IsAdmin else 'Вы не администратор' else: form = AuthenticationForm() return render(request, 'signin.html', RequestContext(request, {'form': form, 'error': error,}))
def login(request): context = {} if request.method == 'GET': form = AuthenticationForm() context['form'] = form return render_to_response('web/login.html', RequestContext(request,context)) elif request.method == 'POST': form = AuthenticationForm(request.POST) if form.is_valid(): username = request.POST['username'] url = '/user/'+username+'/dashboard/' print url return redirect(url) else: context['form'] = form return render_to_response('web/login.html', RequestContext(request,context)) return render_to_response('web/login.html', RequestContext(request,context))
def login_by_email(request): form = AuthenticationForm() if request.method == 'POST': form = AuthenticationForm(request, request.POST) if form.is_valid(): cd = form.cleaned_data user = authenticate(username = cd['email'], password = cd['password']) login(request, user) if request.GET.get('next', None): return HttpResponseRedirect(request.GET.get('next')) else: return HttpResponseRedirect('/') return render_to_response('registration/login.html', { 'form': form, }, context_instance=RequestContext(request))
def login_view(request): form = AuthenticationForm(data=request.POST) if form.is_valid(): backend = MongoEngineBackend() user = backend.authenticate(username=request.POST['username'], password=request.POST['password']) # print user.get_user() django_login(request, user) return redirect('list') else: # except DoesNotExist: # return HttpResponse('user does not exist') # else: # form = AuthenticationForm() # return render_to_response('account/login.html', {'form': form}, context_instance=RequestContext(request))
def login(request): var = {} if request.method == 'POST': form = AuthenticationForm(request.POST) if form.is_valid(): user = authenticate(user_name=request.POST['user_name'], password=request.POST['password']) if user is not None: if user.is_active: django_login(request, user) return redirect('/') else: form = AuthenticationForm() var['form'] = form return render(request, 'login.html', var)
def authenticate(project_id=None): """Authentication form""" form = AuthenticationForm() if not form.id.data and request.args.get('project_id'): form.id.data = request.args['project_id'] project_id = form.id.data project = Project.query.get(project_id) create_project = False # We don't want to create the project by default if not project: # But if the user try to connect to an unexisting project, we will # propose him a link to the creation form. if request.method == "POST": form.validate() else: create_project = project_id else: # if credentials are already in session, redirect if project_id in session and project.password == session[project_id]: setattr(g, 'project', project) return redirect(url_for(".list_bills")) # else process the form if request.method == "POST": if form.validate(): if not form.password.data == project.password: msg = _("This private code is not the right one") form.errors['password'] = [msg] else: # maintain a list of visited projects if "projects" not in session: session["projects"] = [] # add the project on the top of the list session["projects"].insert(0, (project_id, project.name)) session[project_id] = form.password.data session.update() setattr(g, 'project', project) return redirect(url_for(".list_bills")) return render_template("authenticate.html", form=form, create_project=create_project)
def LoginUser(request): if request.method=='POST': username = request.POST['username'] password = request.POST['password'] user = authenticate(username=username, password=password) if user is not None: return render(request, 'login/main.html', {}) else: return render(request, 'login/start.html', {}) else: form = AuthenticationForm() return render(request, 'login/login.html', {'form':form})
def signup(): form = AuthenticationForm() if request.method == 'GET': return render_template('signup.html', form=form) user = User(username=request.form['username'], password=request.form['password']) db.session.add(user) db.session.commit() login_user(user) return redirect(url_for('dashboard'))
def index(): form = AuthenticationForm() if request.method == 'GET': return render_template('index.html', form=form) username = request.form['username'] password = request.form['password'] registered_user = User.query.filter_by(username=username, password=password).first() if registered_user is None: flash('Username or Password is invalid', 'error') return redirect(url_for('index')) login_user(registered_user) return redirect(url_for('dashboard'))
def login(request): form = AuthenticationForm(data=request.POST or None) if request.POST: if form.is_valid(): user = form.get_user() pastes = Paste.get_for_session(request.session) num_affected = pastes.update(author=user) auth_login(request, user) if num_affected: messages.success(request, '{0} note{1} was successfully transferred to your account.'.format( num_affected, pluralize(num_affected) )) return redirect('paste_create') return TemplateResponse(request, 'application/login.html', { 'form': form })
def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME): "Displays the login form and handles the login action." redirect_to = request.REQUEST.get(redirect_field_name, '') if request.method == "POST": form = AuthenticationForm(request=request, 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 or ' ' in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL #from django.contrib.auth import login from auth import login login(request, form.get_user()) if request.session.test_cookie_worked(): request.session.delete_test_cookie() return HttpResponseRedirect(redirect_to) else: form = AuthenticationForm(request) request.session.set_test_cookie() if Site._meta.installed: current_site = Site.objects.get_current() else: current_site = RequestSite(request) from django.template import loader from bidding.views import my_render t = loader.get_template(template_name) c = RequestContext(request, { 'form': form, redirect_field_name: redirect_to, 'site': current_site, 'site_name': current_site.name, }) block_login = (t.render(c)) return HttpResponse(my_render(request, {'form_login': block_login, 'page_title': 'Login', 'page_description': 'Login' }, 'login'))
def authenticate(project_id=None): """Authentication form""" form = AuthenticationForm() if not form.id.data and request.args.get('project_id'): form.id.data = request.args['project_id'] project_id = form.id.data if project_id is None: #User doesn't provide project identifier, return to authenticate form msg = _("You need to enter a project identifier") form.errors["id"] = [msg] return render_template("authenticate.html", form=form) else: project = Project.query.get(project_id) create_project = False # We don't want to create the project by default if not project: # But if the user try to connect to an unexisting project, we will # propose him a link to the creation form. if request.method == "POST": form.validate() else: create_project = project_id else: # if credentials are already in session, redirect if project_id in session and project.password == session[project_id]: setattr(g, 'project', project) return redirect(url_for(".list_bills")) # else process the form if request.method == "POST": if form.validate(): if not form.password.data == project.password: msg = _("This private code is not the right one") form.errors['password'] = [msg] else: # maintain a list of visited projects if "projects" not in session: session["projects"] = [] # add the project on the top of the list session["projects"].insert(0, (project_id, project.name)) session[project_id] = form.password.data session.update() setattr(g, 'project', project) return redirect(url_for(".list_bills")) return render_template("authenticate.html", form=form, create_project=create_project)
def login(request, template_name='registration/login.html', redirect_field_name=REDIRECT_FIELD_NAME): "Displays the login form and handles the login action." redirect_to = request.REQUEST.get(redirect_field_name, '') if request.method == "POST": form = AuthenticationForm(request=request, 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 or ' ' in redirect_to: redirect_to = settings.LOGIN_REDIRECT_URL #from django.contrib.auth import login from auth import login login(request, form.get_user()) if request.session.test_cookie_worked(): request.session.delete_test_cookie() return HttpResponseRedirect(redirect_to) else: form = AuthenticationForm(request) request.session.set_test_cookie() if Site._meta.installed: current_site = Site.objects.get_current() else: current_site = RequestSite(request) from django.template import loader from bidding.views import my_render t = loader.get_template(template_name) c = RequestContext( request, { 'form': form, redirect_field_name: redirect_to, 'site': current_site, 'site_name': current_site.name, }) block_login = (t.render(c)) return HttpResponse( my_render( request, { 'form_login': block_login, 'page_title': 'Login', 'page_description': 'Login' }, 'login'))
def accounts(request): login_form = AuthenticationForm() return {'login_form': login_form}
def authorize(request): result = get_environment(request) result.update(csrf(request)) # 验证是否为登录表单 # TODO 当系统有初始化、登录以外的入口时,此处需要改进(SunFulong@2014-1-7) form = AuthenticationForm(request.POST) # 非登录表单,返回登录画面 if not form.is_valid(): # 验证应用端身份 form, client = verify_client(request.REQUEST) if issubclass(form.__class__, HttpResponse): return form result.update({'name': client.name}) request.session.set_expiry(0) request.session.update(form.cleaned_data) return render_to_response('oauth/authorize.html', result) # 是登录表单,进行相关验证 else: action = form.cleaned_data['action'] username = form.cleaned_data['username'] domain = form.cleaned_data['domain'] password = form.cleaned_data['password'] # 验证应用端身份 form, client = verify_client(request.REQUEST) if issubclass(form.__class__, HttpResponse): return form result.update({'name': client.name}) response_type = form.cleaned_data['response_type'] client_id = form.cleaned_data['client_id'] redirect_uri = request.session['redirect_uri'] scope = request.session['scope'] state = request.session['state'] # 处理code请求 if response_type == 'code': # 处理登录以外的请求 if not action.lower() == 'login'.lower(): return callback_client(redirect_uri + '?error=access_denied', state) # 验证表单合法性 if not username or not domain or not password: result.update({'error': '请输入邮箱地址及密码'}) return render_to_response('oauth/authorize.html', result) # 验证用户合法性 user = authenticate(email=username + '@' + domain, password=password) if not user: result.update({'error': '邮箱地址或密码错误,请重新输入'}) return render_to_response('oauth/authorize.html', result) # 生成code code = AuthorizationCode(client=client, user=user, redirect_uri=redirect_uri, expire_time=datetime.datetime.now() + datetime.timedelta(minutes=10)) code.save() return callback_client( redirect_uri + '?code=' + urlsafe_base64_encode(code.code.bytes), state) else: return callback_client( redirect_uri + '?error=unsupported_response_type', state), None
def authorize(request): result = get_environment(request) result.update(csrf(request)) # 验证是否为登录表单 # TODO 当系统有初始化、登录以外的入口时,此处需要改进(SunFulong@2014-1-7) form = AuthenticationForm(request.POST) # 非登录表单,返回登录画面 if not form.is_valid(): # 验证应用端身份 form, client = verify_client(request.REQUEST) if issubclass(form.__class__, HttpResponse): return form result.update({'name': client.name}) request.session.set_expiry(0) request.session.update(form.cleaned_data) return render_to_response('oauth/authorize.html', result) # 是登录表单,进行相关验证 else: action = form.cleaned_data['action'] username = form.cleaned_data['username'] domain = form.cleaned_data['domain'] password = form.cleaned_data['password'] # 验证应用端身份 form, client = verify_client(request.REQUEST) if issubclass(form.__class__, HttpResponse): return form result.update({'name': client.name}) response_type = form.cleaned_data['response_type'] client_id = form.cleaned_data['client_id'] redirect_uri = request.session['redirect_uri'] scope = request.session['scope'] state = request.session['state'] # 处理code请求 if response_type == 'code': # 处理登录以外的请求 if not action.lower() == 'login'.lower(): return callback_client(redirect_uri + '?error=access_denied', state) # 验证表单合法性 if not username or not domain or not password: result.update({'error': '请输入邮箱地址及密码'}) return render_to_response('oauth/authorize.html', result) # 验证用户合法性 user = authenticate(email=username + '@' + domain, password=password) if not user: result.update({'error': '邮箱地址或密码错误,请重新输入'}) return render_to_response('oauth/authorize.html', result) # 生成code code = AuthorizationCode(client=client, user=user, redirect_uri=redirect_uri, expire_time=datetime.datetime.now() + datetime.timedelta(minutes=10)) code.save() return callback_client(redirect_uri + '?code=' + urlsafe_base64_encode(code.code.bytes), state) else: return callback_client(redirect_uri + '?error=unsupported_response_type', state), None