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 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 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 login(request): if request.method == 'POST': form = AuthForm(request.POST) if form.is_valid(): try: if request.is_ajax(): user = form.authenticate(request) if not user is None: accesstype = request.session['access_type'] auth.login(request, user) if accesstype == DEFUSER_ACCESS_TYPES[0][0]: return json_result({'success': 1, 'accesstype': accesstype}) else: ts = get_template('theme_select.html') themeselect = ts.render(RequestContext(request)) return json_result({'success': 1, 'accesstype': accesstype, 'themeselect': themeselect}) else: return json_form_error(form) else: return HttpResponseRedirect('/') except Exception, e: return HttpResponse(e) else: return json_form_error(form)
def connexion(request): """ Connexion page """ error=False if request.method == 'POST': # S'il s'agit d'une requête POST form = AuthForm(request.POST) # Nous reprenons les données if form.is_valid(): # Nous vérifions que les données envoyées sont valides # Ici nous pouvons traiter les données du formulaire username = form.cleaned_data['username'] password = form.cleaned_data['password'] user=authenticate(username=username,password=password) if user: login(request,user); return redirect(home) else: error=True else: # Si ce n'est pas du POST, c'est probablement une requête GET form = AuthForm() # Nous créons un formulaire vide return render(request, 'challenges/connexion.html',locals())
def login(request): args = {} args.update(csrf(request)) if request.POST: form = AuthForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] password = form.cleaned_data['password'] user = auth.authenticate(username=username, password=password) if user is not None: auth.login(request, user) if request.POST.get('next') != '': return redirect(request.POST.get('next')) else: return redirect('/players/') else: args['login_error'] = "User not found" args['form'] = AuthForm() return render(request, 'login.html', args) else: args['login_error'] = "error" args['form'] = AuthForm() return render(request, 'login.html', args) else: args['form'] = AuthForm() return render(request, 'login.html', args)
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 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 main_page(request): if request.method == 'POST': form = AuthForm(request.POST) if form.is_valid(): login(request, form.user) return HttpResponseRedirect(reverse('logged_in')) else: form = AuthForm() return direct_to_template(request, 'core/main_page.html', {'form': form, 'user': request.user})
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 signin(): if request.method == 'GET': form = AuthForm() return render_template('signin.html', error=False, form=form) else: auth_form = AuthForm(request.form) if auth_form.validate(): session['user'] = auth_form.email.data return redirect(url_for('index')) else: return render_template('signin.html', error=True, form=auth_form)
def authenticate_user(request): user = None if request.method == 'POST': form = AuthForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] passwd = form.cleaned_data['passwd'] try: user = authenticate(username=username, password=passwd) except Exception, err: form.error = err else: login(request, user) return HttpResponseRedirect('/')
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) 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 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 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_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 auth_user(request): error = None form = None if request.method == 'POST': form = AuthForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] passwd = form.cleaned_data['passwd'] user = authenticate(username=username, password=passwd) if user is not None: login(request, user) return HttpResponseRedirect("/") else: error = "Username/password is invalid!" if form == None: form = AuthForm() return render_to_response('auth.html', {'form':form, 'error':error})
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 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 auth_user(request): error = None form = None user = None if request.method == 'POST': form = AuthForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] passwd = form.cleaned_data['passwd'] user = authenticate(username=username, password=passwd) if user is not None: login(request, user) else: form.error = _(u"Ви ввели невірний логін або пароль!") else: form = AuthForm() user = get_current_user(request) return form, user
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 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 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 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 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 authenticate(request): list = SpeakerModel.objects.all() auth = AuthForm() return render(request, 'authenticate.html', {'form': auth , 'items': list})
def hello_world(): auth_form = AuthForm() return render_template('main.html', form=auth_form, user=current_user)
def login(): form = AuthForm(request.form) if request.method == 'POST' and form.validate(): login_user(form.get_account()) return render_template('accounts/login.html', form=form)
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))