def admin_auth(user_id): if get_admin_count() > 0: admin_redirect() form = AuthForm() remove = request.args.get('remove') if not User.query.get(user_id): return abort(404) if form.validate_on_submit(): if remove != 'True': return redirect_after_verification( user_id=user_id, password=form.code.data, auth_func='admin_auth', redirect_to='verification.handle_new_admin', salt='make-auth') else: return redirect_after_verification( user_id=user_id, password=form.code.data, auth_func='admin_auth', redirect_to='verification.handle_admin_removal', salt='remove-auth') return render_template('admin-form.html', form=form, authorization=True, user_id=user_id, category='admin', remove=remove)
def sign_in(): form = AuthForm(request.form) if request.method == "POST" and form.validate(): auth = mongo_init().auth user = auth.find_one({"username": form.data.get("username")}) if not user: flash(u"Sorry, user {username} not found".format(**form.data), "alert-error") return redirect(url_for("sign_in")) username, password = form.data.get("username"), \ form.data.get("password") md5 = hashlib.md5() md5.update(password) if user["password"] == md5.hexdigest(): session["username"] = user["username"] flash("You're successfully authorized", "alert-success") return redirect(url_for("registration_deck")) return redirect(url_for("registration_deck")) return render_template("auth.html", form=form)
def auth_edit(id=None): # 权限修改 form = AuthForm() form.submit.label.text = u'修改' auth = Auth.query.filter_by(id=id).first_or_404() is_flag = True if request.method == 'GET': form.name.data = auth.name form.url.data = auth.url form.html_id.data = auth.html_id if form.validate_on_submit(): if auth.name != form.name.data and Auth.query.filter_by( name=form.name.data).first(): is_flag = False flash(u'您输入的权限已存在', 'err') if auth.url != form.url.data and Auth.query.filter_by( url=form.url.data).first(): is_flag = False flash(u'您输入的路由已存在', 'err') if is_flag == False: return render_template('admin/auth_edit.html', form=form) auth.name = form.name.data auth.url = form.url.data auth.html_id = form.html_id.data db.session.add(auth) oplog = Oplog(user_id=session['user_id'], ip=request.remote_addr, reason=u'修改权限:%s' % form.name.data) db.session.add(oplog) db.session.commit() flash(u'权限修改成功', 'ok') return redirect(url_for('admin.auth_list')) return render_template('admin/auth_edit.html', form=form)
def auth_add(): # 权限添加 form = AuthForm() is_flag = True if form.validate_on_submit(): if Auth.query.filter_by(name=form.name.data).first(): is_flag = False flash(u'您输入的权限已存在', 'err') if Auth.query.filter_by(url=form.url.data).first(): is_flag = False flash(u'您输入的路由已存在', 'err') if is_flag == False: return render_template('admin/auth_add.html', form=form) auth = Auth(name=form.name.data, level=1, url=form.url.data, html_id=form.html_id.data) oplog = Oplog(user_id=session['user_id'], ip=request.remote_addr, reason=u'添加权限:%s' % form.name.data) objects = [auth, oplog] db.session.add_all(objects) db.session.commit() flash(u'权限添加成功', 'ok') return redirect(url_for('admin.auth_add')) return render_template('admin/auth_add.html', form=form)
def login(request): if not request.user.is_authenticated(): form = AuthForm(request.POST or None) if request.POST and form.is_valid(): user = form.login(request) if user: auth.login(request, user) user_param = User_Options.objects.create(user=user) user_param.save() return HttpResponseRedirect("/") # Redirect to a success page. return render(request, 'index.html', {'login_form': form}) else: auth.logout(request) form = AuthForm() return render(request, 'index.html', {'login_form': form})
def regist_user(request): if request.method == 'GET': dc = { 'login_url': reverse('login'), 'heads': json.dumps(form_to_head(AuthForm())) } return render(request, 'authuser/regist.html', context=dc) elif request.method == 'POST': return jsonpost(request, get_globe())
def login(isReg): _form = RegForm(request.form) if isReg else AuthForm(request.form) if request.method == 'POST': return registration(_form) if isReg else autorization(_form) return render_template('login.html', isReg=isReg, btnRegOff=not isReg, form=_form)
def auth(): form = AuthForm() if not form.validate_on_submit(): return send_json_response(message=form.errors, status_code=400) if not is_valid_api_key(api_key=form.api_key.data): return send_json_response(message={'message': 'Ошибка аутентификации'}, status_code=401)
def login(): form = AuthForm(request.form) if request.method == 'POST': found_user = db.session.query(User).filter_by( email=form.data['email']).first() if found_user: authenticated_user = bcrypt.check_password_hash( found_user.password, form.data['password']) if authenticated_user: login_user(found_user) return redirect(url_for('wrap.welcome')) return render_template('login.html', form=form)
def result(request): if request.method == 'POST': form = AuthForm(request.POST, request.FILES) if form.is_valid(): label = int(request.POST['pick']) model = ModuleML() val, pred, conf = model.predict(request.FILES['audio'], label) if pred == label: st = "Match" else: st = "No Match" person_true = SpeakerModel.objects.get(label= pred) else: list = SpeakerModel.objects.all() auth = AuthForm() return render(request, 'authenticate.html', {'form': auth, 'items': list}) else: list = SpeakerModel.objects.all() auth = AuthForm() return render(request, 'authenticate.html', {'form': auth, 'items': list}) return HttpResponse(st + '\n Confidence Score:\t'+ str(conf))
def login(): if session.get("user_id"): return redirect("/account/") else: form = AuthForm() if request.method == "POST": user = db.session.query(User).filter( User.mail == form.mail.data).first() if user.mail and user.password_valid(form.password.data): session["user_id"] = user.id session["is_auth"] = True return redirect("/account/") return render_template("auth.html", form=form)
def log_in(): if session.get("user_id"): return redirect("/account/") form = AuthForm() if request.method == "POST": user = User.query.filter_by(mail=form.mail.data).first() if user.mail and user.password_valid(form.password.data): session["user_id"] = { "id": user.id, "mail": user.mail, "role": user.role, } return redirect("/account/") return render_template("auth.html", form=form)
def authorization(user_id): form = AuthForm() user = User.query.get(user_id) if not user: return abort(400) if form.validate_on_submit(): return redirect_after_verification( user_id=user_id, auth_func='authorization', redirect_to='user_operations.delete_user', salt='delete-auth', password=form.code.data) return render_template('delete.html', form=form, authorization=True, user_id=user_id)
def index(): form = AuthForm() session['user'] = False if form.button.data: user = User(form.login.data, form.passwd.data) if user.auth(): session['user'] = { 'login': user.name, 'passwd': user.passwd, } flash(u'Вход выполнен') return redirect('/myfiles') else: session['user'] = False flash(u'Пароль или логин неверен') return render_template('index.html', form=form)
def auth_add(): form = AuthForm() if form.validate_on_submit(): data = form.data auth_num = Auth.query.filter_by(name=data["auth_name"]).count() if auth_num == 1: flash("权限名称已经存在!", "err") return redirect(url_for("admin.auth_add")) auth_url_num = Auth.query.filter_by(url=data["auth_url"]).count() if auth_url_num == 1: flash("权限地址已经存在!", "err") return redirect(url_for("admin.auth_add")) auth = Auth(name=data["auth_name"], url=data["auth_url"]) db.session.add(auth) db.session.commit() flash("添加权限成功!", "ok") #return redirect(url_for("admin.auth_add")) return redirect(url_for("admin.auth_list", page=1)) return render_template("admin/auth_add.html", form=form)
def signup(): #получаем данные форм с клиента form = AuthForm(request.form) print(form.data) if request.method == 'POST': #and form.validate(): user = db.session.query(User).filter_by( email=form.data['email']).first() try: print('hello') new_user = User(first_name=form.data['first_name'], last_name=form.data['last_name'], email=form.data['email'], password=form.data['password']) db.session.add(new_user) db.session.commit() except IntegrityError as e: db.session.rollback() return render_template('signup.html', error="Юзер с таким email уже существует") return redirect(url_for('wrap.login')) return render_template('signup.html')
def index(request): if request.user.is_authenticated(): return HttpResponseRedirect('/channels') if request.method == 'POST': form = AuthForm(request.POST) if not form.is_valid(): return render(request, "auth.html", {'form': form}) user = auth.authenticate(username=request.POST.get('login', ''), password=request.POST.get('password', '')) if user and user.is_active: auth.login(request, user) return HttpResponseRedirect('/channels') else: error = 'Не верное имя пользователя или пароль' return render(request, "auth.html", { 'form': form, 'deny_auth': error }) return render(request, "auth.html")
def auth_edit(id=None): form = AuthForm() auth = Auth.query.get_or_404(id) if form.validate_on_submit(): data = form.data auth_num = Auth.query.filter_by(name=data["auth_name"]).count() print auth.name print data["auth_name"] print auth_num if auth.name != data["auth_name"] and auth_num == 1: flash("权限名称已经存在!", "err") return redirect(url_for("admin.auth_edit", id=id)) auth_url_num = Auth.query.filter_by(url=data["auth_url"]).count() if auth.url != data["auth_url"] and auth_url_num == 1: flash("权限地址已经存在!", "err") return redirect(url_for("admin.auth_edit", id=id)) auth.name = data["auth_name"] auth.url = data["auth_url"] db.session.add(auth) db.session.commit() flash("修改权限成功!", "ok") #return redirect(url_for("admin.auth_edit",id=id)) return redirect(url_for("admin.auth_list", page=1)) return render_template("admin/auth_edit.html", form=form, auth=auth)
def authenticate(request): list = SpeakerModel.objects.all() auth = AuthForm() return render(request, 'authenticate.html', {'form': auth , 'items': list})
def index(request): saved = False error_login = False if request.method == 'POST': userForm = UserForm(data=request.POST) auth = AuthForm(data=request.POST) searchForm = SearchForm(data=request.POST) if userForm.is_valid(): userForm.save() saved = True if auth.is_valid(): user = authenticate(username=auth.cleaned_data['username'], password=auth.cleaned_data['password']) if user is not None: if user.is_active: login(request, user) else: error_login = True if searchForm.is_valid(): if searchForm.cleaned_data['category'] == u'Questão': return HttpResponseRedirect( '/qb/search/question/' + searchForm.cleaned_data['search_bar']) elif searchForm.cleaned_data['category'] == 'Curso': return HttpResponseRedirect( '/qb/search/course/' + searchForm.cleaned_data['search_bar']) elif searchForm.cleaned_data['category'] == 'Disciplina': return HttpResponseRedirect( '/qb/search/theme/' + searchForm.cleaned_data['search_bar']) elif searchForm.cleaned_data['category'] == 'Assunto': return HttpResponseRedirect( '/qb/search/subjects/' + searchForm.cleaned_data['search_bar']) else: userForm = UserForm() auth = AuthForm() searchForm = SearchForm() recent_questions = Question.objects.filter( status=True).order_by('-datepost')[:10] viewed_questions = Question.objects.filter( status=True).order_by('-view')[:10] data = { 'userForm': userForm, 'authForm': auth, 'searchForm': searchForm, 'saved': saved, 'error_login': error_login, 'recent_questions': recent_questions, 'viewed_questions': viewed_questions } return render_to_response('problematic/index.html', data, context_instance=RequestContext(request))
def hello_world(): auth_form = AuthForm() return render_template('main.html', form=auth_form, user=current_user)