Commit c83e06f8 authored by Mario Manno's avatar Mario Manno

remove call_for_papers from users model, remove after_create

parent 5bc0686f
......@@ -8,7 +8,10 @@ class Cfp::ConfirmationsController < ApplicationController
def create
@user = User.find_by_email(params[:user][:email])
if @user and @user.send_confirmation_instructions
@conference = Conference.find_by_acronym(params[:conference_acronym])
# re-send
if @user and @user.send_confirmation_instructions(@conference)
redirect_to new_cfp_session_path, notice: t(:"cfp.confirmation_instructions_sent")
else
redirect_to new_cfp_user_confirmation_path, flash: {error: t(:"cfp.error_sending_confirmation_instructions")}
......
......@@ -12,7 +12,7 @@ class Cfp::PasswordsController < ApplicationController
def create
@user = User.find_by_email(params[:user][:email])
if @user and @user.send_password_reset_instructions(@conference.call_for_papers)
if @user and @user.send_password_reset_instructions(@conference)
redirect_to new_cfp_session_path, notice: t(:"cfp.sent_password_reset_instructions")
else
flash[:alert] = t(:"cfp.problem_sending_password_reset_instructions")
......
......@@ -10,10 +10,11 @@ class Cfp::UsersController < ApplicationController
def create
@user = User.new(user_params)
@user.call_for_papers = @conference.call_for_papers
@user.person = Person.new(email: @user.email, public_name: @user.email)
@conference = Conference.find_by_acronym(params[:conference_acronym])
if @user.save
@user.send_confirmation_instructions(@conference)
redirect_to new_cfp_session_path, notice: t(:"cfp.signed_up")
else
render action: "new"
......
......@@ -47,7 +47,6 @@ class UsersController < ApplicationController
@user.role = 'submitter'
end
@user.person = @person
@user.call_for_papers = @conference.call_for_papers
@user.skip_confirmation!
respond_to do |format|
......
......@@ -2,13 +2,15 @@ class UserMailer < ActionMailer::Base
default from: Settings['from_email']
def password_reset_instructions(user)
def password_reset_instructions(user, conference)
@user = user
@conference = conference
mail to: @user.email, subject: I18n.t("mailers.user_mailer.password_reset_instructions")
end
def confirmation_instructions(user)
def confirmation_instructions(user, conference=nil)
@user = user
@conference = conference
mail to: @user.email, subject: I18n.t("mailers.user_mailer.confirmation_instructions")
end
......
......@@ -5,8 +5,6 @@ class User < ActiveRecord::Base
USER_ROLES = %w{submitter crew}
EMAIL_REGEXP = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/
# TODO: users should have several cfps, refactor into has_many relation
belongs_to :call_for_papers
has_many :conference_users, dependent: :destroy
has_one :person
......@@ -18,7 +16,6 @@ class User < ActiveRecord::Base
after_initialize :check_default_values
before_create :generate_confirmation_token, unless: :confirmed_at
after_create :send_confirmation_instructions, unless: :confirmed_at
validates_presence_of :person
validates_presence_of :email
......@@ -75,27 +72,16 @@ class User < ActiveRecord::Base
user
end
def send_confirmation_instructions
def send_confirmation_instructions(conference=nil)
return false if confirmed_at
generate_confirmation_token! unless self.confirmation_token
UserMailer.confirmation_instructions(self).deliver_now
UserMailer.confirmation_instructions(self, conference).deliver_now
end
# update users call for papers and sends mail
def send_password_reset_instructions(call_for_papers = nil)
if call_for_papers
self.call_for_papers = call_for_papers
end
def send_password_reset_instructions(conference)
generate_password_reset_token!
UserMailer.password_reset_instructions(self).deliver_now
end
def try_call_for_papers
if self.call_for_papers
self.call_for_papers
else
CallForPapers.last
end
UserMailer.password_reset_instructions(self, conference).deliver_now
end
def reset_password(params)
......
......@@ -2,8 +2,8 @@ Willkommen <%= @user.email %>!
Sie können Ihren Account durch folgenden Link bestätigen:
<% if @user.call_for_papers.present? %>
<%= cfp_user_confirmation_url(:locale => I18n.locale, :confirmation_token => @user.confirmation_token, :conference_acronym => @user.call_for_papers.conference.acronym) %>
<% if @conference %>
<%= cfp_user_confirmation_url(:locale => I18n.locale, :confirmation_token => @user.confirmation_token, :conference_acronym => @conference.acronym) %>
<% else %>
<%= cfp_user_confirmation_url(:locale => I18n.locale, :confirmation_token => @user.confirmation_token, :conference_acronym => Conference.current.acronym) %>
<% end %>
......@@ -2,8 +2,8 @@ Welcome <%= @user.email %>!
You can confirm your account through the link below:
<% if @user.call_for_papers.present? %>
<%= cfp_user_confirmation_url(:locale => I18n.locale, :confirmation_token => @user.confirmation_token, :conference_acronym => @user.call_for_papers.conference.acronym) %>
<% if @conference %>
<%= cfp_user_confirmation_url(:locale => I18n.locale, :confirmation_token => @user.confirmation_token, :conference_acronym => @conference.acronym) %>
<% else %>
<%= cfp_user_confirmation_url(:locale => I18n.locale, :confirmation_token => @user.confirmation_token, :conference_acronym => Conference.current.acronym) %>
<% end %>
......@@ -2,9 +2,9 @@ Hallo <%= @user.email %>!
Jemand hat einen Link angefordert, um Ihr Passwort zu ändern:
<%= edit_cfp_user_password_url(locale: I18n.locale, reset_password_token: @user.reset_password_token, conference_acronym: @user.try_call_for_papers.conference.acronym) %>
<%= edit_cfp_user_password_url(locale: I18n.locale, reset_password_token: @user.reset_password_token, conference_acronym: @conference.acronym) %>
Falls Sie das nicht angefordert haben, ignorieren sie diese
Mail bitte einfach.
Das Passwort wird nicht geändert bis Sie den o.g. Link
Das Passwort wird nicht geändert bis Sie den o.g. Link
benutzen, um ein neues zu setzen.
Hello <%= @user.email %>!
Someone has requested a link to change your password, and you
Someone has requested a link to change your password, and you
can do this through the link below.
<%= edit_cfp_user_password_url(locale: I18n.locale, reset_password_token: @user.reset_password_token, conference_acronym: @user.try_call_for_papers.conference.acronym) %>
<%= edit_cfp_user_password_url(locale: I18n.locale, reset_password_token: @user.reset_password_token, conference_acronym: @conference.acronym) %>
If you didn't request this, please ignore this email.
Your password won't change until you access the link above
......
class RemoveCfpFromUser < ActiveRecord::Migration
def change
remove_column :users, :call_for_papers_id
end
end
This diff is collapsed.
require 'test_helper'
class Cfp::ConfirmationsControllerTest < ActionController::TestCase
setup do
@call_for_papers = FactoryGirl.create(:call_for_papers)
@conference = @call_for_papers.conference
......@@ -13,7 +13,7 @@ class Cfp::ConfirmationsControllerTest < ActionController::TestCase
end
test "resends confirmation instructions" do
user = FactoryGirl.create(:user, confirmed_at: nil, call_for_papers: @call_for_papers)
user = FactoryGirl.create(:user, confirmed_at: nil)
assert_difference 'ActionMailer::Base.deliveries.size' do
post :create, conference_acronym: @conference.acronym, user: {email: user.email}
end
......@@ -21,8 +21,8 @@ class Cfp::ConfirmationsControllerTest < ActionController::TestCase
end
test "performs confirmation" do
user = FactoryGirl.create(:user, confirmed_at: nil, call_for_papers: @call_for_papers)
get :show, conference_acronym: @conference.acronym, confirmation_token: user.confirmation_token
user = FactoryGirl.create(:user, confirmed_at: nil)
get :show, conference_acronym: @conference.acronym, confirmation_token: user.confirmation_token
assert_response :redirect
assert_not_nil assigns(:current_user)
user.reload
......
......@@ -24,14 +24,14 @@ class Cfp::PasswordsControllerTest < ActionController::TestCase
test "displays password reset form" do
user = FactoryGirl.create(:user)
user.send_password_reset_instructions(@call_for_papers)
user.send_password_reset_instructions(@call_for_papers.conference)
get :edit, conference_acronym: @conference.acronym, reset_password_token: user.reset_password_token
assert_response :success
end
test "allows setting a new password" do
user = FactoryGirl.create(:user)
user.send_password_reset_instructions(@call_for_papers)
user.send_password_reset_instructions(@call_for_papers.conference)
before_digest = user.password_digest
put :update, conference_acronym: @conference.acronym, user: {reset_password_token: user.reset_password_token, password: "123frab", password_confirmation: "123frab"}
assert_response :redirect
......
......@@ -18,12 +18,11 @@ class Cfp::UsersControllerTest < ActionController::TestCase
end
assert_response :redirect
assert_not_nil assigns(:user)
assert_equal @call_for_papers.id, assigns(:user).call_for_papers_id
assert_not_nil assigns(:user).confirmation_token
end
test "shows password editing form" do
user = login_as(:submitter)
login_as(:submitter)
get :edit, conference_acronym: @conference.acronym
assert_response :success
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment