Class: Signup::EmailController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/signup/email_controller.rb

Overview

メール認証情報サインアップ

Constant Summary collapse

EditFormClass =
EmailCredentialEditForm

Instance Method Summary collapse

Instance Method Details

#activateObject

POST /signup/email/activate FIXME: URLの見直し FIXME: 無効なアクティベーションキー、アクティベーション済みのキーはフィルタで弾く



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/controllers/signup/email_controller.rb', line 89

def activate
  @credential = EmailCredential.find_by_activation_token(params[:activation_token])

  unless @credential
    set_error("無効なアクティベーションキーです。")
    redirect_to(root_path)
    return
  end

  if @credential.activated?
    set_error("既に本登録されています。")
    redirect_to(root_path)
    return
  end

  @credential.activate!

  # TODO: テスト
  # MEMO: 即時性を優先し、非同期化しない
  ActivationMailer.(
    :recipients => @credential.email)

  redirect_to(:action => "activated")
end

#activatedObject

GET /signup/email/activated FIXME: URLの見直し FIXME: 無効なアクティベーションキー、アクティベーション済みのキーはフィルタで弾く



117
118
119
# File 'app/controllers/signup/email_controller.rb', line 117

def activated
  # nop
end

#activationObject

GET /signup/email/activation/:activation_token FIXME: URLの見直し FIXME: 無効なアクティベーションキー、アクティベーション済みのキーはフィルタで弾く



81
82
83
84
# File 'app/controllers/signup/email_controller.rb', line 81

def activation
  @credential = EmailCredential.find_by_activation_token(params[:activation_token])
  @activated  = @credential.try(:activated?)
end

#createObject

POST /signup/email/create



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'app/controllers/signup/email_controller.rb', line 45

def create
  @signup_form = EditFormClass.new(session[:signup_form])

  @user = MultiAuth.user_model_class.new
  @credential = @user.email_credentials.build
  @credential.attributes = @signup_form.to_email_credential_hash

  if @signup_form.valid? && @user.save
    @activation_url = url_for(
      :only_path        => false,
      :controller       => "signup/email",
      :action           => "activation",
      :activation_token => @credential.activation_token)

    # TODO: テスト
    # MEMO: 即時性を優先し、非同期化しない
    ActivationMailer.(
      :recipients     => @credential.email,
      :activation_url => @activation_url)

    redirect_to(:action => "created")
  else
    set_error_now("入力内容を確認してください。")
    render(:action => "index")
  end
end

#createdObject

GET /signup/email/created



73
74
75
76
# File 'app/controllers/signup/email_controller.rb', line 73

def created
  @signup_form = EditFormClass.new(session[:signup_form])
  @credential  = EmailCredential.find_by_email(@signup_form.email)
end

#indexObject

GET /signup/email



13
14
15
# File 'app/controllers/signup/email_controller.rb', line 13

def index
  @signup_form = EditFormClass.new
end

#validateObject

POST /signup/email/validate



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/signup/email_controller.rb', line 18

def validate
  @signup_form = EditFormClass.new(params[:signup_form])

  if @signup_form.valid?
    session[:signup_form] = @signup_form.attributes
    redirect_to(:action => "validated")
  else
    @signup_form.password              = nil
    @signup_form.password_confirmation = nil
    set_error_now("入力内容を確認してください。")
    render(:action => "index")
  end
end

#validatedObject

GET /signup/email/validated



33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/signup/email_controller.rb', line 33

def validated
  @signup_form = EditFormClass.new(session[:signup_form])

  if @signup_form.valid?
    render
  else
    set_error_now("入力内容を確認してください。")
    render(:action => "index")
  end
end