Class: Api::V1::InfoController
- Inherits:
-
BaseController
- Object
- BaseController
- Api::V1::InfoController
- Defined in:
- app/controllers/api/v1/info_controller.rb
Instance Method Summary collapse
-
#authenticate_user! ⇒ Object
Method overridden because the first time I have to ask for the token.
-
#available_roles ⇒ Object
api :GET, '/api/v1/info/available_roles', "Given auth credentials, in HTTP_BASIC form, it returns the roles list.
-
#token ⇒ Object
api :GET, '/api/v1/info/token', "Given auth credentials, in HTTP_BASIC form, it returns the AUTH_TOKEN, email and id of the user which performed the authentication." api!.
-
#translations ⇒ Object
GET '/api/v1/info/translations'.
-
#version ⇒ Object
api :GET, '/api/v1/info/version', "Just prints the APPVERSION." api!.
Instance Method Details
#authenticate_user! ⇒ Object
Method overridden because the first time I have to ask for the token
37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/controllers/api/v1/info_controller.rb', line 37 def authenticate_user! username, password = ActionController::HttpAuthentication::Basic.user_name_and_password(request) if username user = User.find_by(username: username) end if user && user.valid_password?(password) @current_user = user else return unauthenticated! end end |
#available_roles ⇒ Object
api :GET, '/api/v1/info/available_roles', "Given auth credentials, in HTTP_BASIC form, it returns the roles list
25 26 27 |
# File 'app/controllers/api/v1/info_controller.rb', line 25 def available_roles render json: ROLES.to_json, status: 200 end |
#token ⇒ Object
api :GET, '/api/v1/info/token', "Given auth credentials, in HTTP_BASIC form, it returns the AUTH_TOKEN, email and id of the user which performed the authentication." api!
16 17 18 19 20 21 |
# File 'app/controllers/api/v1/info_controller.rb', line 16 def token render json: { token: @current_user.authentication_token, email: @current_user.email }.to_json, status: 200 end |
#translations ⇒ Object
GET '/api/v1/info/translations'
30 31 32 |
# File 'app/controllers/api/v1/info_controller.rb', line 30 def translations render json: I18n.t(".", locale: (params[:locale].presence || :it)).to_json, status: 200 end |
#version ⇒ Object
api :GET, '/api/v1/info/version', "Just prints the APPVERSION." api!
7 8 9 10 11 |
# File 'app/controllers/api/v1/info_controller.rb', line 7 def version render json: { version: (APPVERSION rescue "No version specified for this app, please add an APPVERSION constant to an initializer to start versioning the application.") }.to_json, status: 200 end |