Class: UsersController

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

Instance Method Summary collapse

Instance Method Details

#destroyObject

Delete your user profile. Can only delete the current user

Example

DELETE users/:id.json

HEAD OK

71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'app/controllers/users_controller.rb', line 71

def destroy
  user = User.find(current_user.id)
   = user.
  user.destroy

  respond_to do |format|
    format.html do
      flash[:success] = "User deleted: #{}"
      redirect_to root_path
    end
    format.json { head :ok }
  end
end

#editObject

:nodoc:


22
23
24
25
26
27
28
# File 'app/controllers/users_controller.rb', line 22

def edit # :nodoc:
  repo_counts = current_user.notifications.group(:repository_full_name).count
  @total = repo_counts.sum(&:last)
  @most_active_repos = repo_counts.sort_by(&:last).reverse.first(10)
  @most_active_orgs = current_user.notifications.group(:repository_owner_name).count.sort_by(&:last).reverse.first(10)
  @pinned_search = PinnedSearch.new(query: params[:q])
end

#exportObject


85
86
87
# File 'app/controllers/users_controller.rb', line 85

def export
  send_data current_user.notifications.to_json, :type => 'application/json; header=present', :disposition => "attachment; filename=octobox.json"
end

#importObject


89
90
91
92
93
94
# File 'app/controllers/users_controller.rb', line 89

def import
  data = JSON.parse(params[:file].read)
  current_user.import_notifications(data)
  flash[:success] = "Import complete"
  redirect_to root_path
end

#profileObject

Return a user profile. Only shows the current user

Example

GET users/profile.json

{
  "user" : {
      "id" : 1,
      "github_id" : 3074765,
      "github_login" : "jules2689",
      "last_synced_at" : "2017-02-22T15:49:32.104Z",
      "created_at" : "2017-02-22T15:49:32.099Z",
      "updated_at" : "2017-02-22T15:49:32.099Z"
  }
}

20
# File 'app/controllers/users_controller.rb', line 20

def profile; end

#updateObject

Update a user profile. Only updates the current user

  • :personal_access_token - The user's personal access token

  • :refresh_interval - The refresh interval on which a sync should be initiated (while viewing the app). In milliseconds.

Example

PATCH users/:id.json

{ "user" : { "refresh_interval" : 60000 } }

HEAD OK

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/users_controller.rb', line 42

def update
  if current_user.update(update_user_params)
    if params[:user][:regenerate_api_token]
      current_user.regenerate_api_token
    end

    respond_to do |format|
      format.html { redirect_back(fallback_location: root_path, notice: 'Settings updated') }
      format.json { head :ok }
    end
  else
    respond_to do |format|
      format.html do
        flash[:error] = 'Could not update your account'
        flash[:alert] = current_user.errors.full_messages.to_sentence
        redirect_to :settings
      end
      format.json { render json: { errors: current_user.errors.full_messages.to_sentence }, status: :unprocessable_entity }
    end
  end
end