1错误禁止此用户保存:重置密码令牌无效

时间:2017-05-04 23:52:11

标签: ruby-on-rails ruby devise

我目前正在做一个使用设计宝石的项目..注册,确认电子邮件以及登录运行良好。但是在忘记密码的情况下,我遇到了这个错误..我试图通过将“更改我的密码”文本悬停在http://localhost:3000/rails/mailers/user_mailer/reset_password_instructions中来检查我收到的令牌与我的表格相同

注意:我按照我搜索的有关reset_password文件的说明

重置密码说明

const string insertQuery = "INSERT INTO Renters (" +
                           "  renter_type," +
                           "  first_name," +
                           "  second_name," +
                           "  family_name," +
                           "  EGN," +
                           "  Contact_number," +
                           "  family_status," +
                           "  day_of_accommodation," +
                           "  speciality," +
                           "  course," +
                           "  faculty_number," +
                           "  room_id" +
                           ") VALUES (" +
                           "  @RenterType," +
                           "  @FirstNamе," +
                           "  @MiddleName," +
                           "  @LastNamе," +
                           "  @EGN," +
                           "  @ContactNumber," +
                           "  @FamilyStatus," +
                           "  @DayOfAccommodation," +
                           "  @Specialty," +
                           "  @CurrCourse," +
                           "  @FacultyNumber," +
                           "  (select room_id from rooms where room_number = @RoomNumber)" +
                           ");";
using (SqlConnection cn = new SqlConnection("mySQLdatabaseConnection"))
{
    using (SqlCommand cmd = new SqlCommand())
    {
        cmd.Connection = cn;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = insertQuery;
        cmd.Parameters.AddWithValue("@RenterType", newrenter.RenterType);
        cmd.Parameters.AddWithValue("@FirstName", newrenter.FirstName);
        cmd.Parameters.AddWithValue("@MiddleName", newrenter.MiddleName);
        cmd.Parameters.AddWithValue("@LastName", newrenter.LastName);
        cmd.Parameters.AddWithValue("@EGN", newrenter.EGN);
        cmd.Parameters.AddWithValue("@ContactNumber", newrenter.ContactNumber);
        cmd.Parameters.AddWithValue("@FamilyStatus", newrenter.FamilyStatus);
        cmd.Parameters.AddWithValue("@DayOfAccommodation", newrenter.DayOfAccommodation);
        cmd.Parameters.AddWithValue("@Specialty", newrenter.student.Specialty);
        cmd.Parameters.AddWithValue("@CurrCourse", newrenter.student.CurrCourse);
        cmd.Parameters.AddWithValue("@FacultyNumber", newrenter.student.FacultyNumber);
        cmd.Parameters.AddWithValue("@RoomNumber", room.RoomNumber);

        try
        {
            cn.Open();
            int recordsAffected = cmd.ExecuteNonQuery();
        }
        catch (SqlException err)
        {
            MessageBox.Show(err.Message);
        }
        finally
        {
            cn.Close();
        }
    }
}

用户邮件程序预览

<p>Hello <%= @resource.email %>!</p>

<p>Someone has requested a link to change your password. You can do this through the link below.</p>

<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>

<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

问题:如何解决此类错误?

1 个答案:

答案 0 :(得分:0)

在user_mailer_preview的文件和reset_password_instructions的方法中尝试添加此

def reset_password_instructions 
        query = "SELECT * FROM users 
            WHERE reset_password_token IS NOT NULL 
            ORDER by reset_password_sent_at DESC"
        user = User.find_by_sql(query).first
        token = user.send(:set_reset_password_token)
        Devise::Mailer.reset_password_instructions(user, token)

    end