summaryrefslogtreecommitdiff
path: root/app/controllers/v1/smtp_certs_controller.rb
blob: 75f524c58d4dcddb8f3796a63b1aba4deebe0e4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class V1::SmtpCertsController < ApiController

  before_filter :require_login
  before_filter :require_email_account
  before_filter :fetch_identity

  # POST /1/smtp_cert
  def create
    @cert = ClientCertificate.new common_name: current_user.email_address
    @identity.register_cert(@cert)
    @identity.save
    render text: @cert.to_s, content_type: 'text/plain'
  end

  protected

  #
  # Filters
  #

  def require_email_account
    access_denied unless service_level.provides? 'email'
  end

  def fetch_identity
    @identity = current_user.identity
  end

  #
  # Helper methods
  #

  def service_level
    current_user.effective_service_level
  end

end