Class: Archangel::Backend::ProfilesController

Inherits:
Archangel::BackendController show all
Includes:
Controllers::SkipAuthorizableConcern
Defined in:
app/controllers/archangel/backend/profiles_controller.rb

Overview

Backend profiles controller

Instance Method Summary collapse

Methods included from Controllers::MetatagableConcern

#assign_meta_tags

Methods inherited from ApplicationController

#current_site, #render_401_error, #render_404_error, #render_error

Methods included from Controllers::PaginatableConcern

#page_num, #per_page

Methods included from Controllers::ActionableConcern

#action, #collection_action?, #member_action?

Instance Method Details

#destroyObject

Destroy backend profile

Formats

HTML, JSON

Request

DELETE /backend/profile
DELETE /backend/profile.json

165
166
167
168
169
170
171
# File 'app/controllers/archangel/backend/profiles_controller.rb', line 165

def destroy
  profile = resource_content

  profile.destroy

  respond_with profile, location: -> { location_after_destroy }
end

#editObject

Edit backend profile

Formats

HTML, JSON

Request

GET /backend/profile
GET /backend/profile.json

Response

{
  "id": 123,
  "site_id": 123,
  "name": "First Last",
  "username": "my_username"
  "role": "admin",
  "avatar": {
    "url": "/uploads/file.png",
    "large": {
      "url": "/uploads/large_file.png"
    },
    "medium": {
      "url": "/uploads/medium_file.png"
    },
    "small": {
      "url": "/uploads/small_file.png"
    },
    "tiny": {
      "url": "/uploads/tiny_file.png"
    }
  },
  "email": "[email protected]",
  "invitation_token": null,
  "invitation_created_at": null,
  "invitation_sent_at": null,
  "invitation_accepted_at": null,
  "invitation_limit": null,
  "invited_by_type": null,
  "invited_by_id": null,
  "invitations_count": 0,
  "deleted_at": null,
  "created_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
  "updated_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
}

112
113
114
115
116
# File 'app/controllers/archangel/backend/profiles_controller.rb', line 112

def edit
  profile = resource_content

  respond_with profile
end

#showObject

Backend profile

Formats

HTML, JSON

Request

GET /backend/profile
GET /backend/profile.json

Response

{
  "id": 123,
  "site_id": 123,
  "name": "First Last",
  "username": "my_username"
  "role": "admin",
  "avatar": {
    "url": "/uploads/file.png",
    "large": {
      "url": "/uploads/large_file.png"
    },
    "medium": {
      "url": "/uploads/medium_file.png"
    },
    "small": {
      "url": "/uploads/small_file.png"
    },
    "tiny": {
      "url": "/uploads/tiny_file.png"
    }
  },
  "email": "[email protected]",
  "invitation_token": null,
  "invitation_created_at": null,
  "invitation_sent_at": null,
  "invitation_accepted_at": null,
  "invitation_limit": null,
  "invited_by_type": null,
  "invited_by_id": null,
  "invitations_count": 0,
  "deleted_at": null,
  "created_at": "YYYY-MM-DDTHH:MM:SS.MSZ",
  "updated_at": "YYYY-MM-DDTHH:MM:SS.MSZ"
}

60
61
62
63
64
# File 'app/controllers/archangel/backend/profiles_controller.rb', line 60

def show
  profile = resource_content

  respond_with profile
end

#updateObject

Update backend profile

Formats

HTML, JSON

Request

PATCH /backend/profile
PUT   /backend/profile.json

Response

{
  "profile": {
    "name": "First Last",
    "username": "my_username"
    "avatar": "local/path/to/new_file.gif"
    "email": "[email protected]"
  }
}

138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'app/controllers/archangel/backend/profiles_controller.rb', line 138

def update
  empty_password_params if resource_params.fetch(:password, nil).blank?

  profile = resource_content

  successfully_updated =
    if needs_password?(profile, resource_params)
      profile.update(resource_params)
    else
      profile.update_without_password(resource_params)
    end

  reauth_current_user if successfully_updated

  respond_with profile, location: -> { location_after_update }
end