2013-03-19 17 views
1

我已经有this solution针对Omniauth & Github实现并正常工作,但有时在过去几个月内它停止工作。Rails Omniauth-github(422)您要更改的内容已被拒绝

我在尝试登录时遇到的错误是:(422)您希望更改被拒绝。

具体表现在Heroku的日志我看到:

ActiveRecord::RecordInvalid (Validation failed: Password can't be blank): 
app/models/user.rb:18:in `create_from_omniauth' 
app/models/user.rb:14:in `from_omniauth' 
app/controllers/sessions_controller.rb:4:in `create' 

我需要当我创建用户保存凭据?

我的用户模型:

def self.from_omniauth(auth) 
    where(auth.slice("provider", "uid")).first || create_from_omniauth(auth) 
end 

def self.create_from_omniauth(auth) 
    create! do |user| 
    user.provider = auth["provider"] 
    user.uid = auth["uid"] 
    user.name = auth["info"]["nickname"] 
    user.email = auth["info"]["email"] 
    user.image = auth["info"]["image"] 
end 
end 

会话控制器:

class SessionsController < ApplicationController 

def create 
    user = User.from_omniauth(env["omniauth.auth"]) 
    session[:user_id] = user.id 
    redirect_to root_url, notice: "Signed in!" 
end 

def destroy 
    session[:user_id] = nil 
    redirect_to root_url, notice: "Signed out!" 
end 
end 

回答

0

它看起来像你要么验证密码字段的存在在你的User模型或使用has_secure_password,这确实是下封面。

如果你自己做了验证,你可以在验证中添加一个像:if => :password_changed?这样的子句。

如果您使用的是has_secure_password,它取决于您使用的Rails版本。任何版本的thesetwo更改(我相信只有Rails 4)支持通过validations: false选项has_secure_password。否则,并不是一个很好的解决方案,除了可能在创建用户时设置一个随机虚拟密码,然后让他们立即进行更改。

1

Facebook的omniauth错误“您要更改的内容已被拒绝” 可能因您在模型中设置的验证而出现。我不得不重构我的验证用户有一个唯一的电子邮件,这是不工作时,用户会尝试使用相同的电子邮件的Facebook登录。

看看你的日志。 heroku logs -t

0

我有这个问题,当我gitlab服务器上的时间是同步的,我重新启动NTPD,其修正时间在服务器上的问题得到解决