我正在尝试(再次)使用Rails 4,devise和omniauth设置身份验证.
我试着按照这篇文章中的例子:Rails 4,Devise,Omniauth(有多个提供者)
我安装了这些宝石:
gem 'devise'
gem 'omniauth-google-oauth2'
gem 'omniauth-facebook'
gem 'omniauth-twitter'
gem 'omniauth-linkedin-oauth2'
gem 'oauth2'
Run Code Online (Sandbox Code Playgroud)
我有一个用户模型和一个身份验证模型.
我有:
User.rb:
has_many :authentications
def disapprove
self.approved = false
end
def approve
self.approved = true
end
Run Code Online (Sandbox Code Playgroud)
SOCIALS = {facebook:'Facebook',google_oauth2:'Google',linkedin:'Linkedin'}
def self.from_omniauth(auth, current_user)
authentication = Authentication.where(:provider => auth.provider,
:uid => auth.uid.to_s,
:token => auth.credentials.token,
:secret => auth.credentials.secret).first_or_initialize
authentication.profile_page = auth.info.urls.first.last unless authentication.persisted?
if authentication.user.blank?
user = current_user.nil? ? User.where('email = ?', auth['info']['email']).first : current_user
if user.blank?
user = User.new
user.skip_confirmation!
user.password = …Run Code Online (Sandbox Code Playgroud) 我试图整理这篇文章,所以对新来者来说似乎并不长.它包括由以下答案中的其他人提出的建议所导致的错误.
我正在尝试用Rails 4创建一个应用程序.
我使用设计和omniauth.
我有用户和个人资料的模型.用户有一个配置文件和配置文件属于用户.
我的目标是将用户模型用于用户并未真正触摸的所有内容.我将配置文件模型用于用户确实维护的内容.
创建新用户时,我希望将用户重定向到他们的配置文件页面,该页面应该部分填充在用户模型中创建的详细信息.
我遇到了麻烦.
我有:
User.rb
has_one :profile
Run Code Online (Sandbox Code Playgroud)
Profile.rb
belongs_to :user
Run Code Online (Sandbox Code Playgroud)
Omniauth_callbacks_controller.rb
if @user.persisted?
sign_in_and_redirect_user(:user, authentication.user.profile)
set_flash_message(:notice, :success, kind: "#{provider}".capitalize) if is_navigational_format?
else
session["devise.#{provider}_data"] = env["omniauth.auth"]
redirect_to new_user_registration_url
end
Run Code Online (Sandbox Code Playgroud)
我也尝试过回调重定向:
sign_in_and_redirect @user, event: :authentication
Run Code Online (Sandbox Code Playgroud)
型材/ show.html.erb
<div class="container-fluid">
<div class="row">
<div class="col-xs 8 col-xs-offset-1">
<%= @profile.user.formal_name %>
<%= @profile.occupation %>
<%= @profile.qualification.awards %>
<%= @profile.overview %>
<%= @profile.research_interests %>
</div>
<div class="col-xs 3">
<div class="geobox">
<%= render 'addresses/location' %>
<%= @profile.working_languages %>
<%= @profile.external_profile %>
</div> …Run Code Online (Sandbox Code Playgroud) 我想在Rails 4中创建一个应用程序.
我正在使用简单的表单形式,并且刚刚尝试使用gem'inpendent-fields-rails'来隐藏或显示基于主要问题的表单字段的子集问题.
我卡住了.
我已将gems添加到我的gem文件中:
gem 'dependent-fields-rails'
gem 'underscore-rails'
Run Code Online (Sandbox Code Playgroud)
我已将我的application.js更新为:
//= require dependent-fields
//= require underscore
Run Code Online (Sandbox Code Playgroud)
我的表格有:
<%= f.simple_fields_for :project_date do |pdf| %>
<%= pdf.error_notification %>
<div class="form-inputs">
<%= pdf.input :student_project, as: :radio_buttons, :label => "Is this a project in which students may participate?", autofocus: true %>
<div class="js-dependent-fields" data-radio-name="project_date[student_project]" data-radio-value="true">
<%= pdf.input :course_project, as: :radio_buttons, :label => "Is this a project students complete for credit towards course assessment?" %>
<%= pdf.input :recurring_project, as: :radio_buttons, :label => "Is this project …Run Code Online (Sandbox Code Playgroud) 我正在尝试学习如何使用Rechart。该文档说您可以在图表元素上放置标签,并举例说明如何使用“名称”作为标签数据键。
我试图在我的图表中执行此操作,但是它不起作用。
如果我从字段中删除“标签”,则不会显示任何标签。如果我保留它,那么显示的唯一标签就是饼图楔形上的值。
我有一个标签,其数据键为“名称”(根据文档),但未在图表上呈现。
import React, { PureComponent } from 'react';
import {
ResponsiveContainer, PieChart, Pie, Legend, Label, LabelList
} from 'recharts';
const data = [
{ name: 'Group A', value: 400 }, { name: 'Group B', value: 300 },
{ name: 'Group C', value: 300 }, { name: 'Group D', value: 200 },
];
export default class Example extends PureComponent {
static jsfiddleUrl = '//jsfiddle.net/alidingling/6okmehja/';
render() {
return (
<div style={{ width: '100%', height: 300 }}>
<ResponsiveContainer>
<PieChart>
<Pie …Run Code Online (Sandbox Code Playgroud) 我正在尝试像标签面板一样使用 AntD 菜单侧边。
我想将组件放在内容中,以便在单击菜单项时内容面板呈现相关组件。
如何让这种结构将组件作为每个菜单项的内容?
import React from 'react';
import { compose } from 'recompose';
import { Divider, Layout, Card, Tabs, Typography, Menu, Breadcrumb, Icon } from 'antd';
import { PasswordForgetForm } from '../Auth/Password/Forgot';
const { Title } = Typography
const { TabPane } = Tabs;
const { Header, Content, Footer, Sider } = Layout;
const { SubMenu } = Menu;
class Dashboard extends React.Component {
state = {
collapsed: false,
};
onCollapse = collapsed => {
console.log(collapsed);
this.setState({ collapsed …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Rails和Simple Form创建一个带有country-select的应用程序.
我收到的错误是:
wrong number of arguments (4 for 0)
Run Code Online (Sandbox Code Playgroud)
我正在使用我找到的示例,在国家选择gem文档页面上的简单表单.我不明白出了什么问题.
在我的模型中,我有:
geocoded_by :address
after_validation :geocode, if: ->(obj){ @obj.address.present? and @obj.address_changed? }
def address
[city, state, participation_country].compact.join(', ')
end
Run Code Online (Sandbox Code Playgroud)
在我的表格中,我有:
<%= f.simple_fields_for :scope do |participants_s| %>
<%= participants_s.simple_fields_for :participant do |par| %>
<%= par.select :participation_country,
priority: ["AU", "GB", "NZ", "US"],
selected: :participation_country,
label: false,
prompt: "Select participation country" %>
Run Code Online (Sandbox Code Playgroud)
我使用时遇到同样的错误
<%= par.input :participation_country,
Run Code Online (Sandbox Code Playgroud)
在我看来,我有:
<%= @project.scope.participant.address %>
Run Code Online (Sandbox Code Playgroud)
在试图设置时,有谁能看到我做错了什么?错误消息表明有问题的行是:
<%= par.select :participation_country,
Run Code Online (Sandbox Code Playgroud)
除了建议的国家/地区代码,我无法计算4个,但我删除了其中一个尝试,但我得到了相同的错误.
当我尝试:
<%= par.country_select("participation_country", {:prompt => "Choose Country"})%>
Run Code Online (Sandbox Code Playgroud)
我得到了同样的错误:错误的参数数量(4表示0) …
我想弄清楚如何获取用户名,该用户名是存储在用户集合中的属性,该属性已与 firebase 身份验证模型创建的属性合并。
我可以访问 authUser - 这为我提供了 firebase 在身份验证工具中收集的有限字段,然后我试图从那里访问相关的用户集合(使用相同的 uid)。
我有一个反应上下文消费者:
import React from 'react';
const AuthUserContext = React.createContext(null);
export default AuthUserContext;
Run Code Online (Sandbox Code Playgroud)
然后在我的组件中,我尝试使用:
const Test = () => (
<AuthUserContext.Consumer>
{authUser => (
<div>
{authUser.email} // I can access the attributes in the authentication collection
{authUser.uid.user.name} //i cannot find a way to get the details in the related user collection document - where the uid on the collection is the same as the uid on the authentication table
</div>
)} …Run Code Online (Sandbox Code Playgroud) firebase reactjs firebase-authentication google-cloud-firestore
我有一个rails 4应用程序.
我正在尝试合并Bootstrap Tabs.
阅读bootstrap文档,它说这样做的一种方法不涉及任何js.我已经尝试了文档中的每种方法,但无法在我的应用程序中使用它们中的任何一种.
我目前的尝试是:
<ul class="nav nav-tabs nav-justified">
<li role="presentation" class="active"> <a href="#terms" aria-controls="terms" role="tab" data-toggle="tab">Terms</a></li>
<li role="presentation"> <a href="#privacy" aria-controls="privacy" role="tab" data-toggle="tab">Privacy</a></li>
<li role="presentation"> <a href="#licence" aria-controls="licence" role="tab" data-toggle="tab">Licence</a></li>
<li role="presentation"> <a href="#trust" aria-controls="trust" role="tab" data-toggle="tab">Trust</a></li>
<li role="presentation"> <a href="#reliance" aria-controls="reliance" role="tab" data-toggle="tab">Reliance</a></li>
<li role="presentation"> <a href="#pricing" aria-controls="pricing" role="tab" data-toggle="tab">Pricing</a></li>
</ul>
<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="terms"><%= render 'pages/legalpolicies/terms' %></div>
<div role="tabpanel" class="tab-pane" id="privacy"><%= render 'pages/legalpolicies/privacy' %></div>
<div role="tabpanel" class="tab-pane" id="licence"><%= render 'pages/legalpolicies/licence' %></div>
<div role="tabpanel" …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置与firebase身份验证的反应.
注册页面存在问题.当我注释掉注册页面时,我的本地页面呈现没有任何问题.当我取消注释此页面时,我收到一条错误消息:
npm.js:341 Uncaught TypeError: Cannot read property 'app' of undefined
at new hm (npm.js:341)
at Object.<anonymous> (RegisterPage.js:12)
at __webpack_require__ (bootstrap 5a6a0f74168ebcba0a5a:19)
at Object.defineProperty.value (AppRouter.js:10)
at __webpack_require__ (bootstrap 5a6a0f74168ebcba0a5a:19)
at Object.<anonymous> (app.js:7)
at __webpack_require__ (bootstrap 5a6a0f74168ebcba0a5a:19)
at Object.<anonymous> (bundle.js:50999)
at __webpack_require__ (bootstrap 5a6a0f74168ebcba0a5a:19)
at module.exports (bootstrap 5a6a0f74168ebcba0a5a:62)
Run Code Online (Sandbox Code Playgroud)
我试图在此代码沙箱中重新创建应用程序的最小部分:https://codesandbox.io/s/6w2r0267kk.但是,我在代码沙箱中收到错误消息:TypeError - 无法获取依赖项,请在几秒钟内重试:无法获取.每次出现此错误大约需要2个小时,现在重复3次.我不确定我在尝试使用该工具时是否做错了.
遇到与我相同的错误消息的其他人建议可能没有正确定义'this':Uncaught TypeError:无法读取未定义的属性'app'
对我来说,那个const是在第22行中分配的.进一步搜索这一查询行,人们注意到这是一个应该为ES6更新的ES5表达式 - 然后引导一条推理路径,表明这不是一个有用的在ES6中使用的方法.我不确定是否试图弄清楚是否是我的解决方案的一部分.
当我在注册页面上使用代码沙箱时,会指示从第78行开始的return语句中的语法错误,但我看不出有什么问题.
任何人都可以提供有关如何开始使用Firebase身份验证的示例(在用户注册时使用挂起标志).我自己并没有编写这段代码,并且很难在最好的时候理解基础知识,所以我想把它想象成一个学习练习,但如果它不是一个合理的基础,那么我也会欣赏那个建议.
我有一个React应用程序,该应用程序将Formik用于表单并将Cloud Firestore用于数据库。
我正在尝试将表单数据保存在Cloud Firestore中。我在控制台或React Inspector工具中没有任何错误,当我按Submit时,我在React Inspection工具中看到按钮变为禁用状态,然后再次启用,但是表单不会清除数据,并且数据确实无法发送到Cloud Firestore。
我的handleSubmit函数具有:
handleSubmit = (formState, { resetForm }) => {
// Now, you're getting form state here!
const payload = {
...formState,
fieldOfResearch: formState.fieldOfResearch.map(t => t.value),
preregisterPlatform: formState.preregisterPlatform.value,
resourceRequests: formState.resourceRequests.map(t => t.value),
resourceOffers: formState.resourceOffers.map(t => t.value),
ethicsIssue: formState.ethicsIssue.map(t => t.value),
disclosureStatus: formState.disclosureStatus.value,
createdAt: firebase.firestore.FieldValue.serverTimestamp()
}
console.log("formvalues", payload);
fsDB
.collection("project")
.add(payload)
.then(docRef => {
console.log("docRef>>>", docRef);
resetForm(initialValues);
})
.catch(error => {
console.error("Error adding document: ", error);
});
};
Run Code Online (Sandbox Code Playgroud)
我的提交按钮有:
<div className="form-group">
<Button
variant="outline-primary"
type="submit"
id="ProjectId" …Run Code Online (Sandbox Code Playgroud)