Sha256: 2bc3b103417e2d495ec53d0cc5545ba215bac9220d673f060c0d97e47f306c5f

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

module API
  module Mounts
    class Auth < Grape::API
      params do
        requires :display_name, type: String
        requires :email, type: String
      end
      post :register do
        params[:email] = params[:email].downcase
        user = Models::User.where(email: params[:email]).first
        if user
          error! :waiting_for_approvement if user.registered?
          error! :already_exists, 400
        end

        user = Models::User.register(declared(params, include_missing: false))

      <%- if @mandrill -%>
        begin
          RegistrationMailer.registered(user).deliver
        rescue
          logger.error $!
        end
      <%- end -%>
      end

      params do
        requires :email, type: String
        requires :email_approvement_code, type: String
      end
      post :approve_email, jbuilder: 'v1/user/profile.json' do
        @user = Models::User.find_by(email: params[:email].downcase, email_approvement_code: params[:email_approvement_code])
        @user.email_approved!
        @user.save
        header['X-Authorize'] = @user.token
        <% if @faye %>
        Faye::Publisher.instance.publish('/user/registered', {display_name: @user.display_name})
        <% end %>
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
grape-gen-0.0.6 template/api/mounts/auth.rb.tt