Class: MicroAuth::AppsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/micro_auth/apps_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#dashboard, #keyboard_tools, #upload

Instance Method Details

#createObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/micro_auth/apps_controller.rb', line 23

def create
  @app = MicroAuth::App.new(app_params.merge({
                                               public_key: SecureRandom.base58(32),
    secret_key: SecureRandom.base58(32),
    app_id: generate_app_id,
    user: current_user
                                             }))
  if @app.save
    redirect_to oauth_app_path(@app.app_id)
  else
    flash[:danger] = 'There was an error while trying to create your app.'
    render :new
  end
end

#deactivateObject



55
56
57
58
59
60
# File 'app/controllers/micro_auth/apps_controller.rb', line 55

def deactivate
  @app.update(active: false, deactivated_by: current_user, deactivated_at: DateTime.now,
              deactivate_comment: params[:comment])
  flash[:success] = 'App deactivated.'
  redirect_to oauth_app_path(@app.app_id)
end

#editObject



45
# File 'app/controllers/micro_auth/apps_controller.rb', line 45

def edit; end

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
# File 'app/controllers/micro_auth/apps_controller.rb', line 6

def index
  @all_apps = if params[:admin].present? && helpers.admin?
                MicroAuth::App.all
              else
                MicroAuth::App.where(user: current_user)
              end
  @apps = if params[:search].present?
            @all_apps.where('name LIKE ?', "#{params[:search]}%")
          else
            @all_apps
          end.order(name: :asc).paginate(page: params[:page], per_page: 30)
end

#newObject



19
20
21
# File 'app/controllers/micro_auth/apps_controller.rb', line 19

def new
  @app = MicroAuth::App.new
end

#showObject



38
39
40
41
42
43
# File 'app/controllers/micro_auth/apps_controller.rb', line 38

def show
  @data = [
    { name: 'Authentications', data: @app.tokens.group_by_week(:created_at).count },
    { name: 'Users', data: @app.tokens.group_by_week(:created_at).count('DISTINCT user_id') }
  ]
end

#updateObject



47
48
49
50
51
52
53
# File 'app/controllers/micro_auth/apps_controller.rb', line 47

def update
  if @app.update app_params
    redirect_to oauth_app_path(@app.app_id)
  else
    flash[:danger] = 'There was an error while trying to update your app.'
  end
end